0
{!REQUIRESCRIPT("/resource/1468830130000/ConnectionJsNoAgent")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 
var result = sforce.apex.execute("SendSms","callSendWSrvId", "{id'{!CKSW_BASE__Service__c.Id}'}"); 
alert('result '); 
window.location.reload();

I keep getting errors and no matter what i do i cant seem to get it to work. I tried it with a @future @remoteAction and standard methods.

@future (callout = true)
    public static void sendWSrvId(String Id) {
//logic
}

Update: Forgot to mention I' using this in a custom button.

Update 2: Error after switching to webservice enter image description here

1
  • 1
    after Id you forgot : – Ratan Paul Jul 18 '16 at 11:40
1

The params object (third parameter to sforce.apex.execute) should be a normal object, not a string. Also, that means your code is malformed.

Here's a corrected version of your JavaScript:

var result = sforce.apex.execute("SendSms","callSendWSrvId", {id: '{!CKSW_BASE__Service__c.Id}'});     
alert(result); 
2
  • Can you please explain how the third param should be set. – user8310 Jul 18 '16 at 11:55
  • @user8310 It should be a normal JavaScript object or JSON string. I normally avoid writing JSON manually when I can avoid it. Also, as Jsm said, the Apex should be webservice. See my JavaScript example in this answer. – sfdcfox Jul 18 '16 at 12:00
0

If you are invoking a method from a Custom button it should be a webService method.

Try this:

Apex Class:

global class SendSms {
        webService static void sendWSrvId(Id recId) {
            //logic
        }
    }

Button code:

{!REQUIRESCRIPT("/resource/1468830130000/ConnectionJsNoAgent")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 
var result = sforce.apex.execute("SendSms","sendWSrvId", "{recId: '{!CKSW_BASE__Service__c.Id}'}"); 
alert('result '); 
window.location.reload();
1
  • I switched it to a webservice but its still not working. I copied your code as well in case i missed something but it didnt change anything. – user8310 Jul 18 '16 at 11:54

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.