A great developer crafts elegant solutions, while a true pro delivers on schedule, every time!
Guys, let's enhance the testing techniques in Salesforce callouts, we have so many options available there just to be utilized. So let's deep dive to make your development more robust and timeline-friendly than ever!
Many a time it happens that your 3rd party environment or web service is not ready and you end up developing the piece from your end to GET, POST, DELETE or PUT callouts. Now as the 3rd party services are not active to support your callouts, you just have a JSON format or an example JSON. You have many ways from which you may still be able to test and make sure your development is working as expected and you may be able to fix any bugs detected and keep up with the timeline.
Things you will need before you consider taking this approach.
- Your side of callout development is partially/fully complete.
- You are aware of the HTTP method to be used.
- You have the JSON architecture or an example JSON.
- Open a notepad.
- See below and understand, the things directly inside the curly brackets are a single entity and any square brackets work as a list of entities. Create your JSON following this convention. Note - Don't leave extra white spaces to save yourself from troubles
- [ { "Name" : "noni1", "Description" : "Noni1 Company", "Account Number" : "1ABC1234" }, { "Name" : "noni2", "Description" : "Noni2 Company", "Account Number" : "2ABC1234" } ]
- Copy your created JSON lines from the notepad.
- Go to the JSON hosting service, you might have to create an account, but it can be done from your personal mail.
- Find an option to create a JSON bin and paste your JSON data to create your JSON bin.
- The website will return with the address of your JSON Bin, save it somewhere, this is the callout URI that you will be using.
- It will also return with another URL where later on you may go and make changes to your JSON file.
- The number of JSON you may upload in a day may or may not be limited.
- From Setup, enter Remote Site Settings in the Quick Find box, then select Remote Site Settings.
- Click New Remote Site.
- Enter a descriptive term for the Remote Site Name.
- and paste the URL of your JSON bin for the remote site.
- Optionally, enter a description of the site.
- Click Save.
Http http = new Http();HttpRequest request = new HttpRequest();request.setEndpoint('<Paste JSON bin URL>');request.setMethod('GET'); //your required methodHttpResponse response = http.send(request);if(response.getStatusCode() == 200) {system.debug(response.getBody());<Your business logic here>}
Comments
Post a Comment
Please comment your thoughts. It helps.