Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- /*
- Contact Newcon = trigger.new[0];
- Contact Oldcon = trigger.old[0];
- Contact ContactObject = new Contact();
- // This takes all available fields from the required object.
- Schema.SObjectType objType = ContactObject.getSObjectType();
- Map<String, Schema.SObjectField> M = Schema.SObjectType.Lead.fields.getMap();
- for (String str : M.keyset()) {
- try{
- System.debug('Field name: '+str +'. New value: ' + Newcon.get(str) +'. Old value: '+Oldcon.get(str));
- if(Newcon.get(str) != Oldcon.get(str))
- {
- system.debug('******The value has changed!!!! ');
- system.debug('******Changed Field Name********** ' +str);
- Set<Id> allInsertedIds = trigger.newMap.keySet();
- system.debug('******The Updated Record Id is*****!!!! ' +allInsertedIds);
- }
- }catch (Exception e)
- {
- System.debug('Error: ' + e);
- }
- }//close for
- // make the asynchronous web service callout here
- // FieldUpdateCallouts.UpdateFieldOnExternalServer();
- */
- }
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement