You need to sign in to do that
Don't have an account?
SolidLucas
Trigger help before insert
Hello,well i've created a trigger that updates a campaign member status to answered,but i need to improve my code,cause actually i've hardcoded the Id of the campaign that i wish to update the member status,what i want to know is there any way to set the campaign without setting the Id hardcoded,cause this will impact in the future. thanks!
this is my code!
this is my code!
trigger bi_WebToCaseLead on Case (before insert) { List<CampaignMember> listCm = [SELECT Id,Lead.Email,LeadId,CampaignId FROM CampaignMember WHERE CampaignId = '701190000001F5l']; Map<String, CampaignMember> mapCm = new Map<String, CampaignMember>(); for(CampaignMember cm : listCm){ mapCm.put(cm.Lead.Email, cm); } for(Case caso : Trigger.new){ Case tempCase = caso; CampaignMember tempCampaign = mapCm.get(caso.SuppliedEmail); if(tempCampaign != null && caso.ChaveCampanha__c == '701190000001F5l'){ tempCampaign.Status = 'Respondido'; caso.RelacionamentoLead__c = tempCampaign.LeadId; update tempCampaign; } } }
Since the trigger is on the case, how about creating a variable on the case storing the campaign.
That way the SOQL just need to reference the campaign of the case.
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
So - it looks like you're doing this only for a specific campaign. I'm thinging you should add a flag to the campaign object for - "Update member status ...". Then in your trigger - you can get all (probably just this one) campaign to get the ID.
Also - you'll have an issue doing the DML update in a loop with your existing code.
As per your requirement i have modified your code.
Please change your trigger code with below code :
Let me know if you need more help on this or if you have any issue in this.
Thanks,
Abhishek Bansal
Hey,Abhishek! First,thanks for your help, i tried to use your code but it didn't work,the update happens after the user fill the web to case form,the test i was doing is to pass the web to case url with the campaign Id,but it didn't update the case,so i created the before trigger to check the values before update the status.
here is my web to case: