You need to sign in to do that
Don't have an account?
SolidLucas
Case Trigger help
Hello,
I'm trying to create a trigger that updates my campaign members status after a lead or a contact fills a web to case form, my web to case is working fine is getting the id through a javascript,but my trigger isn't working. Someone could help me?
Here is my code:
I'm trying to create a trigger that updates my campaign members status after a lead or a contact fills a web to case form, my web to case is working fine is getting the id through a javascript,but my trigger isn't working. Someone could help me?
Here is my code:
trigger bi_WebToCaseLead on Case (before insert) { Set<String> setCampaignMail = new Set<String>(); //List<CampaignMember> listCm = [SELECT Id,Lead.Email,LeadId,ContactId,Contact.Name,Contact.Email,CampaignId FROM CampaignMember WHERE Campaign.IsActive = true]; List<CampaignMember> listAg = [SELECT Id,Lead.Email,LeadId,ContactId,Contact.Name,Contact.Email,CampaignId FROM CampaignMember WHERE Campaign.IsActive = true AND (Lead.Email IN :setCampaignMail OR Contact.Email IN :setCampaignMail)]; for(CampaignMember cm : listAg){ for(Case caso : Trigger.new){ if(!setCampaignMail.contains(caso.SuppliedEmail)){ setCampaignMail.add(caso.SuppliedEmail); } if(caso.ChaveCampanha__c != null && cm.CampaignId.equals(caso.ChaveCampanha__c)){ cm.Status = 'Respondido'; caso.RelacionamentoLead__c = cm.LeadId; } } } update listAg; }
One caution is this - you aren't going to be able to add the CaseId to the CampaignMember. I don't know if you were planning to, but the case Id values will be null since this is a before trigger. If you need to update CampaignMember with the Id of the case then you need to change your approach so that update happens in an after trigger.
All Answers
Can you provide a little more detail about what you want it to do?
I think you will want to start by iterating through Trigger.new to get a set of the SuppliedEmail values first, then query for the related CampaignMember records.
How are you?
What i want to do is basically that my trigger updates the status of my campaing member to "answered" after the user fills my web to case form,so this update basically will happen when the case is created through this web to case.
Regards
Lucas
One caution is this - you aren't going to be able to add the CaseId to the CampaignMember. I don't know if you were planning to, but the case Id values will be null since this is a before trigger. If you need to update CampaignMember with the Id of the case then you need to change your approach so that update happens in an after trigger.
I've tooked a little bit of your logic and applied into my code and guess what? it worked! thank you for your suport!