You need to sign in to do that
Don't have an account?
Joshua Rood
Update CloseDate of Opportunity on eventDrop with FullCalendar
Been tinkering with FullCalendar the last few weeks and am now using it to set up an opportunity calendar based on close date. I have it set up so opportunities (events) can be dragged to a different date, and I'd like that action to update the close date of the opp. I've been digging around and trying various format and date methods, but have had no luck. Below is the pertinent snippet of code and I'd appreciate any input. I know there's a ton out there regarding string to date conversions and date formatting, but after hours of research, I just can't seem to find the right mixture.
For refernece, event.id and event.start are both Strings.
On VF Page:
In Controller:
For refernece, event.id and event.start are both Strings.
On VF Page:
eventDrop: function(event) { updateCD(event.id,event.start); },
In Controller:
public PageReference updateCD(String id, String dropDate) { Date newDate = date.parse(dropDate); for(Opportunity o : [select Id, CloseDate from Opportunity where Id=:id]) { o.CloseDate = newDate; update o; } return null; }
Hello Joshua,
You can use a remote action method which executes asyncronously to perform the update.
In Controller :On VF Page :
Regards,
Gulshan.
All Answers
Hello Joshua,
You can use a remote action method which executes asyncronously to perform the update.
In Controller :On VF Page :
Regards,
Gulshan.
Implementing your code as-is kicked back this message:
I had a feeling it was because event.start is formatted as 'EEE, d MMM yyyy HH:mm:ss', so I appended a .format() when passing that parameter to the updateCloseDate remote action method, like so:
OppCalendar_Controller.updateCloseDate(event.id, event.start.format(), function(result, event) ...
And it's working like a charm! Now it's time to do some research to figure out why that approach worked while the others I tried did not, and hopefully I understand it enough to know when to use it in the futue. Thanks again!
Thanks for marking the answer as 'Best Answer'.
The first approach did not work because FullCalendar being a JavaScript / jQuery based library, it is not compatible with Visualforce/Apex PageReference methods directly.
You could have used an <apex:actionFunction/> (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/apexcode/pages_compref_actionFunction.htm) to perform something similar while still using the original updateCD() PageReference method.
But I personally prefers RemoteAction (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting.htm) methods which are simpler to implement.
Thanks,
Gulshan.