function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Darko Videnov 4Darko Videnov 4 

Sending Order and order items data after Order created

Hi all,

I'd like to write a trigger which would send Order ana order item data after Order insert to a third party syshtem through http request post. Do you have any examples for this kind of request post?
GauravGargGauravGarg
Hi Darko,

Please check this link (https://developer.salesforce.com/forums?id=906F000000092YrIAI). The conversation had discussed the same output as required in your question. Kindly go through it and let me know if you need any help. 

Thanks,
Gaurav
skype: gaurav62990
Email: gauravgarg.nmims@gmail.com
Darko Videnov 4Darko Videnov 4
Thank you. I'll give it a shot.
Darko Videnov 4Darko Videnov 4
Workflow rules doesn't help, or I don't know how to set it up. It gives me the opportunity to send order fields on insert to an endpoint but, I need to send order and order item fields to an endpoint on insert.
GauravGargGauravGarg
Can you please create a Wrapper Class:
Public Class parentClass{
  public String recordId;
  public list<childClass> childList;
}

public Class childClass{
  public String recordId;
}

populate all the values in the variable and update Wrapper as per your fields. 

Thanks,

Gaurav
Skype: gaurav62990

om sai 10om sai 10
You  will hjave to use HttpRequest and HttpResponse  mechanism.You can create header and specify Json format and then set up body and specify the fields in the body and send it across and you get the response .You will have to create Payload and send it across.

You will have to something like this.

Http http = new Http();

HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8'); // Set the body as a JSON object
request.setBody('{"name":"mighty moose"}');
HttpResponse response = http.send(request); // Parse the JSON response

if (response.getStatusCode() != 201)
{
System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus());
}

Chek below given link to read about 

http://khaidoan.wikidot.com/salesforce-developer-integration-callout






 
Darko Videnov 4Darko Videnov 4
I tried with wrapper class, but since I'm new with Apex I wasn't successful in writing the code. I had lot of problems in the syntax. I wrote one class that gets the id from the order after update trigger and pulls the data with soql and then parses the data to the second class that puts it into an http request and sends it to the external api, but the code doesnt work. I'm not sure if I patched order and order line items with soql correctly...