How to setup Apache ANT tool in Mac OS for Salesforce?

1. Download Apache Ant version 1.6 or newer to a directory of your choice-http://ant.apache.org/bindownload.cgi



2. Log into a Salesforce organization.

3. From Setup, click Develop --> Tools and select Force.com Migration Tool.




4. Save the .zip file locally and extract the contents to the directory of your choice.

5. Copy ant-salesforce.jar and paste into your Ant installation's lib directory. The lib directory is located in the root folder of your Ant installation.

6. Execute the below command in Terminal.

vim .profile

7. Press "i" key, so that you will be in Insert mode.


8. Paste the below code

export JAVA_HOME=$(/usr/libexec/java_home)
export ANT_HOME=/Users/magulanduraipandian/Desktop/Magulan/Ant
export PATH=$PATH:$ANT_HOME/bin

9. Do the same for vim .bash_profile Press "Esc" key.

10. Enter :wq and press "Enter" key.

11. Go to the path using "CD" command. For example, cd Desktop/Magulan/Ant/bin and execute the ant commands.

Note:
If you face ant command not found issue, please close the terminal and open it again.

Cheers!!!

SOQL to get Account ids where Contact count is greater than 2

Sample Query:

SELECT Account.Id FROM Contact GROUP BY Account.Id HAVING COUNT(Account.Id) > 2

This query is used to get Account ids where Contact count is greater than 2 for the accounts.

Cheers!!!

apex:commandButton not working sometime

If apex:commandButton is not working, check the below

1. In reRender attribute, check whether we are calling parent component Id and child component Id. If it is coded in that way, remove the child component Id since parent component Id is used.

2. Use <apex:actionFunction/> for calling Javascript methods.

Cheers!!!

Sample Wrapper Class using Apex in Salesforce

Sample Code:

Visualforce Page:

<apex:page controller="Sample" tabStyle="Account">
<apex:form >
<apex:pageMessages />
    <apex:pageBlock id="pg">
        <apex:pageBlockSection >
            <apex:pageBlockTable value="{!listWrapper}" var="a">
                <apex:column >
                    <apex:inputCheckbox value="{!a.checkBool}"/>
                </apex:column>
                <apex:column value="{!a.acct.Name}"/>
                <apex:column value="{!a.acct.Industry}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

Apex Controller:

public class Sample {
    public List<WrapperClass> listWrapper {get;set;}
    
    public Sample() {
        List<Account> listAcct = [SELECT Name, Industry FROM Account LIMIT 1000];
        
        if(listAcct.size() > 0) {
            listWrapper = new List<WrapperClass>();
            
            for(Account a : listAcct) {
                listWrapper.add(new WrapperClass(a));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checkBool {get;set;}
        public Account acct {get;set;}
        public WrapperClass(Account acct) {
            this.acct = acct;
        }        
    }
}

Output:


Cheers!!!

How to sort related list in Salesforce?

To sort related list in Salesforce, follow the below steps

1. Go to the parent object.

2. Select the page layout.

3. In the child object related list, click the gear icon (Settings).


4. Select the field for Sorting.


Cheers!!!

Email-Based Identity Confirmation Option Salesforce

1. Go to Setup --> Administer --> Profiles.

2. Select the profile.

3. Select "System Permissions".

4. Select "Email-Based Identity Confirmation Option" check box.


Cheers!!!

Force.com Streaming API

Use Streaming API to receive notifications for changes to Salesforce data that match a SOQL query you define, in a secure and scalable way.

Streaming API is useful when you want notifications to be pushed from the server to the client based on criteria that you define.

For simple example, check the below link

http://www.infallibletechie.com/2016/02/streaming-api-example-in-salesforce.html

For more information, check the below link

http://www.salesforce.com/developer/docs/api_streaming/

Cheers!!!

How to record and play using Selenium IDE?

Follow the below steps to record and play using Selenium IDE

1. Go to Tools --> Selenium IDE.


2. Open any site. The recording process will be on by default.

For example, open www.yahoomail.com, give your username and password, click login, open any email.

3. Click "Save Test Case" to save.


4. Click "Open" and locate the saved test case.


5. Click "Play current test case"  to play.


How to install Selenium IDE?

1. Go to "http://docs.seleniumhq.org/download/".

2. Select the version.


3. Click "Allow".


4. Click "Install Now".


Cheers!!!

Simple Search using Visualforce and Apex in Salesforce?

Sample Code:

Visualforce page:

<apex:page controller="Sample" tabStyle="Account">
    <apex:actionstatus id="actStatus">
        <apex:facet name="start">
            <div class="waitingSearchDiv" id="el_loading" style="background-color: #fbfbfb; height:100%;opacity:0.65;width:100%;">
                <div class="waitingHolder" style="top: 100px; width: 91px;">
                <img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
                <span class="waitingDescription">Loading...</span>
                </div>
            </div>
        </apex:facet>
    </apex:actionstatus>
<apex:form >
<apex:pageMessages />
    <apex:pageBlock id="pg">
        <apex:pageBlockSection >
            <apex:panelGrid columns="3" cellpadding="3" cellspacing="3">
                <apex:outputLabel value="Account Name: "/>
                <apex:inputText value="{!acctName}"/>
                <apex:commandButton value="Go" action="{!searchAcct}" status="actStatus" reRender="pg"/>
            </apex:panelGrid> 
        </apex:pageBlockSection>
        <apex:pageBlockSection rendered="{!listAcctOptions.Size > 0}" title="Account Selection">
            <apex:panelGrid columns="2">
                <apex:outputLabel value="Select Account: "/>
                <apex:selectList value="{!selectedAcctId}" size="1">
                    <apex:selectOptions value="{!listAcctOptions}"/>
                    <apex:actionSupport action="{!fetchRecords}" event="onchange" status="actStatus" reRender="pg"/>
                </apex:selectList>
            </apex:panelGrid>
        </apex:pageBlockSection>        
        <apex:pageBlockSection rendered="{!listContacts.Size > 0}" title="Contacts">
            <apex:pageBlockTable value="{!listContacts}" var="con">
                <apex:column >
                    <apex:outputLink target="_blank" value="/{!con.Id}">{!con.Name}</apex:outputLink>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        <apex:pageBlockSection rendered="{!listOpptys.Size > 0}" title="Opportunities">
            <apex:pageBlockTable value="{!listOpptys}" var="oppty">
                <apex:column >
                    <apex:outputLink target="_blank" value="/{!oppty.Id}">{!oppty.Name}</apex:outputLink>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        <apex:pageBlockSection rendered="{!listCases.Size > 0}" title="Cases">
            <apex:pageBlockTable value="{!listCases}" var="cas">
                <apex:column >
                    <apex:outputLink target="_blank" value="/{!cas.Id}">{!cas.CaseNumber}</apex:outputLink>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>

Apex Controller:

public class Sample {
    public String acctName {get;set;}
    public List<SelectOption> listAcctOptions {get;set;}
    public List<Contact> listContacts {get;set;}
    public List<Case> listCases {get;set;}
    public List<Opportunity> listOpptys {get;set;}
    public String acctId {get;set;}
    public String selectedAcctId {get;set;}
    
    public Sample() {
        listAcctOptions = new List<SelectOption>();
        listContacts = new List<Contact>();
        listCases = new List<Case>();
        listOpptys = new List<Opportunity>();
    }
    
    public void searchAcct() {
        String soql = 'SELECT Id, Name FROM Account WHERE Name LIKE \'' + acctName + '%\' LIMIT 999';
        List<Account> listAcct = Database.query(soql);
        system.debug('Test ' + listAcct);
        if(listAcct.size() > 0) {
            listAcctOptions = new List<SelectOption>();
            listAcctOptions.add(new SelectOption('none', '-----------None-----------'));
            for(Account a : listAcct) {
                listAcctOptions.add(new SelectOption(a.Id, a.Name));
            }
        }
    }
    
    public void fetchRecords() {
        if(selectedAcctId != 'none') {
            listOpptys = [SELECT Id, Name FROM Opportunity WHERE AccountId =: selectedAcctId];
            listContacts = [SELECT Id, Name FROM Contact WHERE AccountId =: selectedAcctId];
            listCases = [SELECT Id, CaseNumber FROM Case WHERE AccountId =: selectedAcctId];
        } else {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Select an Account to fetch their records'));
        }
    }
}

Output:



Cheers!!!

Error: Invalid field 'Opportunity.Contract' specified

Use ContractId instead of Contract.

Sample Query:

SELECT Name, ContractId FROM Opportunity LIMIT 2

Cheers!!!

How to handle Time Limit Exceeded : Your request exceeded the time limit for processing in Salesforce?

To handle Time Limit Exceeded : Your request exceeded the time limit for processing in Salesforce

1. Cache any data that is frequently accessed, such as icon graphics.

2. Avoid SOQL queries in your Apex controller getter methods.

3. Reduce the number of records displayed on a page by:

a. Limiting the data coming back from SOQL calls in your Apex controllers. For example, using AND statements in your WHERE clause, or removing null results

b. Taking advantage of pagination with a list controller to present fewer records per page

Cheers!!!

How to convert Lead without creating Opportunity in Salesforce?

Sample Code:

Lead myLead = new Lead(LastName = 'Foo', Company='Foo Bar');
insert myLead;    
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.id);
lc.ConvertedStatus = 'Closed - Converted';
lc.setDoNotCreateOpportunity(true);
Database.LeadConvertResult lcr = Database.convertLead(lc);                
System.assert(lcr.isSuccess());

Cheers!!!