Can I bypass a Validate Record Data Trigger if new records i

Posted by stephen.vanrooyen on 02-Mar-2017 03:06

Hi Guys,
 
I have a Validate Record Data trigger on an object which prevents the user from creating records if a related object does not have records.
This does exactly what I want it to do from the UI, however I would like to bypass this validation when I create new records from a trigger.
 
I created a trigger on another object that creates a record for this object using the rbv_api.createRecord() method.
I’ve tried using the rbv_api.isAPI() or rbv_api.isUI() method to try an bypass the validation, but the rbv_api.createRecord() is still regarded as the UI.
 
Is there a way to achieve this?
 
Regards,
http://www.aigs.co.za/templates/email_signatures/2016/stephen_van_rooyen.png
 

Posted by mpiscoso@gmail.com on 02-Mar-2017 06:36

I can suggest two ways.

1. Don't use a validate record data trigger and don't set the value is always required flag on the desired field. Instead, use your pages to set the field as required.

2. Create a checkbox field such as "validate relationship?" Which should have an initial value of true for all records. Use this field in your trigger as a condition where you only validate if the checkbox is set to true. On your createRecord() api, set the value of your trigger created records to false so that they wont get validated.

Also, if you plan to create a lot of records using createRecord() you might encounter governor limits such as no. Of triggers ran per transaction or formula runtime. I suggest you also look into the combination of setFieldValue() + runTrigger() on a Create Record Trigger which has a data map and has run dependent triggers checked in its trigger options. Although if you are only creating a small amount of records, it should be good

Hope this helps.

All Replies

Posted by mpiscoso@gmail.com on 02-Mar-2017 06:36

I can suggest two ways.

1. Don't use a validate record data trigger and don't set the value is always required flag on the desired field. Instead, use your pages to set the field as required.

2. Create a checkbox field such as "validate relationship?" Which should have an initial value of true for all records. Use this field in your trigger as a condition where you only validate if the checkbox is set to true. On your createRecord() api, set the value of your trigger created records to false so that they wont get validated.

Also, if you plan to create a lot of records using createRecord() you might encounter governor limits such as no. Of triggers ran per transaction or formula runtime. I suggest you also look into the combination of setFieldValue() + runTrigger() on a Create Record Trigger which has a data map and has run dependent triggers checked in its trigger options. Although if you are only creating a small amount of records, it should be good

Hope this helps.

Posted by stephen.vanrooyen on 02-Mar-2017 07:30

Hi,
 
Thanx for the feedback.
 
I implemented suggestion #2, and it works like a charm. 👍
 
Thanks for the heads up, but I’m not creating that many records.
The main reason for using the createRecord() methods is because the values I’m using to create this new record comes from multiple objects (which I don’t think is currently possible using Data Maps.)
 
Regards,
http://www.aigs.co.za/templates/email_signatures/2016/stephen_van_rooyen.png
 

Posted by mpiscoso@gmail.com on 02-Mar-2017 07:41

It "could" be available if you create clones of the fields on the object and use those in conjunction with setFieldValue() and Data Maps.

Ex.

- Have value on related object A (text field)

- Have text field on object to catch the value

- Use setFieldValue() to set the field on the text field

- Use the text field in the Data Map

It might seem like a lot of steps (get the data > set the data on data map fields > runTrigger API) but when dealing with a large data set, this is the only way that I've found to work where you'll encounter less limits due to the runtime not being a "single" transaction as with createRecord() and being divided into multiple create record triggers.

I'll leave this here for future reference.

Good to know I was able to help!

This thread is closed