SHARE
TWEET

addLeadToCampaign.js

martyychang Feb 4th, 2014 964 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * JavaScript for custom Lead button to add the currently displayed lead
  3.  * on the lead detail page to a hard-coded campaign.
  4.  *
  5.  * @see https://success.salesforce.com/answers?id=90630000000hZxyAAE
  6.  */
  7. // FIX:02 Changed API version from 27.0 to 29.0
  8. {!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
  9.  
  10. /* FIX:01 Removed due to unclear reason why this code is here
  11. getDate = function(dateObj){
  12. var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay() : dateObj.getDay();
  13. var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth() : dateObj.getMonth();
  14.  
  15. return dateObj.getFullYear()+'-'+month+'-'+day;
  16. }*/
  17.  
  18.  
  19. var campaignMember = new sforce.SObject('CampaignMember');
  20.  
  21. campaignMember.CampaignId = '701i0000000abru';
  22. campaignMember.LeadId = '{!Lead.Id}';
  23. // FIX:03 Not sure why this is here. Specifying CampaignMember.LeadIs
  24. //        shoudl be sufficient
  25. //campaignMember.Lead = '{!Lead.Name}';
  26. campaignMember.Status = 'Sent';
  27.  
  28.  
  29.  
  30. result = sforce.connection.create([campaignMember]);
  31.  
  32. if(result[0].success == 'true'){
  33.     alert(campaignMember.CampaignId+' has been added to Campaign.');
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top