• RQureshi
  • NEWBIE
  • 5 Points
  • Member since 2020
  • Mr
  • Connexin Limited


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello, My requirement is whenever we create a record in Salesforce, it should create an incident in external system populating salesforce fields I'm sending a post request to External webservice using REST API. I'm able to create an incident in external system and send salesforce record fields, how do i update an incident in external system because In trigger i have before insert and before update which creates a duplicate incident on update. I want to update the old incident with new values if there is any change in Salesforce record not create a new incident?
External system fields (Name and Incident group)
Salesforce fields( Multiple fields)
 
public class RadarUpdate {
@future (callout=true)
  public static void postcallout(string Id) {  
  Patient_Satisfaction__c c = [select id, Name,  Description_of_Feedback__c from Patient_Satisfaction__c where Patient_Relation__c ='Referred to Privacy Office' order by         createdDate desc limit 1];
    JSONGenerator gen = JSON.createGenerator(true);
    gen.writeStartObject();
    gen.writeObjectField('Name',c.Name);
    gen.writeObjectField('description',c.Description_of_Feedback__c);
    gen.writeObjectField('incident_group_id',7387);
    gen.writeEndObject();
    String jsonS = gen.getAsString(); 
    System.debug('jsonMaterials'+jsonS);
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('https://api.radarfirst.com/incidents');
    request.setMethod('POST');
    request.setHeader('Content-Type','application/json;charset=UTF-8');
    request.setHeader('User-agent', 'Salesforce-integration-client');
    request.setHeader('Authorization','Bearer  123');
    request.setBody(jsonS);
    // Set the body as a JSON object
    HttpResponse response = http.send(request);
    if (response.getStatusCode() != 201) {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
    } else {
    System.debug(response.getBody());
    }
    }
}