Validating on when a related record was attached

Posted by wytkat28 on 21-Oct-2014 15:35

Want to run a trigger based on the most recent record attached. I can see in the audit trail when the change is made, it tells me that the field was updated from related record A to related records A and B. Where I can pull the date when the related record was attached?

All Replies

Posted by Godfrey Sorita on 21-Oct-2014 16:30

Hi Katie,

Pulling the data on the audit trail might cause performance issues on your trigger in the future. Instead, you can create a trigger which updates a specific date field whenever the lookup field is updated.

Below are the simple steps to accomplish this:
1. Create an Update Field Value trigger.
2. Set the Timing to 'After Update'.
3. Select the lookup field on 'On Field Change'.
4. Paste this code to the formula body to set the current date, relative to the current user's time zone: new Date(rbv_api.getCurrentDate());
5. Make sure the query API permission are enabled for this object and save the trigger.


Regards,
Godfrey

Posted by wytkat28 on 22-Oct-2014 16:03

Well, that technically answers my question. I was hoping for something that existed in Rollbase that I could pull in as opposed to a trigger to generate a new value on update. Or should I assume that's probably not the case?

Posted by Godfrey Sorita on 22-Oct-2014 16:55

You can do either of the following to pull data from audit trail:

1. Use selectQuery API. Paste the code below to your trigger to query the latest date the lookup field has been updated. 

rbv_api.selectValue("SELECT createdAt FROM $ACT_TRAIL WHERE objId = ? AND content LIKE ?", {!id}, 'Value of First Name field was changed%');

2.  Use Related Activity Trail tokens. Paste the code below to your trigger to print all audit trail content related to the current record:

{!#LOOP_BEGIN.$ACT_TRAIL}
  rbv_api.println('{!$ACT_TRAIL.content}');
  rbv_api.println('{!$ACT_TRAIL.createdAt}');
{!#LOOP_END.$ACT_TRAIL}

**You will need to add if conditions to extract the latest date when lookup was attached.

**This option is very inefficient.


This thread is closed