Create Object Records Via Trigger than then creates records

Posted by dubosegriffin on 10-Oct-2014 18:22

So here is the scenario.

I have a trigger on object 1 that creates records on the object using javascript. Here is an example:

if({!kickoff}){
var g = new Array();
g["name"]="01-Kickoff";
g["R8666824"]={!id};
g["total_budget"]=parseInt(2);
g["default_milestone"]=true;
var newId = rbv_api.createRecord("milestone3", g);
}

I then have another trigger on object 2 that creates record on the object 2 based on the creation of the record on object 1. Here is the script on the second trigger.

var name = '{!name#text}';
var def = '{!default_milestone#value}';
var product = '{!R8666824.product#code}';

if (def == "true"){
if(name == "01-Kickoff"){
var a = new Array();
a["name"]="Kickoff Call";
a["R8666857"]={!id};
a["R8666835"]={!R8666824.id};
a["estimated_time"]=parseInt(2);
var newId = rbv_api.createRecord("pm_task", a);
}

The problem is that I have the trigger on object 1 creating 20 records, and the trigger on object 2 creating 40 records from the object 1's 20 records. For some of the object 2 records, there are more than one record created for one object 1 record.

The problem is that some of the object 2 records are not created and it is totally random. The start of this process is a checkbox field. If I check all the checkboxes, to create all records for object 1, all object 1 records are created, but not all object 2 records are created.  If I select only a few of the object 1 checkboxes creating 5-10 obecjt 1 records, all of the expected object 2 records are created.

There is either something going on with a timeout, or I also read that there is a limit on the number of secondary triggers that can run off a primary trigger. There are only 2 triggers involved here.

When I use the trigger debug I get the the "too many triggers" error.

Thanks for any insight.

All Replies

Posted by pvorobie on 12-Oct-2014 12:22

Please use Triggers Debugger first. You may invoke other triggers while creating records through API.

Posted by dubosegriffin on 13-Oct-2014 08:11

Thank you but I am confused. I did you Trigger Debug which is how I determined what the error is.

Posted by Orchid Corpin on 13-Oct-2014 16:26

You can use Data map > Conversion Map

Trigger 1: Create a trigger with type "Create New Record" and use the created Conversion Map (if you are creating multiple records do not specify a timing to this, put that in trigger 2). Specify name on Integration name e.g. "trigger1".

Trigger 2: Create a trigger with type "Object Script" and you can loop inside this trigger. e.g. below code.

for(i=0; i < 10; i++) {
    rbv_api.runTrigger("currentObject", {!id}, "trigger1"); //This will run trigger 1
}

Do this on Object 2 too. Let me know if you still have trigger error.

Regards,

Orchid

Posted by dubosegriffin on 16-Oct-2014 14:44

This results in an error as well.

Object definition currentObject not found (line #4)

Posted by dubosegriffin on 16-Oct-2014 14:59

I was able to get pas that error but it did not work. It also will not get the end result I am looking for.

Posted by Orchid Corpin on 16-Oct-2014 15:40

"currentObject" is just my test name this may be different from yours, changed that to your current object name. 

Trigger Create New Record may execute faster than the createRecord API since this one you can choose to "Run dependent triggers after this one is completed"

Regards,

Orchid

Posted by Orchid Corpin on 30-Oct-2014 17:36

Hi,

Are there still any issues? or do you still have questions related to this?

Thanks,
Orchid

This thread is closed