You need to sign in to do that
Don't have an account?
Indhurani Kanagaraj
How to write Apex test class for this? Please help me
public class Handeller
{
List<ID> tempAccList = new List<ID>();
List<Account> aList = new List<Account>();
List<Customer__c> cList = new List<Customer__c>();
List<Account> aList1 = new List<Account>();
public void getAccountId (List<Account> accList)
{
for (Account acc: accList)
{
tempAccList.add(acc.Id);
}
if(!tempAccList.isEmpty())
{
createCustomer();
}
}
public void createCustomer()
{
aList =[SELECT Id,Name,Phone,Role_of_the_main_contact__c FROM account WHERE Id IN:tempAcclist];
for (Account acc1: aList)
{
Customer__c cust = new Customer__c();
cust.Name = acc1.Name;
cust.Phone__c= acc1.Phone;
cust.Role_of_the_contact__c=acc1.Role_of_the_main_contact__c;
cust.Related_Account__c=acc1.ID;
cList.add(cust);
acc1.Phone=null;
acc1.Role_of_the_main_contact__c=null;
aList1.add(acc1);
}
insert cList;
update aList1;
}
}
{
List<ID> tempAccList = new List<ID>();
List<Account> aList = new List<Account>();
List<Customer__c> cList = new List<Customer__c>();
List<Account> aList1 = new List<Account>();
public void getAccountId (List<Account> accList)
{
for (Account acc: accList)
{
tempAccList.add(acc.Id);
}
if(!tempAccList.isEmpty())
{
createCustomer();
}
}
public void createCustomer()
{
aList =[SELECT Id,Name,Phone,Role_of_the_main_contact__c FROM account WHERE Id IN:tempAcclist];
for (Account acc1: aList)
{
Customer__c cust = new Customer__c();
cust.Name = acc1.Name;
cust.Phone__c= acc1.Phone;
cust.Role_of_the_contact__c=acc1.Role_of_the_main_contact__c;
cust.Related_Account__c=acc1.ID;
cList.add(cust);
acc1.Phone=null;
acc1.Role_of_the_main_contact__c=null;
aList1.add(acc1);
}
insert cList;
update aList1;
}
}
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
You write a test class for this the same way that you would any other:
- Set up some data for the Apex to access
- Verify the behaviour with asserts.
Let us know if this will help you