About

Edit photo

Thursday, February 16, 2017

APEX Test Classes - Examples


Apply @istest annotation to code. Signature Characterisitics: static --- test method must be a static void  --- it should always no return type. no parameters --- Don't use parameters. Example: @istest public class myclass { @istest private static void mytest() {...} //or private static void testmethod mytest() {...} } Test cannot do: commit changes to DB. Perform...

Thursday, February 9, 2017

Approval process using apex


An approval process is an automated process which can be used to approve/reject record updates. A record can be submitted for approval request from related list "Approval History". Once a records is submitted it goes for approval to a specified approver. This is a...

send email in apex salesforce


Salesforce provides method to send emails from apex. We can create a instance of that method, set all the required parameters and then send the emails. We can set the email addresses to which the email be sent in "setToAddresses", we can give emails seperated by comma. Simialrly bcc,cc email addresses can be seperated by comma . We can specify the body as text or HTMl as desired. Following is a...

avoid recursive trigger salesforce


Recursion occurs when the code gets called again and again and goes into a infinite loop. It is always advisable to write a code that does not call itself. However, sometimes we are left with no choice. Recursion occurs in trigger if your trigger has a same DMLstatement and the same dml condition is used in trigger firing condition on the same object(on which trigger has been written) For...

LEAD conversion in trigger


trigger ConvertLeadtrigger on Lead (after insert,after update) { Integer Count =0; Database.LeadConvert[] leadCollectionArray = new Database.LeadConvert[trigger.new.size()] ; for(Lead Lea : trigger.new){ if(Lea.rating == 'Hot'){ Database.LeadConvert convLead = new database.LeadConvert(); convLead .setLeadId(Lea.Id); convLead.setConvertedStatus('Closed...

SOSL Example in Salesforce


system.debug([FIND 'test' IN ALL FIELDS RETURNING Account (Id,Name,type),Contact(name,email),Opportunity(name,StageName),Lead(company,name,status)]); Dynamic: The following program search the field com* in account, opportunity and contacts and gets the output in...