Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Event subject=Title
- public static EventObj upsertEvents(String sEventObj, String sObjectName, String titleField, String startDateTimeField, String endDateTimeField, String descriptionField, String userField,string whatIdField,string whoIdField){
- EventObj upsertingEvent = (EventObj)JSON.deserialize(sEventObj, EventObj.class);
- system.debug('upserting event###########'+upsertingEvent);
- sObject newRecord = Schema.getGlobalDescribe().get(sObjectName).newSObject();
- Datetime EventStartDate= datetime.valueOf(upsertingEvent.startDateTime);
- Datetime EventEndDate= datetime.valueOf(upsertingEvent.endDateTime);
- if (upsertingEvent.Id != null && isAccessible(sObjectName,'Id')){
- newRecord.put('Id',upsertingEvent.Id);
- }
- if (isAccessible(sObjectName,titleField)) {
- newRecord.put(titleField, upsertingEvent.title);
- }
- if (isAccessible(sObjectName,startDateTimeField)) {
- newRecord.put(startDateTimeField, upsertingEvent.startDateTime);
- }
- if (isAccessible(sObjectName,endDateTimeField)) {
- newRecord.put(endDateTimeField, upsertingEvent.endDateTime);
- }
- if (isAccessible(sObjectName,descriptionField)) {
- newRecord.put(descriptionField, upsertingEvent.description);
- }
- if (isAccessible(sObjectName,whatIdField)) {
- newRecord.put(whatIdField, upsertingEvent.whatId);
- }
- if (isAccessible(sObjectName,whoIdField)) {
- newRecord.put(whoIdField,upsertingEvent.whoId);
- }
- System.debug('WhoId--'+upsertingEvent.whoId );
- try {
- upsert newRecord;
- Account acc1 = null;
- if(newRecord.get(whatIdField) != null && String.valueOf(newRecord.get(whatIdField)) != '')
- {
- acc1 = [Select Id, Name from Account where Id =: String.valueOf(newRecord.get(whatIdField))];
- }
- Contact cont1 = null;
- if(newRecord.get(whoIdField) != null && String.valueOf(newRecord.get(whoIdField)) != '')
- {
- cont1 = [Select Id,Interceptor_ID__c, Name from Contact where Id =: String.valueOf(newRecord.get(whoIdField))];
- }
- //New line of code
- Datetime start= DateTime.valueOf(newRecord.get(startDateTimeField));
- Datetime enddate=DateTime.valueOf(newRecord.get(endDateTimeField));
- Map<Integer, String> MonthMap = new Map<Integer, String>();
- MonthMap.put(1, 'Jan');
- MonthMap.put(2, 'Feb');
- MonthMap.put(3, 'Mar');
- MonthMap.put(4, 'Apr');
- MonthMap.put(5, 'May');
- MonthMap.put(6, 'Jun');
- MonthMap.put(7, 'Jul');
- MonthMap.put(8, 'Agu');
- MonthMap.put(9, 'Sep');
- MonthMap.put(10, 'Oct');
- MonthMap.put(11, 'Nov');
- MonthMap.put(12, 'Dec');
- string TitleName;
- if(cont1!=null){
- System.debug('InterceptorId--' + cont1.Interceptor_ID__c);
- TitleName=cont1.Interceptor_ID__c+':'+' '+' '+MonthMap.get(start.month())+String.valueOf(start.day())+'-'+start.format('HH:mm a')+'-'+enddate.format('HH:mm a');
- }
Add Comment
Please, Sign In to add comment