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
hamshuhamshu 

second largest value of child object(roll up summary) using trigger

hi all,

 

i am trying to find the second largest value of my child record using trigger but i am getting error ...any help

 

this is my code.

 i am geting following error ...Compile Error: unexpected token: '(' at line 20 column 100

trigger secoundlargest on object2__c (after insert,after update,after undelete)
{
    Map<Id,object1__c> ohh = new Map<Id,object1__c>();
    set<id> ids=new set<id>();
    try
    {
        if(trigger.isinsert||trigger.isupdate||trigger.isundelete)
        {
            for(object2__c oid:trigger.new)
            {
                ids.add(oid.Object1__c);
            }
            Ids.remove(null);
            for(id idss:ids)
            {
                ohh.put(idss,new object1__c(id=idss,grandtotal__c=0));
            }
       
          
             for(object2__c sd:[select name,(SELECT MAX(total__c) FROM object2__c  WHERE total__c < (SELECT       MAX(total__c) FROM object2__c)) from  object2__c WHERE object1__c IN: ids])
      {
            }
            
        }
    }
    catch(Exception e)
    {
         System.debug('### Exception: ' + e.getMessage());
    
    }

}

 

i am missing something ...

 

regard,

jaba

souvik9086souvik9086

Hi

 

You have to use Object2__r in the nested child query and also check the brackets are opened and closed properly.

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks