2

Why Apex Exceptions Email Settings are not copied to Sandbox upon sandbox refresh?

We need to manually setup Apex Exceptions Email Settings every time after sandbox refresh. Is there any way to make this automatic, probably by using SandboxPostCopy interface or by other means?

0

There is a standard object ApexEmailNotification which stores information about Apex Exceptions Email Settings

It is possible to retrieve these data using SOQL or Tooling API SOQL

SELECT CreatedById,CreatedDate,Email,Id,IsDeleted,LastModifiedById,LastModifiedDate,SystemModstamp,UserId FROM ApexEmailNotification

enter image description here

Despite this object is defined as EverCreateable, it is not possible to use Apex to create this records, if you try to

insert new ApexEmailNotification(UserId='0051t000002So5jAAC');

you will receive an error

DML operation Insert not allowed on ApexEmailNotification

enter image description here

Even though DML operation Insert is forbidden on this object, there is still an option to use Tooling API POST method to create this records by sending JSON body to /services/data/v45.0/tooling/sobjects/ApexEmailNotification endpoint

enter image description here

or even using usual endpoint

/services/data/v45.0/sobjects/ApexEmailNotification

enter image description here

So basically it is possible to write a script in SandboxPostCopy which would query production data and use self callout to insert them in Sandbox after refresh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.