You need to sign in to do that
Don't have an account?
Vidhyasagar Ranganathan
Help to create trigger to update records
Hello,
I am trying to create a trigger that will update the custom object records once records are created in the object. The custom object has ID from Lead Object and with that I will have to pull 5 fields of that lead and update in the custom object.
I started with the trigger but couldn't proceed and any help is appreciated
Thanks
trigger CampaignAttributionGetLead2 on Campaign_Attribution__c (before insert, before update) {
for (Campaign_Attribution__C C: Trigger.new){
if(C.Lead_ID__C != null)
{
List<Lead> L = [SELECT createddate, name, company, status, Lead_Medium__c FROM lead where ID = :C.Lead_ID__c] ;
{
C.Lead_Created_Date__c = L.createddate;
C.Lead_Medium__c = L.Lead_Medium__c;
C.Lead_Status__C = L.Status;
C.Lead_Name__C = L.name;
C.Lead_Company__C = L.company;
}
}
}
update C;
}
I am trying to create a trigger that will update the custom object records once records are created in the object. The custom object has ID from Lead Object and with that I will have to pull 5 fields of that lead and update in the custom object.
I started with the trigger but couldn't proceed and any help is appreciated
Thanks
trigger CampaignAttributionGetLead2 on Campaign_Attribution__c (before insert, before update) {
for (Campaign_Attribution__C C: Trigger.new){
if(C.Lead_ID__C != null)
{
List<Lead> L = [SELECT createddate, name, company, status, Lead_Medium__c FROM lead where ID = :C.Lead_ID__c] ;
{
C.Lead_Created_Date__c = L.createddate;
C.Lead_Medium__c = L.Lead_Medium__c;
C.Lead_Status__C = L.Status;
C.Lead_Name__C = L.name;
C.Lead_Company__C = L.company;
}
}
}
update C;
}
Please check once below sample code:
I have not tested above code may you will get some syntactical errors.
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
try the following code:
Mark best if does helps you.
Thanks,
Rahul
TRY THIS CODE:
Thanks
Akhsay
I just did some changes and it worked well.