Guest User

Untitled

a guest
Jun 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. Event subject=Title
  2.  
  3. public static EventObj upsertEvents(String sEventObj, String sObjectName, String titleField, String startDateTimeField, String endDateTimeField, String descriptionField, String userField,string whatIdField,string whoIdField){
  4. EventObj upsertingEvent = (EventObj)JSON.deserialize(sEventObj, EventObj.class);
  5. system.debug('upserting event###########'+upsertingEvent);
  6. sObject newRecord = Schema.getGlobalDescribe().get(sObjectName).newSObject();
  7. Datetime EventStartDate= datetime.valueOf(upsertingEvent.startDateTime);
  8. Datetime EventEndDate= datetime.valueOf(upsertingEvent.endDateTime);
  9. if (upsertingEvent.Id != null && isAccessible(sObjectName,'Id')){
  10. newRecord.put('Id',upsertingEvent.Id);
  11. }
  12. if (isAccessible(sObjectName,titleField)) {
  13. newRecord.put(titleField, upsertingEvent.title);
  14.  
  15. }
  16. if (isAccessible(sObjectName,startDateTimeField)) {
  17. newRecord.put(startDateTimeField, upsertingEvent.startDateTime);
  18. }
  19. if (isAccessible(sObjectName,endDateTimeField)) {
  20. newRecord.put(endDateTimeField, upsertingEvent.endDateTime);
  21. }
  22. if (isAccessible(sObjectName,descriptionField)) {
  23. newRecord.put(descriptionField, upsertingEvent.description);
  24. }
  25.  
  26.  
  27. if (isAccessible(sObjectName,whatIdField)) {
  28. newRecord.put(whatIdField, upsertingEvent.whatId);
  29. }
  30. if (isAccessible(sObjectName,whoIdField)) {
  31. newRecord.put(whoIdField,upsertingEvent.whoId);
  32. }
  33.  
  34. System.debug('WhoId--'+upsertingEvent.whoId );
  35. try {
  36. upsert newRecord;
  37.  
  38. Account acc1 = null;
  39. if(newRecord.get(whatIdField) != null && String.valueOf(newRecord.get(whatIdField)) != '')
  40. {
  41. acc1 = [Select Id, Name from Account where Id =: String.valueOf(newRecord.get(whatIdField))];
  42. }
  43.  
  44. Contact cont1 = null;
  45.  
  46. if(newRecord.get(whoIdField) != null && String.valueOf(newRecord.get(whoIdField)) != '')
  47. {
  48. cont1 = [Select Id,Interceptor_ID__c, Name from Contact where Id =: String.valueOf(newRecord.get(whoIdField))];
  49. }
  50. //New line of code
  51. Datetime start= DateTime.valueOf(newRecord.get(startDateTimeField));
  52. Datetime enddate=DateTime.valueOf(newRecord.get(endDateTimeField));
  53.  
  54. Map<Integer, String> MonthMap = new Map<Integer, String>();
  55. MonthMap.put(1, 'Jan');
  56. MonthMap.put(2, 'Feb');
  57. MonthMap.put(3, 'Mar');
  58. MonthMap.put(4, 'Apr');
  59. MonthMap.put(5, 'May');
  60. MonthMap.put(6, 'Jun');
  61. MonthMap.put(7, 'Jul');
  62. MonthMap.put(8, 'Agu');
  63. MonthMap.put(9, 'Sep');
  64. MonthMap.put(10, 'Oct');
  65. MonthMap.put(11, 'Nov');
  66. MonthMap.put(12, 'Dec');
  67. string TitleName;
  68. if(cont1!=null){
  69. System.debug('InterceptorId--' + cont1.Interceptor_ID__c);
  70. TitleName=cont1.Interceptor_ID__c+':'+' '+' '+MonthMap.get(start.month())+String.valueOf(start.day())+'-'+start.format('HH:mm a')+'-'+enddate.format('HH:mm a');
  71. }
Add Comment
Please, Sign In to add comment