You need to sign in to do that
Don't have an account?
Avinash@salesforce
Trigger On Opportunity Product Which Shows an error message
Hi friends,
I am writing a trigger on opportunityLineItem. There is a custom picklist field (ExistingProduct__c) on opportunityLineItem.
Now my scenario is when a opportunityLineItem is added to opportunity with the picklist value as "ExistingProduct__c = YES".
When the user try to add another opportunityLineItem to same opportunity with same picklist value. It should through an error message.
There should be only one opportunity LineItem with ExistingProduct__c ==Yes for one Opportunity.
I tried this way but it's not working.
trigger OpportunityProduct on OpportunityLineItem (before insert) {
List<Opportunity> opps = [select id,StageName,Ownerid,accountid from opportunity where id in :opportunityIds];
List<OpportunityLineItem> opls = [Select Id, ExistingProduct__c from OpportunityLineItem where id in : opportunityIds];
for(OpportunityLineItem op : trigger.new){
if(op.ExistingProduct__c == 'Yes'){
//insert op;
opportunityLineItem oldopp = trigger.oldMap.get(op.Id);
if(op.ExistingProduct__c[0] != oldopp.ExistingProduct__c){
op.addError('*****************');
}
}
}
}
How to achieve this....?
Could anyone help.
I am writing a trigger on opportunityLineItem. There is a custom picklist field (ExistingProduct__c) on opportunityLineItem.
Now my scenario is when a opportunityLineItem is added to opportunity with the picklist value as "ExistingProduct__c = YES".
When the user try to add another opportunityLineItem to same opportunity with same picklist value. It should through an error message.
There should be only one opportunity LineItem with ExistingProduct__c ==Yes for one Opportunity.
I tried this way but it's not working.
trigger OpportunityProduct on OpportunityLineItem (before insert) {
List<Opportunity> opps = [select id,StageName,Ownerid,accountid from opportunity where id in :opportunityIds];
List<OpportunityLineItem> opls = [Select Id, ExistingProduct__c from OpportunityLineItem where id in : opportunityIds];
for(OpportunityLineItem op : trigger.new){
if(op.ExistingProduct__c == 'Yes'){
//insert op;
opportunityLineItem oldopp = trigger.oldMap.get(op.Id);
if(op.ExistingProduct__c[0] != oldopp.ExistingProduct__c){
op.addError('*****************');
}
}
}
}
How to achieve this....?
Could anyone help.
Use this trigger :
Regards,
Ajay