You need to sign in to do that
Don't have an account?

How to populate the last event date into a custom field?
Hi,
I'm looking to create a custom field on the contact object which will store the last completed event date logged against the record.
I've tried to create this through the use of formula fields and the 'last activity date' but unfortunatly this brings through the date of previous tasks and any future events scheduled. Can someone recommend a solution? Appreciate this may only be accomplished through APEX.
I'm looking to create a custom field on the contact object which will store the last completed event date logged against the record.
I've tried to create this through the use of formula fields and the 'last activity date' but unfortunatly this brings through the date of previous tasks and any future events scheduled. Can someone recommend a solution? Appreciate this may only be accomplished through APEX.
Object: Event (at creation)
Condition : If the Name Id (whoid) starts with 003 (indicating that the event is related to a contact record)
Action : Use a scheduled action that would fire 1 Hour after the End Date time.
The action you would use would be executing an Apex method with the Invocable Annotation. In Process builder you would pass the Name Id and the End Date Time as parameters.
You would use InvocableVariable annotation to store the Event's contact Id and End Date/Time in the class and use the Invocablemethod annotation so that the Apex class is available as an action within Process Builder. In your Apex method you would basically take the two parameters to update the custom contact date field.
Check out these links for more information on how to use Process Builder and Invocable Apex.
Documentation :
https://help.salesforce.com/servlet/servlet.FileDownload?file=015300000035wMDAAY
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableVariable.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm
Great simple blog post that should get you started:
http://bobbuzzard.blogspot.com/2015/02/lightning-process-builder-and-invocable.html
Here is my blog posts where I use Process Builder to execute Apex methods in a different use case:
https://tccloud.wordpress.com/2015/06/01/syncing-chatter-posts-on-case-feed-with-case-comments/
All Answers
You are correct, the completion of an event would be based on the end date being in the past.
Many Thanks,
Fiona
Object: Event (at creation)
Condition : If the Name Id (whoid) starts with 003 (indicating that the event is related to a contact record)
Action : Use a scheduled action that would fire 1 Hour after the End Date time.
The action you would use would be executing an Apex method with the Invocable Annotation. In Process builder you would pass the Name Id and the End Date Time as parameters.
You would use InvocableVariable annotation to store the Event's contact Id and End Date/Time in the class and use the Invocablemethod annotation so that the Apex class is available as an action within Process Builder. In your Apex method you would basically take the two parameters to update the custom contact date field.
Check out these links for more information on how to use Process Builder and Invocable Apex.
Documentation :
https://help.salesforce.com/servlet/servlet.FileDownload?file=015300000035wMDAAY
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableVariable.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm
Great simple blog post that should get you started:
http://bobbuzzard.blogspot.com/2015/02/lightning-process-builder-and-invocable.html
Here is my blog posts where I use Process Builder to execute Apex methods in a different use case:
https://tccloud.wordpress.com/2015/06/01/syncing-chatter-posts-on-case-feed-with-case-comments/
I'm having trouble writting the Invocable Annotation apex code.
I've tried to simplyify the criteria by only wanting to show the last date of an event logged against the account and not the contact but I'm still getting errors.
Any help would be greatly appreciated.
Thanks,
Fiona