You need to sign in to do that
Don't have an account?

How can auto delete record after 3 minutes?
I have a Custom object
I want after insert record 3 minutes, if Status=0 , This record will auto delete.
How can auto delete record after 3 minutes?
I want after insert record 3 minutes, if Status=0 , This record will auto delete.
How can auto delete record after 3 minutes?
I trust you are doing very well.
You can achieve your requirement using Process Builder and Invocable Apex Class. As you can't schedule a process builder in minutes, there is a workaround to 'Set Time for Actions to Execute' in minutes.
First, you have to create a formula field on sObject (in my case: Account).
Object : Account
Custom Formula Field (Date/Time) : Add3__c (Formula: CreatedDate+63/1440)
* From this formula you will get time 60mins + 3mins after the record created date. We will use this time in a process builder, to execute a process builder before 1 hour of this time.*
Now, create flow in process builder:
Object : Account
Start the process : only when a record is created
Criteria Name : No Criteria
Criteria for Executing Actions : No criteria—just execute the actions!
Schedule Actions :
Set Time for Actions toExecute : 1 Hours Before Add3__c *(Suppose, record created time is 6:30 pm, so according to formula Add3__c will be 7:33 pm. So, process builder will execute on 6:33 pm i.e; 1 hour before 7:33 pm)*
Add Action : Call Apex
Action Name : Delete Account
Apex Class : TimeDeleteInvocable
Set Apex Variables :
Field : accIds
Type : Field Reference
Value : [Account].Id
Process Builder Screenshot :
1.
2.
3.
4.
Apex Class:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas