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
Harish NallalaHarish Nallala 

validation rule Or Trigger,when product with picklist field revenue type 'NE 'and 'NR' with Opportunity recordtype of TSP?

I want to add One product with One revenue type 'NE' in one opportunity,when a product added with revenue type NE to the opportunity,when NE exists,i would like tell my user create a new opportunity for product with 'NR' ,but do not they supposed top add both products with NE and NR in a single Opportunity.how could we make it ?

Any ideas? Thank you !!!
Raj VakatiRaj Vakati
Hi Harish ,
You need to write a simple before insert and before update trigger .

Thanks ,
Raj
Harish NallalaHarish Nallala
Hi Raj,Thanks for the reply, I struck here,I m new to this Apex kind,any  Idea How would be it structured?
Trigger TriggerNRNE on OpportunityLineItem (before insert,before update) {
    
    List<OpportunityLineItem> OplList = new List<OpportunityLineItem>();
    set<Id> setOfOpportunityId = new  set<Id>();

    map<Id,Integer> tempMap = new map<Id,Integer>();

    OplList = [SELECT Id,revenue_type__c,OpportunityId FROM OpportunityLineItem where OpportunityId In :setOfOpportunityId];
    for(opportunity lineItems:trigger.new){
        If(revenue_type__c = 'NIR' || revenue_type__c = 'NIE'){
          ====  
            ====
            
        }
    }

Thanks,
Harish
Raj VakatiRaj Vakati
Try this. i haven't
trigger OppLine on OpportunityLineItem (before insert ,before update) {
    List<OpportunityLineItem> OplList = new List<OpportunityLineItem>();
    Map<Id,Id> ids = new Map<Id, id>();
    for(OpportunityLineItem op : Trigger.new){
        If(op.Name=='NE'){
           // ids.put(op.OpportunityId); 
            If(ids.containsKey(op.OpportunityId)){
             op.addError('Some think wrong');   
            }else{
               // op.OpportunityId
              ids.put(op.Id , op.OpportunityId);
            }
        }    
    }
   
    
}

tested 
Harish NallalaHarish Nallala
well, its not working,I can still add two Products with different revenue_type__c picklist fields as NR and NE in single opportunity.