Ads

Sunday 14 July 2013

How to undelete records Using Apex?

Salesforce keep record you delete to Recycle Bin for 15 days with maximum record of 25 times the Megabytes (MBs) in your storage. For example, if your organization has 1 GB of storage then your limit is 25 times 1000 MB or 25,000 records. If your organization reaches its Recycle Bin limit, Salesforce automatically removes the oldest records if they have been in the Recycle Bin for at least two hours.

You can manually undelete records by click Recycle Bin icon in bottom left menu. Undelete account will include contact, case, opportunity tagged to that Account. But, if you have many records or you have specific record Id or you want to undelete records with some conditions, manually delete is not an option, use Apex code for it.

You not really need to be good developer to utilize Apex code. Here we go:

1. Open Developer Console
From your name in top right, look for Developer Console











2.From Developer Console
Go to Debug menu and select Open Execute Anonymous Window











3. Enter SOQL 
Example:
Account[] a = [SELECT Id FROM Account WHERE name = 'singtel' ALL ROWS];
undelete a;
Important to add ALL ROWS, otherwise deleted records will be not return on query.






4. Monitor Apex Debug Log
Go to Monitor - Logs - Debug Logs (in Salesforce menu, not Developer console)
Add user to monitor, default it will capture 20 log request for the users

5. Execute 
Click Execute button in Enter Apex Code window

6. Back to Debug Log
Select latest debug log and click View to monitor

Tuesday 9 July 2013

How to fetch Contact details from Opportunity using SOQL in Salesforce?

Query:

SELECT Id, Opportunity.Name, Opportunity.OrderNumber__c, Opportunity.Approval_Status__c, Contact.Email, Contact.Name FROM OpportunityContactRole

Output:


REQUIRED CHECKBOX VALIDATION?

So we now how to enable a required field in a record, but how about making a requried checkbox in your Salesforce form? well it's simple and here is how to do it:

Field 1: Lookup field called : "Account"
Field 2: Date field called "Date"
Field 3: Date field called "Expected Completion Date"
Field4: Checkbox called "Review""

AND(Review__c = FALSE,
OR(
NOT(ISBLANK(Account__c)),
NOT(ISBLANK(Date__c)),
NOT(ISBLANK(Expected_Completion__Date__c))))


and now, If the user enters data in to any one, any two, or all three fields, but does NOT check the box, an error will be thrown.

"SYSTEM.QUERYEXCEPTION: LIST HAS NO ROWS FOR ASSIGNMENT TO SOBJECT"

So I was quering Account a = [Select name from account where id=: strld];
and an exception was thrown: System.QueryExceptoin: List has no rows for assignment to SObject.

Here is the mistake I made and how to fix it:

List<Account>lst = [Select name from account where id=: strld];



WORKBENCH FOR SALESFORCE ?

What is WorkBench ?

Here is the another interesting GUI based tool for Salesforce though announced in Dreamforce before,  this is a free tool from Salesforce.com and not just limited for developers. Other than developer related offering, this tool leverage bunch of different features that you can access through web-based UI to work with Salesforce


Workbench pleasant features 


  • Query the results, download bulk XML and .csv files 
  • Pretty structured information is provided alike Data Loader
  • Offer more data load options than data loader
  • Offer tons of options for developers
  • Handy and web based tool, with easy access to both Production and Sandbox 
  • Provided with Chrome extension and Firefox Add-on to ease the life 


Some Limitations
  • Can't save the data load mapping, which is turn-off
  • Can't schedule, no scheduled options



Workbench is insanely powerful tool for admins and developer to interact with Salesforce.com. This purely web-based tool that uses oauth to connect your salesforce org. The WorkBench use force.com API and supports bulk api calls, rest call, streaming data and surprisingly these all do not end here. The best feature I like about this application is SOQL query calls from to Salesforce cloud right away with pretty interactive interface

You can query, manipulate data and the metadata in Salesforce org, this also leverage advance features like debug logs and backward compatibility testing and single sign-on integration




Query Results and Pagination 

Query results are shown there itself while in the old versions, the users were required to jump from page to page to retrieve records,  but now with pagination support, the row number on SOQL query results continue from page to page and make data view pretty easy







Browser Support 


Workbench comes with chrome extension that ease the access, and in no time work bench is ready to use and can be pulled up right inside your favorite chrome browser



How to get started with Workbench ?













Login with your org credentials and select objects







Pull up a data using Query









Tuesday 25 June 2013

Summer13 Release Features

Some Of The available Features With summer13 are  Listed Below,

  1.Approval Processes now available in change sets and exposed through the Metadata API
  2.Publisher actions are available in change sets and are supported in both managed and unmanaged packages.
  3.Summer ’13 introduces a new computer-telephony integration (CTI) Visualforce component—     support:clickToDia.
4.Summer ’13 introduces a new Visualforce component, chatter:userPhotoUpload that lets users upload a photo to their Chatter profile page
  5.The maximum size for a SOQL query has been increased to 20,000 characters
  6.Use Chatter in Apex to build Chatter integrations and custom UIs without making HTTP callouts Because Chatter in Apex exposes many Chatter API resources as Apex classes in the ConnectApi namespace
  7.Global Actions
  8. Communities

Thursday 20 June 2013

Adding Rows Dynamically to Page block Table ?

Apex:

public class MemberPopup
{
    public List<Account> memberList {get;set;}
    public List<Account> memberAddList {get;set;}
    public String memberName {get;set;}      
    public MemberPopup()
    {
        String sql = 'SELECT Name,Company__c FROM Account';
        memberList = Database.Query(sql);
        memberAddList = new List<Account>();
        memberAddList.add(new Account());
    }  
    public void AddRow()
    {
        memberAddList.add(new Account());
    }
}



VF Page:

<apex:page controller="MemberPopup" >
<apex:form >
    <apex:pageBlock id="membAdd" >                
        <apex:pageblockSection >
            <apex:pageBlockTable value="{!memberAddList}" var="m" >
                <apex:column headerValue="Member Name">
                    <apex:inputField value="{!m.Name}"/>
                </apex:column>
                <apex:column headerValue="Mobile Number">
                    <apex:inputField value="{!m.Company__c}"/>
                </apex:column>
                <apex:column headerValue="eMail Id">
                    <apex:inputField value="{!m.Account_Status__c}"/>
                </apex:column>
            </apex:pageBlockTable>
            <br/><apex:commandLink value="Add Row" action="{!addRow}" reRender="membAdd"/>      
        </apex:pageblockSection>      
        <apex:pageblockSection columns="1" >
            <apex:pageblockSectionItem >
                <apex:commandButton value="Save" />
                <apex:commandButton value="Cancel" />
            </apex:pageblockSectionItem>       
        </apex:pageblockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>