Wednesday, June 3, 2015

Salesforce Button: Change status of Lead Status field.

Take an example a company uses Salesforce CRM in their organization. A user has come to you with request that he wants a button on Lead record detail page to change Lead Status field to “Closed – Not Converted”. How can this be done using button?
The system administrator needs to create button.

Navigation: Setup > Customize > Leads > Buttons, Links and Actions

New Button or Link

Enter the details
Label: Change Lead Status to Closed – Not Converted.
Name: Auto populated
Description: Change Lead Status to Closed – Not Converted
Display Type: Detail Page Button
Behavior: Execute JavaScript
Content Source: OnClick JavaScript

Code
{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}
var objLead = new sforce.SObject('Lead');
objLead.Id = '{!Lead.Id }';
objLead.Status = 'Closed - Not Converted';
var result = sforce.connection.update([objLead]);
if(result[0].success=='true'){
alert('The Lead was Updated Successfully');
location.reload(true);}

Click Syntax for errors and save.

When you click save following page is displayed notifying us to add the button to the page layout.

Add Change Lead Status to Closed – Not Converted button to the page layout.

Lead detail page. Lead Status: Working – Contacted. Now I want to change the status to Closed – Not Converted. Click the button.

The Lead was updated successfully.

Lead Status changed to Closed – Not Converted.