6

i have one Ajax custom button

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} 
alert("k"); 
sforce.apex.execute("Account_chk","method1",{i:"{!Account.Id}"});

that callsAccount_chkclass

public class Account_chk {
  public void method1(Id i) {
    Account a=[select Id2_vod__c from Account where id = :i];
    a.Id2_vod__c= 'kkkk';
    update a;
  }
}

errors out

{faultcode:'soapenv:Client',faultstring:'No operation available for request{http://soap.sforce.com/schemas/package/Account_chk}method1, please check the WSDL for the service.',}

please help

1 Answer 1

11

You must use the webservice keyword to generate a service, and it must be static, since it won't be considered constructed.

See http://teachmesalesforce.wordpress.com/2011/05/02/call-apex-code-from-a-custom-button/ as an example (not my blog).

3
  • hi sfdcfox! Can we make it in a batchable class?I am getting an Unexpected Token Illegal error. Commented Aug 28, 2014 at 17:01
  • I'm pretty sure you can. Can you post your updated code?
    – sfdcfox
    Commented Aug 28, 2014 at 18:36
  • global class Account_chk { WebService static void method1(Id i) { Account a=[select Id2_vod__c from Account where id = :i]; a.Id2_vod__c= 'kkkk'; update a; } } Commented Aug 28, 2014 at 18:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .