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
Rick SF AdminRick SF Admin 

Custom button that triggers email alert and a field update

I have a custom object (Resources__c). I'm trying to create a custom button on the custom object that when clicked, will updated a picklist value to "Requested" and trigger an email alert (RR Alert). I know I can accomplish this without using a custom button (using WFR), but the requestor wants a button on the custom object.  
Raj VakatiRaj Vakati
HI Rick,
I prefer to do it with workflow the reason it when switch from classic to lighting on click javascript button will not work.. 


Option 1 : Here is the javascript onclikc button to update the picklist values and send email from WFR .. 
 
{!REQUIRESCRIPT("/soap/ajax/42.0/connection.js")}

try{

    var res = new sforce.SObject("Resources__c");

    res.Id = "{!Resources__c.Id}";
    res.PickList__c ='Requested';
  
    var result = sforce.connection.update([res]);

    if(result[0].success === "true"){
        location.reload();
    }
    else{
        alert(
            "An Error has Occurred. Error: " +
            result[0].errors.message
        );
    }
}
catch(e){
    alert(
        "An unexpected Error has Occurred. Error: " + 
        e
    );
}


Option 2 : Create a lightning component and call from the visualforce page. You could able to create a button for the same VF page