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
Vijay RautVijay Raut 

Login in Apex Trigger

Hi All,

Is it possible to login with another user in Apex Trigger.

My Use Case:
I want to deleting Account in UPDATE trigger based on some conditions. But when account get deleted, it will be available in SFDC Recycle bin of that User. I want to hide that record from recycle bin of that user.

So i am thinking of, before deleting, i will login with some dummy user and perform the delete operation. So that deleted record will be available to the dummy user's recycle bin.

Or is there any function available to clear SFDC recycle bin from Apex?

Any help on this would be appreciated.

Thanks
V.R.
Ron HessRon Hess
No, you cannot login as another user, you may be able to clear out some of the critical fields before deleting it, this shoudl prevent it from being undeleted.

you can also add a "before undelete" trigger and prevent an undelete from occuring on that record.