1

I am trying to send some information to salesforce on my iOS7 device. I am using the SFRestAPI of Salesforce. In my API class I've the following:

    @HttpPost
    global static ResonseWrapper doPost(String value1){
        // Some code..
        String action = RestContext.request.params.get('value2');
    }

How am I supposed to fill value1 and value2? I am able to fill value2 in a doGet request, but I can't figure out how I fill value1 and value2 in a doPost.

I've the following post method in ios:

- (void) sendAsyncRestRequestPost
{
    SFRestRequest *postRequest = [[SFRestRequest alloc]init];
    [postRequest setEndpoint:[NSString stringWithFormat:@"services/apexrest%@/somedata/", @""]];
    [postRequest setPath:[NSString stringWithFormat:@"services/apexrest%@/somedata/", @""]];
    [postRequest setMethod:SFRestMethodPOST];
    [[SFRestAPI sharedInstance] send:postRequest delegate:self];
}

1 Answer 1

2

You can pass multiple values into the POST method:

@HttpPost
global static String doPost(String name,
    String phone, String website) {
    Account account = new Account();
    account.Name = name;
    account.phone = phone;
    account.website = website;
    insert account;
    return account.Id;
}

And then pass it formatted JSON which matches:

{
  "name" : "Wingo Ducks",
  "phone" : "707-555-1234",
  "website" : "www.wingo.ca.us"
}

This is from the Apex workbook here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_rest_code_sample_basic.htm

I don't have the iOS code to match currently, so LMK that does not get you where you need to go. Here is an article about forming a POST method request with a JSON body that may help:

https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/ios_rest_apis_using_methods.htm

3
  • This is not an option. It seems that it is possible in the Android version of the Salesforce SDK. But I can't find how to do this in the iOS version.
    – P Griep
    Sep 10, 2014 at 6:40
  • I appended the answer with a pointer on how to build the JSON body
    – joshbirk
    Sep 10, 2014 at 16:19
  • I have the same question. How can call the service if I have 3 params in the method?
    – BruceYue
    Nov 7, 2014 at 2:51

You must log in to answer this question.

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