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
ZurMilesZurMiles 

Delete files older the 3 minutes

Hello all,

 

 

There is a way to delete files older than 3 minutes? 

Thanks.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
harsha__charsha__c

Finally the preferred solution will be as followed.

 

Schedule the same batch 20 times in an hour as followed

 

System.schedule('Job9', '0 3 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job3', '0 6 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job4', '0 9 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job5', '0 12 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job6', '0 15 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job7', '0 18 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job8', '0 21 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));.....................20 times

 

By this your batch will run once in every 3 mins.

All Answers

harsha__charsha__c

files/records?

ZurMilesZurMiles

Attachments. 

harsha__charsha__c

You can run a batch for every 2 min and you can delete the Attachment records.

 

 

 

ZurMilesZurMiles
batch for every 2 min? I though that you can only run a batch, minimum, every hour.
This is one hour: - ', '0 0 0/1 * * ?' - right?
What would be the 2 minutes? Could you please let me know?
Thanks
harsha__charsha__c

This needs some work around as followed.

 

Schedule the same batch 30 times in an hour as followed

 

System.schedule('Job9', '0 2 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job3', '0 4 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job4', '0 6 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job5', '0 8 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job6', '0 10 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job7', '0 12 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job8', '0 14 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));.....................30 times

 

By this your batch will run once in every 2 mins.

Vinit_KumarVinit_Kumar

Harsha,

 

This is going to hit the governor limit of salesforce as the maximum no. of scheduled Jobs is limited.

harsha__charsha__c

Max limit per day is 2000, but in our case we are just calling it for 1440 times in a day.

 

Assuming no other batches are running.

Vinit_KumarVinit_Kumar

Harsha.

 

I am not talking about Max. No. of Batches in a day which is 2000.I am talking No. of scheduled Jobs which is 25 in an org because the Apex Jobs needs to be scheduled as well.

 

System.schedule('Job9', '0 2 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job3', '0 4 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job4', '0 6 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job5', '0 8 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job6', '0 10 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job7', '0 12 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job8', '0 14 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));.....................30 times

 

You can't schedule it this way,it would hit the limit of No. of scheduled Jobs.

harsha__charsha__c

Ohh, yes

 

Then we can make 20 batches, with each batch running for the interval of 3 min.

 

Right?

 

Vinit_KumarVinit_Kumar

Yes it could be done depending there are no more other scheduled classes in the org.I mean the total should not exceed 25.

harsha__charsha__c

Finally the preferred solution will be as followed.

 

Schedule the same batch 20 times in an hour as followed

 

System.schedule('Job9', '0 3 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job3', '0 6 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job4', '0 9 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job5', '0 12 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job6', '0 15 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job7', '0 18 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));
System.schedule('Job8', '0 21 * * * ?', new BatchApex('gggggg', '0019000000LRvuw'));.....................20 times

 

By this your batch will run once in every 3 mins.

This was selected as the best answer