+ Start a Discussion
aj4aj4 

Apex trigger or Apex class for mass update on Account field at end of every Month

Hi!
 
In our implementation we have member field on account object. Every month we want to update this field with some value derived from child record.
 
 
1)Should we code Trigger OR  Apex class to be call from S-control?
 
 2)If it is trigger  then how would you mass update all accounts?
3)Can we write Apex class and call it from s-control
4)Can you automate the process to run at the end of the month?
5) Please provide sample code for the solution for above.
 
Thanks
 
 
 
 
 
 


Message Edited by aj4 on 05-12-2008 04:56 PM
aj4aj4
Please response...
 
 
Ron HessRon Hess
1)Should we code Trigger OR  Apex class to be call from S-control?

A trigger is nice, but it  will work when child  is modified no monthly
apex called from scontrol is fine, from a button or link

 2)If it is trigger  then how would you mass update all accounts?
not a good idea, depending on how many accounts you may not be able to update all from a trigger.

3)Can we write Apex class and call it from s-control
Yes, examples in AJAX tools package on appexchange

4)Can you automate the process to run at the end of the month?
Not at the current time, no time based apex calls

5) Please provide sample code for the solution for above.
 See AJAX Tools package for srcs on how to call a webservice from scontrol
aj4aj4

Thanks for the reply.

 

We have approximately 60000 accounts and still growing.

How will you handle data to hold so many record into list or set and proccess each account record to find child and then update account.

It will hit the governence limit  because list cant handle for than 1000 record and dml  limitation of 20.

Do you have sample code for such situation or solution.

 

Thanks

 

 

 

 

 

 

 

aj4aj4
I have sample code ...
 
webservice static void updateAccounts(){
 account [] accts = [select id from Account ];
 
 
 for (account  a : accts ) {
 
      Pop__c [] pops = [Select Mem__c From Pop__c where Account__c =:a.id  ];  
        
          double tot = 0;
                        
           for(Pop__c  pop : pops){
            tot  =  tot+ pop.Mem__c;
                    
          }
          a.mbr = tot;
         system.debug('account name   '+ a.id+ 'tot  '+);
          
          update a;
           
   }
 
}
 
 
How to optimize above code to avoid governence Limit.  there are more than 60000 account record and each account have 1- 20 child record which need to process.
 
aj4aj4
Anyone..... Please  response.
Rob P12Rob P12
    I'm having a similar problem. Our Account object is 144K records. If I query on anything other then the name I get the query.exception error more than 100k records. In my case a Key is provided(from external source) on the Opportunity that represents a Var or Reseller. This is different than the Account Name on the Opportunities. I'm trying to query the Account using this Key, Then  write  this information in a section on the Opportunity. This would create an account to Var Reseller xref with the proper Id's. The query.exception tells me the Key field needs to be indexed or Filtered. I filter in the where clause where Key =:keyvalue.

If you find anything else on this please let me know.
Ron HessRon Hess
There is a new feature in Developer Preview at the current time called @future, this may allow you to process more records than you are able to otherwise.  Check out the latest documentation to see this described.