0
@RestResource(urlMapping='/v/restAPIKeyGeneration/*')

global with sharing class APIforKeyGeneration{


    global class Account{
    public String sname;
    public String bp;

}

    @HttpPost
    global static String CallTo(Account[] account){
    system.debug('rtrtr');
    String Name;
    String BillingCity;
    for (Account i : account) {
           Name = i.sname;
           BillingCity = i.bp;
    }
    //String key = SourceMDMRestAPI.GenerateKey(account[0].Name);
    return 'key' ;
    }


}


public class SourceMDMRestAPI{
    public static string GenerateKey(Account acc){//how can i cal this method in my webservice
Account m=new Account(Name=acc.name);
    return m.id;
}
1

Your method is trying to accept an Schema.Account (a subtype of Schema.SObject), but your webserivce method is trying to pass it a custom class APIforKeyGeneration.Account. Since they're not compatible types, you're getting a compilation error.

The minimum fix you could do is to specify the custom class in the parameter:

global class SourceMDMRestAPI{
    global static string GenerateKey(ApiForKeyGeneration.Account acc){//how can i cal this method in my webservice
        Account m=new Account(Name=acc.sname);
        return m.id;
    }
}

Also, you meant to pass the entire object, so you'd want to do something like this:

@RestResource(urlMapping='/v/restAPIKeyGeneration/*')

global with sharing class APIforKeyGeneration{


    global class Account{
        public String sname;
        public String bp;

    }

    @HttpPost
    global static String CallTo(Account[] account){
        system.debug('rtrtr');
        String Name;
        String BillingCity;
        for (Account i : account) {
            Name = i.sname;
            BillingCity = i.bp;
        }
        String key = SourceMDMRestAPI.GenerateKey(account[0]);
        return 'key' ;
    }
}

Personally, I'd consider renaming your Account class to something else to avoid confusion.

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.