and thanks in advance for any suggestions, greatly appreciated!
we created a trigger that queries the accounts and creates custom invoice records for each stop on our service trucks. each route is designated with a color and a service week per month (week 1, week2, etc) so that when you pick a color and a week, any account that meets that criteria will have an invoice record created. we created workflows to push fields from the related account to each individual invoice record, but these workflows are causing trigger errors on our invoice creation trigger. any idea what to do, based on this error message?
Error: Invalid Data. Review all error messages below to correct your data. Apex trigger Logistic_trigger_run caused an unexpected exception, contact your administrator: Logistic_trigger_run: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it. Division undefined: []: Trigger.Logistic_trigger_run: line 177, column 1
Here is the trigger code for one combination of color (route) and week:
trigger Logistic_trigger_run on Run__c (after insert) {
List<Logistic__c> ordtoinsert = new list<Logistic__c>();
for(Run__c o: Trigger.new){
if(o.Color__c=='Orange'){
if(o.Week_Cycle__c =='Week 1' ){
List<Account> toinsert = [Select id, Name from Account where run__c ='Orange' AND (Wk1__c = TRUE) ]; // 3DRobotics
for(Account newOr: toinsert){
Logistic__c LogisticObj =new Logistic__c();
LogisticObj.Account1__c=newOr.Id;
LogisticObj.Date_Unloaded__c=date.today();
LogisticObj.run__c=o.id;
ordtoinsert.add(LogisticObj);
}
insert ordtoinsert;
system.debug('---->'+toinsert);