Test method is used for Unit testing of your code. You can either write the test method of class inside the class of you can create the separate class for writing the test method. Test method is the keyword by which sales force is identifying that this is your test method.
Try the below code as reference:
public class AssignLeads
{
public static Boolean assignAlreadyCalled=FALSE;
public static boolean assignAlreadyCalled()
{
return assignAlreadyCalled;
}
@future
public static void assign(List<Id> lIds)
{
assignAlreadyCalled=TRUE;
List<Lead> leads=[SELECT Id,LastModifiedBy.Alias FROM Lead WHERE Id IN: lIds];
for(lead l:leads)
{
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
l.setOptions(dmo);
}
update(leads);
}
public static testmethod void testCoverage()
{
list<id> lds=new list<id>();
lead l=new lead(lastname='test',company='abc');
insert l;
lds.add(l.id);
AssignLeads a=new AssignLeads();
AssignLeads.assign(lds);
AssignLeads.assignAlreadyCalled();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
http://lmgtfy.com/?q=apex+test+methods+salesforce
Hi,
Test method is used for Unit testing of your code. You can either write the test method of class inside the class of you can create the separate class for writing the test method. Test method is the keyword by which sales force is identifying that this is your test method.
Try the below code as reference:
public class AssignLeads
{
public static Boolean assignAlreadyCalled=FALSE;
public static boolean assignAlreadyCalled()
{
return assignAlreadyCalled;
}
@future
public static void assign(List<Id> lIds)
{
assignAlreadyCalled=TRUE;
List<Lead> leads=[SELECT Id,LastModifiedBy.Alias FROM Lead WHERE Id IN: lIds];
for(lead l:leads)
{
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
l.setOptions(dmo);
}
update(leads);
}
public static testmethod void testCoverage()
{
list<id> lds=new list<id>();
lead l=new lead(lastname='test',company='abc');
insert l;
lds.add(l.id);
AssignLeads a=new AssignLeads();
AssignLeads.assign(lds);
AssignLeads.assignAlreadyCalled();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.