Advertisement
Guest User

Untitled

a guest
Jan 29th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. trigger FieldUpdateTrigger on Contact (after update) {
  2. Set<Id> contactIds = new set<Id>();
  3. for(Contact Values : Trigger.new) {
  4. Contact oldValues = Trigger.oldMap.get(Values.Id);
  5. if(Values != oldValues) {
  6. ContactIds.add(values.id);
  7. }
  8. }
  9. if (!ContactIds.isEmpty()){
  10. FieldUpdateCallouts.UpdateFieldOnExternalServer(ContactIds);
  11. }
  12. /*
  13. Contact Newcon = trigger.new[0];
  14. Contact Oldcon = trigger.old[0];
  15. Contact ContactObject = new Contact();
  16. // This takes all available fields from the required object.
  17. Schema.SObjectType objType = ContactObject.getSObjectType();
  18. Map<String, Schema.SObjectField> M = Schema.SObjectType.Lead.fields.getMap();
  19. for (String str : M.keyset()) {
  20. try{
  21. System.debug('Field name: '+str +'. New value: ' + Newcon.get(str) +'. Old value: '+Oldcon.get(str));
  22. if(Newcon.get(str) != Oldcon.get(str))
  23. {
  24. system.debug('******The value has changed!!!! ');
  25. system.debug('******Changed Field Name********** ' +str);
  26. Set<Id> allInsertedIds = trigger.newMap.keySet();
  27. system.debug('******The Updated Record Id is*****!!!! ' +allInsertedIds);
  28. }
  29. }catch (Exception e)
  30. {
  31. System.debug('Error: ' + e);
  32. }
  33. }//close for
  34. // make the asynchronous web service callout here
  35. // FieldUpdateCallouts.UpdateFieldOnExternalServer();
  36. */
  37. }
  38.  
  39. public class FieldUpdateCallouts {
  40. @future (callout=true)
  41. public static void UpdateFieldOnExternalServer(Set<Id> ContactIds){
  42. List<Contact> ConList = new List<Contact>();
  43. Http http = new Http();
  44.  
  45. HttpRequest req = new HttpRequest();
  46. req.setMethod('POST');
  47. req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
  48. String username='';
  49. String password='';
  50. Blob headerValue = Blob.valueOf(username +':' +password);
  51. String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
  52. req.setHeader('Authorization', authorizationHeader);
  53. String targetString ='{"str": "Newcon.get(str)"}';
  54. String encodedString = EncodingUtil.urlEncode(targetString,'UTF-8');
  55. req.setBody('encodedString');
  56. req.setEndpoint('/admin/api');
  57. HttpResponse res = new HttpResponse();
  58. res = http.send(req);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement