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
Surinder Singh 25Surinder Singh 25 

Auto Update Opp Primary Campaign Source

I have to write an trigger which will do -

When an campaign is added to opportunity ( from campaign influence related list "Add to compaign" button), then if that opportunity has no already existing campaigns(means that campaign is the first one) then make that campaign primary campaign autometically ( if user forget to check primary campaign source checkbox). If user has checked primary campaign source checkbox then nothing to do.

I am not sure on which object i have to write trigger. What will be the trigger. Completely have no idea on this Opp Campaign relationship. Please help me to write trigger.
HARSHIL U PARIKHHARSHIL U PARIKH
I have just read lots of information from internet on this topic but coildn't find a particular workaround for how to make Campaign as a Primary Campaign on opportunity when there is a only one campaign attached.

But however, here is one of the good link which you may want to look around:

Link: = http://www.simplysfdc.com/2016/10/salesforce-customizable-campaign.html

I have tried taking approach in this link above in my developer org this is what it does,
It takes the regular "Campaign Influence" related list out from under the opportunity and puts (I mean you have to put from edit page layout) new "Campaign Influence" list as a related list.
This is how it would look like,
User-added image

I am not sure how this would help in your case since there is no edit button. This is helpful for the people who wants to import 100 associated campaigns to the single opportunity from dataloader because since they have enabled the new related list, the API names appears under the dataloader.
This approach also opens up the API name for the Campaign Influence object from Set up (means you can see Fields, Validatiopn rules, Triggers etc.. links from set up when you type Campaign Influence in search bar).

The disadvantage is this:
Campaign Influence Model 
When you enable this new Campaign Influence, by default Salesforce will provide a model called "Salesforce Model", this model will server as Primary model and Locked - campaign influence records for a locked model can only be added or edited via workflows and the API. Your users can’t add records manually in Salesforce.

You can add new model suit to your business requirements. If you set up more than one influence model, designate one of them as the primary model. The primary model’s records appear in the Campaign Influence related list on opportunities and the Influenced Opportunities related list on Campaigns.

There was an Idea about this topic: https://success.salesforce.com/ideaView?id=087300000006n77AAA
but that was about making 'Campaign Influence' accessible via API (by following the first link I provided) and I am not sure if we can have edit button show up in related-list though..

Hope this information helps!

 
Surinder Singh 25Surinder Singh 25
Thanks for sharing usefull information Govind. But this information is but working for me in this case. Still i need to figure it out, how can i customize the process. Problem is that Campaign influence API is not available for use in apex. 
HARSHIL U PARIKHHARSHIL U PARIKH
I am not sure how it would work if there is no edit button at all for users to select? It says your users can't add records manually in salesforce ;)