Created
September 7, 2018 06:50
-
-
Save choudharymanish8585/2c06dd90e108de98a6f1c0605d90f188 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class FullCalendarDemo{ | |
@RemoteAction | |
global static List<User_Calendar__c> getEvents() { | |
String userId = UserInfo.getUserId() ; | |
List<User_Calendar__c> userCalendar = [SELECT Id, Name, User__r.Name, | |
Event__c, Event__r.Name, Event__r.Start_Time__c, Event__r.End_Time__c | |
FROM User_Calendar__c | |
WHERE User__c=:userId]; | |
if(userCalendar.size()>0){ | |
return userCalendar; | |
} else{ | |
return null; | |
} | |
} | |
@RemoteAction | |
global static List<User_Calendar__c> createOrUpdateEvents(String calendarEvent) { | |
//Geting Calendar_Event__c object from received Json String | |
Calendar_Event__c eventObject = ((Calendar_Event__c) JSON.deserialize(calendarEvent, Calendar_Event__c.class)); | |
//you need to put proper regex to validate recordId | |
Boolean isOldRecord = eventObject.Id != null; | |
upsert eventObject; | |
//If its new record, create User Calendar record as well | |
if(!isOldRecord){ | |
User_Calendar__c userCalendar = new User_Calendar__c(Event__c=eventObject.Id, User__c=UserInfo.getUserId()); | |
insert userCalendar; | |
} | |
return getEvents(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment