+ Start a Discussion
Rahul H 4Rahul H 4 

when the User clicks the button “Activate Accounts”, the selected accounts should get the status Active = “Yes”.

The button with the label “Activate Accounts”, when the User clicks the button “Activate Accounts”, the selected accounts should get the status Active = “Yes”.

The user also needs to get feedback about the successful update or any errors. The list should refresh after a successful update
Best Answer chosen by Rahul H 4
Deepali KulshresthaDeepali Kulshrestha
Hi Rahul,
Please try this simple code to get the expected results.

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

// identify the record 
var o = new sforce.SObject("Account"); 
o.id = "{!Account.Id}"; 

o.Active__c = 'Yes'; 
var result = sforce.connection.update([o]); 

//refresh the page 
//window.location.reload(); 

if( result[0].success === "true" ) { 
window.location.reload(); 

else { 
alert( result[0].errors.message ); 
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha

All Answers

Raju yadavRaju yadav
Hi @Rahul H 4
You can use wrapper class with checkbox.
user select the number of account by clicking the ckeckbox after that they click the Activate Accounts button 
after the clicking the button we can update the status active = 'yes' in backend.
I think it should help you.
Deepali KulshresthaDeepali Kulshrestha
Hi Rahul,
Please try this simple code to get the expected results.

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

// identify the record 
var o = new sforce.SObject("Account"); 
o.id = "{!Account.Id}"; 

o.Active__c = 'Yes'; 
var result = sforce.connection.update([o]); 

//refresh the page 
//window.location.reload(); 

if( result[0].success === "true" ) { 
window.location.reload(); 

else { 
alert( result[0].errors.message ); 
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
This was selected as the best answer
Rahul H 4Rahul H 4
Thanks much
Rahul H 4Rahul H 4
Hey Deepali,
Thanks for the reply
Can we update multiple accounts? For example: If I have a checkbox and I select multiple accounts and then I click on the button "Activate Accounts", what should be the logic?