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
Sangeeta BhatiaSangeeta Bhatia 

Add Campaing to Lead upon create

I am new to Apex. I need to write a code where when a new lead is created, if the lead source = Chat, i want to add a campaing called "chat" to this lead record. Can someone please help me with this code. thanks.
Robert ZentgrafRobert Zentgraf
Hi Sangeeta,

I think you can create a workflow to the lead object and assign the campaign "Chat" (<= should be created at first as campaign) by field update.

Regards
Robert
(mindforce: mind-force.de)
Sangeeta BhatiaSangeeta Bhatia
Robert the challenge is that Campaign is not a field that can be updated. It is a related list. I dont see how I can assign the chat campaign to the lead via workflow. 
Robert ZentgrafRobert Zentgraf
Hi Sangeeta,

you are right. There seems to be an interesting logical idea:
https://help.salesforce.com/apex/HTViewSolution?id=000005401&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000005401&language=en_US)
https://success.salesforce.com/answers?id=90630000000gtsXAAQ

Perphaps, you can check the campaign field during lead creation by using a validation rule!?

Best Regards
Robert
(mindforce: http://www.mindforce.de)