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
ravali k 3ravali k 3 

how to create a trigger for having only one opportunity for one account it should be allow 2nd opportunity.

shailesh_rawteshailesh_rawte
Hi ravali,


You have create trigger on opportunity object.
for(opportunity oy:trigger.new){
       
       if(oy.accountid==''){
          List<Opportunity>  acc=[select id from Opportunity where accountid=:oy.accountid];
          if(acc.isEmpty())
             oy.addError('Only i opportunity for one account');
       }
       
   }