function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ckellieckellie 

Unable to Assign userid

I am writing a trigger that will return the user full name to a custom lookup field to the username. The problem is that i cannot pick up the lead.ownerid when add/update a campaign member from the lead record or the conttact record. Below is the start of the trigger.

 

trigger cmOwner on CampaignMember (Before Insert, Before Update) {

    Set<Id> lIds = new Set<Id>();
    Set<Id> cIds = new Set<Id>();
    
    for(CampaignMember cm : Trigger.new) {
    System.debug('**** 1 lIds id : '+cm.lead.ownerid);

        LIds.add(cm.lead.ownerid);
        cIds.add(cm.contact.ownerid);

    System.debug('**** 2 lIds id : '+cm.lead.ownerid);

   }

    list<user> lUs = [select id, FirstName, LastName from user where id in :lids];

}

 

Although the trigger is set to run whenever a campaign member record was created or updated, no records are added to sets when i create or edit a campaign member record. Why are the records not entering the trigger?

 

Thank you,

ckellie

Best Answer chosen by Admin (Salesforce Developers) 
srikeerthisrikeerthi

Hi

 

You need to write the trigger for after insert,after update to get the id.

 

 

Thanks

All Answers

srikeerthisrikeerthi

Hi

 

You need to write the trigger for after insert,after update to get the id.

 

 

Thanks

This was selected as the best answer
ckellieckellie

Thank you very much.