I'm just trying to call a post method if a multipicklist value is selected at the time of update. Not sure where exactly I'm making mistake
trigger RadarFirst on Patient_Satisfaction__c (before update) {
for (Patient_Satisfaction__c cc : Trigger.new){
if(cc.Patient_Relation__c.contains('Referred to Privacy Office')){
RadarUpdate.postcallout(cc.id);
}
}
}
public class RadarUpdate {
@future (callout=true)
public static void postcallout(string Id) {
Patient_Satisfaction__c c = [select id, Name, Reporter_Phone__c,Reporter_First_Name__c,Reporter_Last_Name__c, Reporter_Email__c,
Description_of_Feedback__c from Patient_Satisfaction__c where Patient_Relation__c ='Referred to Privacy Office' order by lastmodifiedDate desc limit 1];
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeObjectField('name', c.Name);
gen.writeObjectField('incident_group_id', 7387);
gen.writeObjectField('description',c.Description_of_Feedback__c);
gen.writeFieldName('submitted_by');
gen.writeStartObject();
gen.writeStringField('given_name',c.Reporter_First_Name__c);
gen.writeStringField('surname', c.Reporter_Last_Name__c);
gen.writeStringField('phone',c.Reporter_Phone__c);
gen.writeStringField('email',c.Reporter_Email__c);
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 eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.ayMT8mfFcCqkLyRGZsmodZfjcDpm-cGV0f3EJ_5NF-KU-DJ9DVWrUEzO4XUj4LjKLlU9ub9793bJuZdNkAGFJbUmecq7k3bfvVbJmuBwzlJny3wHnSLpf0khXR_UT5FIiKHji5iSmbE8Ojc-qfPwwn2B5S7SAZ44LAB-5ag7AErALqEOgSLYm0CKIGNvYGFmMsyJZbmgm4TD8FTfS3pcoC13lFo7V4U5kJOyFvEGqVAZLdT3p-VdxRIJ9qfbP8AlKrcIS4Znm-bq3c-iYqk7JfujalXBYgA_YltelAGrzFVjDMXcahFkaK71rGSFyaRv_O3xPqP3P9RG9Ga5ohx9vw.vCTJwd85Lq9TTslt.i6A8KSwPc6Nole_lwpo8pNDucVW0ENFbCSvTPajl3DpS0H6eb3C7ccyJYAT1Oi_s4RFtfluMHPOXl6CBKM_Qfj8RUQuLgnVBWj16CJeZm1fXvt0.wJKuy-m5GsNs4d_ecc2e5A');
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());
}
}
}
cc.Patient_Relation__c.contains()
, ifPatient_Relation__c
happens to be null. – Derek F Apr 13 '20 at 23:53