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

4
  • srihari.. If you have 2 method you need to call 2 times.. Commented May 19, 2016 at 9:51
  • metho params means..i have two params in one method:{MethodParam:'List<Change_Log__c> newlist '} is this correct Commented May 19, 2016 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 Commented May 19, 2016 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 Commented May 19, 2016 at 10:25

2 Answers 2

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

2
  • Thank u Frodo...but i hav two methods Commented May 19, 2016 at 9:36
  • call it second time :) Commented May 19, 2016 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.

2
  • how to create a single method can u tell me the synatx plz Commented May 19, 2016 at 9:39
  • @srihari copy the same style as UpdateOfSameObject() or UpdateofAnotherObject(). Commented May 19, 2016 at 9:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.