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
Kris WebsterKris Webster 

Quick Trigger HELP

I am trying to write a trigger that will populate a contact lookup field with a specific contact. I am struggling to figure out how to code the specific contact into the trigger. 

Check out the code and you will see what I mean...

Any help would be MUCH APPRECIATED! Thanks guys! 
 
trigger CampaignTrigger on Campaign (after insert) {

	for(Campaign camp:Trigger.New){
		if(camp.Project_Manager__c == null)
		camp.Project_Manager__c = WHAT DO I PUT HERE?? THE USERS ID? 
	}



}

 
Raj VakatiRaj Vakati

Use User Id (If Project_Manager__c is lookup or master to user 
 
trigger CampaignTrigger on Campaign (after insert) {

	for(Campaign camp:Trigger.New){
		if(camp.Project_Manager__c == null)
			// Yes .. You need to add the user Id 
		// In this case i am getting campagin Owner Manager Id and stamping 
		camp.Project_Manager__c = [Select id from User where Id =:OwnerId].ManagerId ; 
	}



}

 
Saifullah SaifiSaifullah Saifi
One question : what do you mean by specific  contact.
who is the project manager for any campaign
Brother @Raj wrote the answer but it's not bulikfied.
If you will help me , when do you want to assign project manager, or how conatct and project manager are related. If you willgive me the explaination.
Kris WebsterKris Webster
I want the project manager to always equeal a specific contact. It will always be this same specific contact for all records created. So the Project Manager lookup field should always be filled with the contact "Kris Webster" 
Kris WebsterKris Webster
I want the project manager to always fill with the same specific contact. SO every time a record is created the field will be filled with the contact "Kris Webster" 
Kris WebsterKris Webster
Is this possible ?? 
NimitNimit
trigger CampaignTrigger on Campaign (after insert) {

Contact con = [Select id from contact where Name = 'Kris Webster' limit 1];
	for(Campaign camp:Trigger.New){
		if(camp.Project_Manager__c == null)
		<b>	// Yes .. You need to add the user Id 
		// In this case i am getting campagin Owner Manager Id and stamping </b>
		camp.Project_Manager__c = con.Id;
	}



}

 
Ajay K DubediAjay K Dubedi
Hi Kris,

Below code can fulfill your requirements, Hope this will work for you.
trigger CampaignTrigger on Campaign (after insert) {

Contact conObj = [Select id,Name from contact where Name = 'Kris Webster' limit 1];

    for(Campaign campObj:Trigger.New){
        if(campObj.Project_Manager__c == null)
        campObj.Project_Manager__c = conObj.Id;
        campObj.Name  = conObj.Name
    }

}

Please mark this as best answer if this solves your problem.

Thank you,
Ajay Dubedi