Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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).

share|improve this answer
    
hi sfdcfox! Can we make it in a batchable class?I am getting an Unexpected Token Illegal error. –  SFDC_Geek Aug 28 at 17:01
    
I'm pretty sure you can. Can you post your updated code? –  sfdcfox Aug 28 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; } } –  SFDC_Geek Aug 28 at 18:45
    
Thanks a lot sfdcfox !!!!!! its working !!!!!!! –  SFDC_Geek Aug 28 at 18:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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