• Mallareddy
  • NEWBIE
  • 0 Points
  • Member since 2017
  • Symplocus SoftSolutions

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
public class TypeOfBusinessValidation{
    public static void validate(List<Opportunity> newList){
         List<Opportunity> oppList = new List<Opportunity>();
        Id MSORecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Managed Sales Opportunity').getRecordTypeId();
        
        Map<id,Opportunity> oppMap = new Map<id,Opportunity>();
        for(Opportunity opp : newList){
            oppMap.put(opp.id,opp);
        }
        
        List<OpportunityLineItem> oppLt=[Select id,Product2.Division__c,OpportunityId,Opportunity.Competitive_Status__c,Opportunity.Type_of_business1__c from OpportunityLineItem where Opportunity.RecordTypeId=:MSORecordTypeId and OpportunityId in :newList];
        for(OpportunityLineItem oli: oppLt){
                if(oppMap.get(oli.OpportunityId).Competitive_Status__c== 'Not Competitive' && oli.Product2.Division__c=='END USER COMPUTING'){
                    oppMap.get(oli.OpportunityId).addError('Type of Business should not be blank when Competitive status is NOT COMPETITIVE and Product Division is END USER COMPUTING');
                }
        }    
     }
}