Right now my trigger updates field(Sales order) on parent object (Opp) with the value from child object (OM) field Sales order), right now if there are no child record then if we try to enter the value manually then it ignores the value so i need to make an exception to it to ignore it when there are no related OM records, how to add exception?
trigger UpdateSalesOrder on Opportunity (before update) {
list<id> opptyIdList = new list<id>();
for(Opportunity o: trigger.new){
opptyIdList.add(o.Id);
}
list<Order_Management__c> omlist = [Select o.Sales_Order__c, o.Opportunity__c, o.Id From Order_Management__c o where o.Opportunity__c in : opptyIdList] ;
map<Id,String>omMap = new map<id,String>();
for(Order_Management__c o: omlist){
omMap.put(o.Opportunity__c,o.Sales_Order__c);
}
for(Opportunity o: trigger.new)
{
if(o.StageName == 'Closed/Won')
{
o.SalesOrder__c = omMap.get(o.Id);
}
}
}