function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
abdulqabdulq 

Trigger behavior changes after its deployed.....any possible reasons ?

Hi, I'm writing a trigger on ECS__eCommSource_Order_Line__c and if the user increases 'ECS__Quantity'  filed value then the trigger is suppose to add that number of Asset Records in asset object. The trigger is working fine in sandbox but when Iits deployed in Live org its actually creating twice the number of records to Quantity difference value. For example if the old quantity value is 2 and the updated value is 3 then it should create one asset record i.e difference between the old and new value but it my case its creating two records - I can't seem to find how. Below is my trigger code.

 
trigger AssetCreation on ECS__eCommSource_Order_Line__c (before update) 
 
list<asset> records = new list<asset>();
 
//Checking if the user has increased the quantity and adding asset record.
for(integer i = 0; i < Trigger.new.size(); i++)
{
ECS__eCommSource_Order_Line__c new_li = trigger.new[i];
ECS__eCommSource_Order_Line__c old_li = trigger.old[i];

if (new_li.ECS__Quantity__c > old_li.ECS__Quantity__c)
{
integer diff = (new_li.ECS__Quantity__c - old_li.ECS__Quantity__c).intValue();

for (integer j = 0; j < diff; j++)
{
records.add(new asset(AccountID = new_li.ECS__Account__c, Contact__c = new_li.ECS__Customer__c, B2C_Product__c = new_li.ECS__Product__c, Order__c = new_li.ECS__Order__c, Order_Line__c = new_li.id, Name = new_li.ECS__Title__c));
}

insert records;
}
}
}

 

bujjibujji
I think if your doing before actions in a trigger, you no need write the insert or update statements.

Thanks,
Bujji
abdulqabdulq
The trigger is running on a different object and i'm inserting records into
a different object.
What you said 'bujji' is when you modify the values of the records inside
the trigger and that may not require an update/insert statement.