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
sfdc_danesfdc_dane 

Storage Usage

Hi,

 

Just want ask if there's a way to query records like the record count on Storage Usage?

 

Also, is it possible to to apex batch like 100k records to update per day/week? Any idea how will I do that?

 

Thanks!!

Best Answer chosen by Admin (Salesforce Developers) 
AdrianCCAdrianCC

Okay, last answer :)

 

You're going to use a scheduler class to make sure the batch fires regularly. See here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm 

 

You can also start the batch manually from the developer console like this:

Id batchInstanceId = Database.executeBatch(new BatchClass(<list of params>), 200); //200 means how many records are processed at a time, you can chnge this to suit your needs

 This is the documentation for batches: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch.htm

 

Later Edit: To run the tests you can either use force.com ide or the browser interface, it's the same as for a normal class. 

Also you can monitor your jobs under Setup> Monitoring> Scheduled Jobs 

 

Adrian 

 

All Answers

AdrianCCAdrianCC

Hello dane!

 

There's no standard object for Storage Usage, not from what I've found. What do you need it for? Can you use a simple COUNT() and AggregateResults to replace it?

 

For the batch apex, if you're using Database.QueryLocator then the limit is set at 50 million records. I don;t see why 100k should pose a problem. Are you getting an error or something at the moment? http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm 

 

Thanks,

Adrian 

sfdc_danesfdc_dane

Hi Adrian,

 

Thanks for a quick reply. I'm still thinking how will I develop the code. Because I have a parent object(Candidate) which has child objects(Application).

 

What I need is to update a field in Candidate to put the ld of a certain Application related to that Candidate base on the condition given. So I'm planning

 

to get the count of the total records on the Storage Usage of the object and loop for the update? But I'm not sure that will work as I might encounter

 

Limit? Any idea how can i build this one? 

 

Thanks!

AdrianCCAdrianCC

Why aren't you using a trigger?

Whenever you insert/update an Application the trigger fires and checks the condition(I assume that the condition is at Application level, correct me if I'm wrong). You get the related Candidate and update whatever field you need to update. And the change would be synchronous(instant), not like the batch that waits for the VM to be free.

 

Are you doing bulk operations? Like imports thrugh Data Loader or smth? If you're updating a large number of records at a time then the trigger is not okay... 

 

Thx,

Adrian 

sfdc_danesfdc_dane

Yup were doing bulk, also they request an weekly/monthly update on the records so apex batch is recommended for that right?

AdrianCCAdrianCC

Yes, you are right, batch is the way. The trigger will only process a maximum of 50k records at a time. I didnt't check that, sorry.

 

Adrian 

sfdc_danesfdc_dane

Alright thanks, last question...

 

I see this as a guide doing apex batch:

 

http://developer.force.com/cookbook/recipe/using-batch-apex-to-reassign-account-owners

 

just want to know how can I run and test this? Any Idea?

 

Thank man!

AdrianCCAdrianCC

Okay, last answer :)

 

You're going to use a scheduler class to make sure the batch fires regularly. See here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm 

 

You can also start the batch manually from the developer console like this:

Id batchInstanceId = Database.executeBatch(new BatchClass(<list of params>), 200); //200 means how many records are processed at a time, you can chnge this to suit your needs

 This is the documentation for batches: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch.htm

 

Later Edit: To run the tests you can either use force.com ide or the browser interface, it's the same as for a normal class. 

Also you can monitor your jobs under Setup> Monitoring> Scheduled Jobs 

 

Adrian 

 

This was selected as the best answer
sfdc_danesfdc_dane

Great!!! Thanks Adrian! Your the man!!

AdrianCCAdrianCC

:) this was easy.

 

Be warned! This will generate a lot of errors, debug logs etc until you clean the code up and  check/catch for all exceptions. At 100k records I suppose it's normal to happen.

 

Good luck,

Adrian