Skip to main content
I've been trying to create this custom button for a while now, and I'm pretty sure this may be impossible because Salesforce does not give editing rights to the Campaign ID in the Campaign Members Object.  I would love to hear if anyone has been able to do something like this.

 

Here is the script I'm currently working with unsuccessfully.

 

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

 

getDate = function(dateObj){

 

var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay() : dateObj.getDay();

 

var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth() : dateObj.getMonth();

 

return dateObj.getFullYear()+'-'+month+'-'+day;

 

}

 

var campaignMember = new sforce.SObject('CampaignMember');

 

campaignMember.CampaignId = '00xxx0000xxx000';

 

campaignMember.LeadId = '{!Lead.Id}';

 

campaignMember.Lead = '{!Lead.Name}';

 

campaignMember.Status = 'Sent';

 

result = sforce.connection.create([campaignMember]);

 

if(result[0].success == 'true'){

 

    alert(campaignMember.CampaignId+' has been added to Campaign.');

 

}
2 respuestas
  1. 5 feb 2014, 0:59

    Hello, Patrick, I think you have the right idea. What's probably creating the problem is your attempt to set campaignMember.Lead to a string value. Everything else looks pretty good. I tested some simplified code[1] for a sample button in my DE org, and it appeared to work as expected.

    [1]: some simplified code (

    http://pastebin.com/UqmQWvfX)

0/9000