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
SarikaPSarikaP 

Best practice to code: To Add Terms & Conditions based on Quote Amount

We have a custom object "Terms & Conditions - Quote'.
Based on the "Amount" of the quote, I have to delete certain 'T&C' from the custom object and add other 'T&C' respectively.
The T&C's are linked to the product, whenever a lineitem is added, all product related T&C's are added. But now we want to add further customization to check the amount too. Based on final amount of quote, T&C's can change.
 
SabrentSabrent
I am assuming you already have a trigger or handler class to do the logic as you have described. 
If so, you may only have to add a conditional statement and collect a list of T&C to delete and another list to insert. 

something like this, 
1. list<Terms _Conditions _Quote__c> TandCToDelete  = new list <Terms _Conditions _Quote__c>();
2. list<Terms _Conditions _Quote__c> TandCToInsert  = new list <Terms _Conditions _Quote__c>();
3. In SOQL query the Amount field 
4. Loop through all records in trigger.new  for (Terms _Conditions _Quote__c tc : trigger.new){
5. if (Amount > 1000){
        TandCToDelete.add(tc.Id);
} else{
        TandCToInsert  .add(tc.id)

insert TandCToInsert ;
delete TandCToDelete . 

}

 
SarikaPSarikaP
Thanks Rov. My main query is the trigger action all the above logic goes in after action but which operation?
SarikaPSarikaP
Also is it better to use process builder?
SabrentSabrent
What is the relationship between your Custom Object, Product and Quote ? 
from your description it seems like you would use a After Update trigger. 

There are pros and cons of using Process Builder over Trigger (ref: https://blogs.perficient.com/2017/06/13/when-to-use-process-builder-or-apex-triggers-to-automate/)




 
SarikaPSarikaP
I have added my code in this post:https://developer.salesforce.com/forums/ForumsMain?id=9062I000000IFdRQAW