Welcome to the new Post of SalesforceGeek, Today we are going to learn about the difference between Setup and Non-Setup Objects.
Setup Object are the object which are dealing with the Metadata for declarative development. Some of the Examples of Setup Objects are User, Profile, RecordType, etc.
Check this out for more information: Setup Objects (Setup objects ).
Every other object like those which are native(Standard Objects) and Custom Objects fall into the category of Non-Setup Objects. Some of the Examples are Account, Contact, etc. Now you will think that setup object dealing with metadata so you can’t perform CRUD operation on Setup Object Records. You can but the fact is you can’t use Dml operation in the same Transaction Simultaneously with Non-setup Objects.
It means that in a piece of Apex Code you cannot use INSERT / UPDATE / DELETE commands on one set of Setup Objects and one set of Non-Setup Objects together. You’ll have to perform the DMLs on the Setup Objects in a separate transaction.
Now how to use them:-
- Put them in a different transaction and wrap the code(to process Setup objects) in a different Apex Class and its own @future annotated method. This would run the code in a different transaction.
- Spawning Batch Apex etc. all of which have an advantage of = “they run in a different transaction” unit.