You need to sign in to do that
Don't have an account?
Trigger to Populate Lookup Fields
Hi
I'm quite new to the triggers world, so forgive me for any mistakes...
I have a field populated with contact ID, and I want that two lookup fields will be populated accordingly ("Assigned to Partner" and "Assigned to Partner Rep")
I managed to populate the "Assigned to Partner Rep" with the "Partner Rep" contect (Id in this case). "Assigned to partner" is populated only after another edit, not right away
(He is populated by the "Partner SF ID", which is the partner account ID)
trigger AssignedRep on Lead(before insert, before update) {
for (Lead a : Trigger.new) {
if(a.LeadSource =='Partner' && a.Partner_Rep__c != null){
a.Assigned_to_Partner_Rep__c = a.Partner_Rep__c;
if(a.Assigned_to_Partner_Rep__c != null)
a.Assigned_to_Partner__c = a.Partner_SF_ID__c;
}
}
}
Also, how do I write a test coverage to this code? I understood it's mandatory (although the code is quite simple...)
Any help is appriciated!
Thanks!
Itay
Hi Itay,
It looks to me like this could solve your issue: You were checking the field 'Partner_Rep__c' twice to be not null.
For test coverage you need to create a test class which inserts and updates a lead (and several for bulk operations). Have a look here for Testing Best Practices.
Hope this helps.
Florian