You need to sign in to do that
Don't have an account?
Janin Dancause
This is my trigger I have write to add a specific account ID to a Contact. I am new to salesforce programming and I try to write the unit test but I need some help to do it.
Help to write the first unit test
This is my trigger I have write to add a specific account ID to a Contact. I am new to salesforce programming and I try to write the unit test but I need some help to do it.
trigger Contacts_Accounts on Contact (Before Insert, Before Update) { for (Contact newContact : Trigger.New){ String id_account; id_account = [select id from Account where idClientSoquij__c = :newContact.idClientSoquij__c].id; newContact.AccountId = id_account; } }
Since your trigger is on insert and update of contact, you have to create Contacts in your class, to cover all the cases you to insert a case, also update a Case.
Account also you have to create since your trigger does query that, below is the sample code I am pasting here for you for your trigger:
Also I would suggest, do not write the query inside the loop since you will encounter exception (Salesforce lemitations) when you will insert more then 150 contact records through data loader.
Mark my answer as best if it does help you.
Please use this code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
If you found this answer helpful then please mark it as best answer so it can help others.
Thanks
Akshay