You need to sign in to do that
Don't have an account?
Samantha Reddy
ApexClass:
UseCase In Account Object:
Created a Trigger when the ParentAccount is selected in account object ,need to copy the phone number and name and insert the record.
how can i add the Trigger in the Apex Class and Write Test Class...
Thanks
Samantha
How to create a Test Class for the Trigger , weather we need to add it so the Apex Class
trigger CopyAccountTriggerTest on Account (before insert) { if(checkRecursiveTest.runOnce()) { Set<Id> accountIds = new Set<Id>(); for (Account acc : Trigger.new) { if (acc.ParentId != null){ accountIds.add(acc.ParentId); } if(accountIds.size() > 0){ List<Account> accounts = [select id,Name,Phone from account where id in :accountIds ]; for (Account acc2 : Trigger.new) { if (acc2.ParentId != null){ acc2.Name = 'Duplicate'+accounts[0].Name; acc2.Phone= 'Duplicate'+accounts[0].Phone; } } } } } }
ApexClass:
public class checkRecursiveTest { private static boolean run = true; public static boolean runOnce(){ if(run){ run=false; return true; }else{ return run; } } }
UseCase In Account Object:
Created a Trigger when the ParentAccount is selected in account object ,need to copy the phone number and name and insert the record.
how can i add the Trigger in the Apex Class and Write Test Class...
Thanks
Samantha
Here is the code for you reference with the Test class 100% Coverage. You do not need checkRecursiveTest.runOnce since you are running on before Insert so not including that in my code.
Test Class
I hope this will help
All Answers
Can you check the below test class.
If this solution helps, Please mark it as best answer.
Thanks,
Here is the code for you reference with the Test class 100% Coverage. You do not need checkRecursiveTest.runOnce since you are running on before Insert so not including that in my code.
Test Class
I hope this will help