You need to sign in to do that
Don't have an account?
ChickenOrBeef
Populate 'Primary Campaign Source' with most recent Campaign Influence
Hey everyone,
Here is the issue we need to resolve:
1) A lead is converted to an opportunity without being in a campaign yet
2) The lead is now the Primary Contact on the opportunity
3) After a while that Primary Contact gets put in a campaign
The issue?
4) The 'Primary Campaign Source' field on the opportunity needs to be populated with the last campaign the Primary Contact was added to
Can I do this with a regular Apex trigger? Or do I need to use batch Apex?
Thanks!
-Greg
Here is the issue we need to resolve:
1) A lead is converted to an opportunity without being in a campaign yet
2) The lead is now the Primary Contact on the opportunity
3) After a while that Primary Contact gets put in a campaign
The issue?
4) The 'Primary Campaign Source' field on the opportunity needs to be populated with the last campaign the Primary Contact was added to
Can I do this with a regular Apex trigger? Or do I need to use batch Apex?
Thanks!
-Greg
1)create a trigger on Campaign Member object such that you can get the Contact associated with this Campaign
2)Once you have the campaign - get the opportuities linked to his Contact using SOQL
3)Once you have this lst - you can update the Primary Campaign Source field with the name of the campaign this contact is linked with.
All Answers
1)create a trigger on Campaign Member object such that you can get the Contact associated with this Campaign
2)Once you have the campaign - get the opportuities linked to his Contact using SOQL
3)Once you have this lst - you can update the Primary Campaign Source field with the name of the campaign this contact is linked with.
Hi,
How is the primaty contact put in a campaign? Is it through apex? If it is done through a DML, I though we can create a trigger on "Contact Role", but we unfortunately cannot create triggers on "opportunitycontactrole".
You may have to use batch apex and schedule it to run periodically.
My idea: You can get the contact ID for the primary contact from the opportunitycontactrole object using a SOQL query, then query that Contact ID on the "CampaignMember" object, and get the ID of the campaign which has the latest Created Date, may be through ASC LIMIT to 1. This Campaign ID can then be updated in the opportunity's Primaty Campaign Source field.
I haven't tried it myself though.
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
Did you get this to work? Would you mind sharing the SOQL you used? I am having this same issue.
Best,
Kramer
I ended up using batch apex for this. Here's the entire batch class:
I'm not sure if that's the absolute most efficient way to handle that, but there it is. Let me know if you have any questions.
-Greg