3

I am trying to send this data to another salesforce org REST endpoint.

map<string,Set<string>> mp = new map<string,Set<string>>() ;
mp.put('Data1',new set<String>{'Data11:True'});
System.debug(mp);
String jsonstr = (String)JSON.serialize(mp);
System.debug(jsonstr);

Destination Org request respose i received as like below,

 System.debug(String.valueOf(RestContext.request.params));

// Output :  {{"DATA1":["Data11:TRUE"]}=}

In the above output why i got extra braces at start { and the extra symbol at the end =}.

So I am writing string method to eliminate these characters.

Addition to this my request is in the below form:

 RestRequest:[
    headers=
    {Accept=text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2, Cache-Control=no-cache, 
    CipherSuite=....., 
    Connection=keep-alive, 
    Content-Type=application/x-www-form-urlencoded, 
    Host=...., 
    Pragma=no-cache, 
    SFDC_STACK_DEPTH=1, 
    User-Agent=SFDC-Callout/40.0, 
    X-Salesforce-SIP=...., ...}, 
    httpMethod=POST, 
    params={{"DATA1":["Data11:TRUE"]}=}, 
    remoteAddress=...., 
    requestBody=Blob[0], 
    requestURI=/PermSetDelegation/, resourcePath=/services/apexrest/PermSetDelegation/*]

Here is how I solved it:

  1. I set the below in post request.setHeader('Content-type','Application/json');

  2. At the rest end i am using the below to get the JSON. Now the string looks exact JSON which is sent from the source

    RestContext.request.requestBody.toString();
    
  • Putting your code in Execute Anonymous, my output is simply {"Data1":["Data11:True"]}. – Adrian Larson Jun 14 '17 at 10:40
  • Also you should just post the solution as an answer. – Adrian Larson Jun 14 '17 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.