1
<script src="/soap/ajax/37.0/connection.js"> </script >
<script src="/soap/ajax/37.0/apex.js"> </script >
function success() {
var alertString="Success!"; 
alert(alertString); 
}

sforce.connection.sessionId = "{!$Api.Session_ID}";
sforce.apex.execute("ChangeLogTriggerHandler", "UpdateOfSameObject","UpdateOnAnotherObject", {recordId :{!Change_Log__c.Id} " }, { onSuccess: success, onFailure: error });

How to Call two methods of handler class in Custom button scripting

In the above i am Used Class name as ChangeLogTriggerHandler

method1 : UpdateofsameObject

method2 : UpdateofAnotherObject

but its not workinng

  • srihari.. If you have 2 method you need to call 2 times.. – Ratan Paul May 19 '16 at 9:51
  • metho params means..i have two params in one method:{MethodParam:'List<Change_Log__c> newlist '} is this correct – srihari May 19 '16 at 9:53
  • yes for example if you method accept two parameters. then call like sforce.apex.execute("myClass","makeContact", {firstParam:"firstParamValue", SecondParam:"SecondaParamValue"}); this way you can pass multiple parameters – Ratan Paul May 19 '16 at 10:01
  • {!requireScript("/soap/ajax/20.0/connection.js")} {!requireScript("/soap/ajax/20.0/apex.js")} var retStr; retStr = sforce.apex.execute("ChangeLogTriggerHandler", "UpdateOfSameObject",{List<Change_Log__c> newlist :"Trigger.New"} {Record ID:'{! Change_Log__c.Id }'}); retStr = sforce.apex.execute("ChangeLogTriggerHandler", "UpdateOnAnotherObject", {List<Change_Log__c> newlist :"Trigger.New"}{Record ID:'{! Change_Log__c.Id }'}); alert('The method returned: ' + retStr); document.location = '/{!Change_Log__c.Id}'; its giving unexpected token error – srihari May 19 '16 at 10:25
1

The syntex to call is:

// call apex webservice method
        sforce.apex.execute("ClassName", "MethodName", {MethodParam:'value'});

For more information see this thread how to call remote action in javascript button without using vf page

  • Thank u Frodo...but i hav two methods – srihari May 19 '16 at 9:36
  • call it second time :) – Mr.Frodo May 19 '16 at 9:38
1

call one method after another.

sforce.apex.execute("ChangeLogTriggerHandler", "UpdateOfSameObject", {MethodParam:'value'}); 
sforce.apex.execute("ChangeLogTriggerHandler", "UpdateofAnotherObject", {MethodParam:'value'});

or

create a single method in your class ChangeLogTriggerHandler which calls both method internally and call that method from your script.

  • how to create a single method can u tell me the synatx plz – srihari May 19 '16 at 9:39
  • @srihari copy the same style as UpdateOfSameObject() or UpdateofAnotherObject(). – Saumya Ranjan Satapathy May 19 '16 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.