+ Start a Discussion
NBlasgenNBlasgen 

Change Campaign Member Status via Lead Trigger (?)

I would like to be able to change the Campaign Member Status (ie, Responded) via an update to a Lead field.  Wanted to try doing it with Workflow, but I don't seem able to do it.  I expect, as with everything, it can be done with a Trigger.  Any pointers would be helpful.

NBlasgenNBlasgen

My point was that I knew Triggers would work but pointed on CampaignMembers would be helpful.  Anyways, I guess I can mess around with Apex Exploer and figure it out.

sforce2009sforce2009

is this what you are looking for,

 

Trigger myTrigger on Lead(before update)
{
    map<Id, Lead> leadmap = new map<Id, Lead>();
    for(Lead l: Trigger.new)
    {
        if(l.yourupdatefield__c == 'value')
            leadmap.put(l.Id, l);
    }
    list<CampaginMember> lstCM = [select Id, Status from CampaignMember where LeadId in: leadmap.keyset()];
    for(Integr i = 0; i < lstCM.size(); i++)
    {

        lstCM[i].Status = "Responded";
    }

    update lstCM;
}