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

Compare Opportunity Product with Order Product
when a Product is added to Opportunity, Check for previous Orders related to Opportunity account and
and if no orders exists then update a picklist field on Opportunity as (New).
if any Orders exists then check for the latest orders price and compare it with our new product price that we are adding.
if it is greater than new product's price then update picklist on opportunity as Loss
if less then update as WOn.
I have Written a trigger to achieve this and was stuck at this point. Needed help to proceed further..!
trigger triggeronopportunity on Opportunity (before insert,before update) {
List<opportunity> oppo = new List<opportunity>();
List<Account> acc = new List<Account>();
List<OpportunityLineItem> oppl = new List<OpportunityLineItem>();
List<PricebookEntry> pb = new List<PricebookEntry>();
Set<ID> OppIds = new Set<ID>();
Set<ID> accIds = new Set<ID>();
for(Opportunity opp : trigger.new){
if(oppl.size() == 0){
opp.Revenue_Type__c = 'New ';
}
for(Account a : [Select Id, Order_Product__c FROM Account Where Id in :OppIds ]){
========== Struck Here ==============
}
}
}
The above trigger has the solution. All you need to do is just replace the name of fields with correct field names which are marked with '*'.