1

I'm working on a Rest service Where I'd Patch the incoming request. I need some help on how to test the service and with the apex class . Below is the sample snippet.

"request": {
        "Data": {
                   value : null,
                   SCA   : null

            "Address": [
                {
                    city : null,
                    Zip  : null,
                Country  : null 
                }
            ],
            "addressValue": null 
       }

Apex Class:

@RestResource(urlMapping='/*')
global with sharing class MyRestResource {

public class Data {
public String value;
public String SCA;
public String Addressvalue;
public List<Address> Address;

}

public class Address {
    public String City;
    public String Zip;
    public String Country;
}

@HttpPut
global static String doPatch() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
  // check for a opportunity with below opportunityid and opp.accountid == below accountid then perform update. 
}

}

<instancename>/accountid/contactid/opportunityid

is how I'm looking to make the request.

I'm trying to use some chrome plugins like DHC/rest client. But I don't know on how exactly to prepare and pass the request through the plugins to match the class.

Any help is much appreciated. Thanks!

1

1) Your JSON body is not valid, use http://jsonlint.com/ before passing the request body

2) Your class is incomplete / you have not pasted complete class inyour question.

3) There are many tools thought I prefer workbench since I have been using it for a long time (personal fav) https://workbench.developerforce.com/

STEP 1: Go to the above link, authenticate using your sandbox or PRD credentials.

STEP 2: From the tabs at the top pick "REST EXPLORER" from the "Utilities" drop down.

STEP 3: Pick "PUT"as your http method and paste (If I were you I would give the url mapping a proper version and give it a proper endpoint name, something like @RestResource(urlMapping='/v1.0/myuri'))

paste /services/apexrest/* in the text box before the execute button and paste the request body and hit execute.

you should be able to see pretty/ raw response. My example class:

@RestResource(urlMapping='/*')
global with sharing class MyRestResource1 {

@HttpPut
global static String doPatch() {
return 'hello';
}

}

Workbench screen: enter image description here

| improve this answer | |

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.