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()); } }}3 answers
Do this
and in your methods, depending on which one, do the followingif (trigger.isInsert) {
postcallout(string Id);
} else if (trigger.isUpdate) {
putcallout(string id);
}
request.setMethod('POST') OR request.setMethod('PUT);