You need to sign in to do that
Don't have an account?

Adding a validation to an existing trigger
I have an existing trigger which is running on the Opportunity object. I need to add a validation rule which
1. Updates the Approval_Status__c field on the Opportunity to a null value if a related Product is modified or a new Product is added to the Opportunity.
2. Prevent a user from moving the stage backwards.
1. Updates the Approval_Status__c field on the Opportunity to a null value if a related Product is modified or a new Product is added to the Opportunity.
2. Prevent a user from moving the stage backwards.
//Trigger
trigger OpportunityLineItemtrigger on OpportunityLineItem (after insert, After update) {
if(Trigger.IsInsert || Trigger.IsUpdate)
{
OpportunityLineItemtriggerHandler.LogicAfterInsertORupdate(Trigger.New);
}
}
//TRigger Handler Class
public class OpportunityLineItemtriggerHandler{
public static void LogicAfterInsertORupdate(list<OpportunityLineItem> LstOfOLI){
List<Opportunity> LstOfopp = new List<Opportunity>();
for(OpportunityLineItem oli :LstOfOLI )
{
Opportunity o = new Opportunity();
o.Approval_Status__c = '';
o.id = oli.oli
LstOfopp.add(o);
}
if(LstOfopp.size() >0)
{
update LstOfopp;
}
}
}
.
2) You can may create a validation rule look at ischanges or isNew functions , that might help you.
Kindly mark this answer, if it helps you.
Thanks,
Shamsi