I have developed a trigger and apex class, now what I want is that whenever a field is updated in salesforce object I want to update a similar field in the 3rd party application.
Trigger:
trigger FieldUpdateTrigger on Contact (after update) {
Set<Id> contactIds = new set<Id>();
for(Contact Values : Trigger.new) {
Contact oldValues = Trigger.oldMap.get(Values.Id);
if(Values != oldValues) {
ContactIds.add(values.id);
}
}
if (!ContactIds.isEmpty()){
FieldUpdateCallouts.UpdateFieldOnExternalServer(ContactIds);
}
}
Future Method Class:
public class FieldUpdateCallouts {
@future (callout=true)
public static void UpdateFieldOnExternalServer(Set<Id> ContactIds){
List<Contact> ConList = new List<Contact>();
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
String username='';
String password='';
Blob headerValue = Blob.valueOf(username +':' +password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
String targetString ='{"str": "Newcon.get(str)"}';
String encodedString = EncodingUtil.urlEncode(targetString,'UTF-8');
req.setBody('encodedString');
req.setEndpoint('/admin/api');
HttpResponse res = new HttpResponse();
res = http.send(req);
}