You need to sign in to do that
Don't have an account?
Shawn Reichner 29
Trigger not updating record
Hello Awesome Developers.....
I have the following trigger that should be updating an Apttus Quote Record based on Line Items that are added.
Ultimately what I am trying to achieve is when a new Apttus config file is created (gets created when a cart is finalized) and is marked finalized for its status, look for the line Items associated with that Apttus config record, and if any of those items has a particualr product code through the product selected to be used and its quantity is greater that 3 then add those records to a list and then for that list update the master Quote record to have a checkbox checked true which will then require an approval to be done.
Looks like through my debug statements I can see that the records and lists are being treated fine up until line 45 as the master quote record does not get updated.
Any help on this would be greatly appreciated, and if you need any mor einformation, please ask,
Thanks again,
Shawn
Trigger Code:
I have the following trigger that should be updating an Apttus Quote Record based on Line Items that are added.
Ultimately what I am trying to achieve is when a new Apttus config file is created (gets created when a cart is finalized) and is marked finalized for its status, look for the line Items associated with that Apttus config record, and if any of those items has a particualr product code through the product selected to be used and its quantity is greater that 3 then add those records to a list and then for that list update the master Quote record to have a checkbox checked true which will then require an approval to be done.
Looks like through my debug statements I can see that the records and lists are being treated fine up until line 45 as the master quote record does not get updated.
Any help on this would be greatly appreciated, and if you need any mor einformation, please ask,
Thanks again,
Shawn
Trigger Code:
trigger ColocationCrossConnectApproval on Apttus_Config2__ProductConfiguration__c (before insert, before update) { List<Apttus_Config2__LineItem__c> colocationList = new List<Apttus_Config2__LineItem__c>(); system.debug('colocationList Size Initial -'+colocationList.size()); List<Apttus_Config2__LineItem__c> crossConnectList = new List<Apttus_Config2__LineItem__c>(); system.debug('crossConnectList Size Initial -'+crossConnectList.size()); List<Apttus_Config2__ProductConfiguration__c> configRecords = new List<Apttus_Config2__ProductConfiguration__c>(); system.debug('configRecords Size Initial -'+configRecords.size()); For(Apttus_Config2__ProductConfiguration__c config : Trigger.new){ If(config.Apttus_Config2__Status__c == 'Finalized'){ configRecords.add(config); system.debug('configRecords Size After -'+configRecords.size()); } // End of Status = Finalized If Statement } // End of Trigger.New For Loop If(configRecords.size()>0){ For(Apttus_Config2__ProductConfiguration__c configToWork : configRecords){ List<Apttus_Config2__LineItem__c> colocationItems = [SELECT ID, Name, Apttus_Config2__OptionId__c,Apttus_Config2__OptionId__r.ProductCode, Apttus_Config2__ConfigurationId__c,Apttus_Config2__Quantity__c, Apttus_Config2__ConfigurationId__r.Apttus_QPConfig__Proposald__r.ColocationApprovalRequired__c, Apttus_Config2__ConfigurationId__r.Apttus_QPConfig__Proposald__r.CrossConnectApprovalRequired__c FROM Apttus_Config2__LineItem__c WHERE Apttus_Config2__ConfigurationId__c IN : configRecords]; system.debug('colocationItems Size -' + colocationItems.size()); For(Apttus_Config2__LineItem__c coLoItems : colocationItems){ If(coLoItems.Apttus_Config2__OptionId__r.ProductCode == 'SAN-001' && coLoItems.Apttus_Config2__Quantity__c > 3){ colocationList.add(coLoItems); system.debug('colocationList Size After -'+colocationList.size()); } // End Of Colocation If Statement To Add CoLocation Line Items to colocationList else If(coLoItems.Apttus_Config2__OptionId__r.ProductCode == 'SAN-002' && coLoItems.Apttus_Config2__Quantity__c > 3) { crossConnectList.add(coLoItems); system.debug('crossConnectList Size After -'+crossConnectList.size()); } // End of Else If Statement to add Cross Connect Lines to crossConnectList } // End of Line For Loop } // End of configToWork For Loop } // End Of Bulkify If Statement If(colocationList.size()>0){ For(Apttus_Config2__LineItem__c finalcoLoList : colocationList){ finalcoLoList.Apttus_Config2__ConfigurationId__r.Apttus_QPConfig__Proposald__r.ColocationApprovalRequired__c = True; Database.update(finalcoLoList); } // End of finalcoLoList For Loop } // End of colocationList size If Statement If(crossConnectList.size()>0){ For(Apttus_Config2__LineItem__c finalcrossList : crossConnectList){ finalcrossList.Apttus_Config2__ConfigurationId__r.Apttus_QPConfig__Proposald__r.CrossConnectApprovalRequired__c = True; Database.update(finalcrossList); } // End of finalcrossList For Loop } // End of crossconnectList size If Statement } // End Of Trigger
You are not able to update related records like this, Database.update(finalcoLoList); will try to update the Apttus_Config2__LineItem__c record, not the Apttus_QPConfig__Proposald__c record.
You will need to get a list of the Apttus_QPConfig__Proposald__c records to update the fields on those.
Unrelated but still an issue, on line 22 you are doing a select inside a loop which you should always try to avoid, if you ever have more that 100 records in the trigger you will start to hit limits, try your best to avaoid these.
From what I can see though, the select will always get the same list of records each time so this loop is not needed.
here's my attempt at your trigger if I understand what you're tying to update
All Answers
You are not able to update related records like this, Database.update(finalcoLoList); will try to update the Apttus_Config2__LineItem__c record, not the Apttus_QPConfig__Proposald__c record.
You will need to get a list of the Apttus_QPConfig__Proposald__c records to update the fields on those.
Unrelated but still an issue, on line 22 you are doing a select inside a loop which you should always try to avoid, if you ever have more that 100 records in the trigger you will start to hit limits, try your best to avaoid these.
From what I can see though, the select will always get the same list of records each time so this loop is not needed.
here's my attempt at your trigger if I understand what you're tying to update