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
Will EdwardsWill Edwards 

How do I create a button that updates the record status and creates a related event?

I want to click a button on a campaign member record that will:
  1. Update the campaign record status
  2. Create a new related event that I can update
Thanks.
Pankaj MehraPankaj Mehra
Hi Will

create a new javascript button

Navigate to “Customize | Campaign | Button, Links and Actions”.
Create new button of type “Detail Page Button” , behavior “Execute Javascript” and content source “Onclick JavaScript”.

 
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 

var accnt = new sforce.SObject("Account");
accnt.Id = '{!Account.Id}';
accnt.Name = prompt('Enter new Account Name','{!Account.Name}');

var result = sforce.connection.update([accnt]);
if(result[0].getBoolean("success"))
{
   alert('Account updated successfully');
   window.location.reload();
}
else{
  alert('Error : '+result);
}

Similar to above example you can create and update records on button click.

Thanks
Will EdwardsWill Edwards
Pankaj, thanks. This is what the button already does. Can you help? It fills in some fields automatically. /00U/e?RecordType=012500000001QyU&ent=Event &evt2={!CampaignMember.Contact}&evt3_lkid={!CampaignMember.CampaignId} &evt3={!CampaignMember.Campaign} &evt4={!TODAY()} &evt5={!CampaignMember.Campaign}+{!CampaignMember.CompanyOrAccount}+{!CampaignMember.Contact} &CF00N38000003WwBq={!CampaignMember.CompanyOrAccount}
Pankaj MehraPankaj Mehra
Hi Will,

You can update the campaign first and then redirect to the URL you created:


 
Will EdwardsWill Edwards
Can you give me some code to do that please? Thanks.
Pankaj MehraPankaj Mehra
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 

var cmp = new sforce.SObject("Campaign");
cmp.Id = '{!Campaign.Id}';
cmp.status = 'Status';

var result = sforce.connection.update([cmp]);
if(result[0].getBoolean("success"))
{
   alert('Account updated successfully');
   window.location.url = '/00U/e?RecordType=012500000001QyU&ent=Event &evt2={!CampaignMember.Contact}&evt3_lkid={!CampaignMember.CampaignId} &evt3={!CampaignMember.Campaign}&evt4={!TODAY()}&evt5={!CampaignMember.Campaign}+{!CampaignMember.CompanyOrAccount}+{!CampaignMember.Contact} &CF00N38000003WwBq={!CampaignMember.CompanyOrAccount}';
}
else{
  alert('Error : '+result);
}