• Mandapaka Raghu 9
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi 

i have a scenario like one account record does not contain more than three opportunity records, and i wrote a following trigger, but it is  not working for inserting the records one by one , but this trigger is working for inserting the bulk records through list.

trigger Opportunity_Validation_Trigger2 on Opportunity (before insert) {
    list<Opportunity> opportunities=trigger.new;
    
    map<id,list<Opportunity>> AccOppMap=new map<id,list<Opportunity>>();
    for(Opportunity opps:opportunities){
        if(opps.AccountId!=null){
            if(AccOppMap.containsKey(opps.AccountId)){
                list<Opportunity> oppslist= AccOppMap.get(opps.AccountId);
                oppslist.add(opps);
            }
            else
            {
                list<Opportunity> oppslist=new list<Opportunity>();
                oppslist.add(opps);
                AccOppMap.put(opps.AccountId, oppslist);
            }
        }
    }
    
    for(opportunity op:trigger.new){
        if(op.AccountId!=null){
            integer count=AccOppMap.get(op.AccountId).size();
            if(count>=3){
                op.addError('an account should not contain more than 3 opportunities');
            }
        }
        
    }
}


can any one please help me, the scenerio is it should work for inserting the records one after one and through list using execute anonomous window.
Hi guys,
 I have a doubt on ant deployment tool, iam new to this...
So what my doubt is... I have a two orgs x and y ,, I was retrieving Apex classes from x org and deploying to y org and next I have done some modifications on  Apex class  in x org and retrieve again and deployed to y org but I was getting an error because the Apex classes with same name are already existed in y org as we deployed at first time ,, so can any one tell me is it possible to override those classes ,,if it is please explain
thanks.
Hi 

i have a scenario like one account record does not contain more than three opportunity records, and i wrote a following trigger, but it is  not working for inserting the records one by one , but this trigger is working for inserting the bulk records through list.

trigger Opportunity_Validation_Trigger2 on Opportunity (before insert) {
    list<Opportunity> opportunities=trigger.new;
    
    map<id,list<Opportunity>> AccOppMap=new map<id,list<Opportunity>>();
    for(Opportunity opps:opportunities){
        if(opps.AccountId!=null){
            if(AccOppMap.containsKey(opps.AccountId)){
                list<Opportunity> oppslist= AccOppMap.get(opps.AccountId);
                oppslist.add(opps);
            }
            else
            {
                list<Opportunity> oppslist=new list<Opportunity>();
                oppslist.add(opps);
                AccOppMap.put(opps.AccountId, oppslist);
            }
        }
    }
    
    for(opportunity op:trigger.new){
        if(op.AccountId!=null){
            integer count=AccOppMap.get(op.AccountId).size();
            if(count>=3){
                op.addError('an account should not contain more than 3 opportunities');
            }
        }
        
    }
}


can any one please help me, the scenerio is it should work for inserting the records one after one and through list using execute anonomous window.