What Are Setup and Non-Setup Objects in Salesforce
In this top salesforce blog, we will be discussing what are Setup and Non Setup Objects in Salesforce.
Setup and Non-Setup Objects in Salesforce
Non-Setup Objects are standard objects like accounts or any custom object. Setup Objects are used to interact with metadata for declarative development.
Objects in Salesforce are the major part I can say as it is the tabular database where the information and data are stored on which manipulation and computation happens. Salesforce provides standard objects which are already present in the org for everyone. Salesforce has plenty of objects which are more than enough to work with and it can be modified by adding fields or validation rules or other functionalities to use these objects in the respective environment. Still, there is no boundary of customization, and Salesforce is flexible enough to offer users to make their own objects in the org by their choice and of their requirements entirely. The Objects which are made by users for business purpose means the customization comes under Custom Object.
In one more aspect, Salesforce has differentiated the objects which are set up and non-setup objects. Moving forward, let's dig more into these types of objects. These objects differ on the basis of the interaction with them on the platform.
Some examples of setup objects are:-
- User
- Profile
- Record Type
- Holiday Etc.
And all other general objects in Salesforce are non-setup objects that are:-
- Account
- Contact
- Lead
- Case
- Opportunity Etc.
Mainly, setup objects are those which must be from the builder area in the platform or from the setup only. And with the non-setup objects, this is not in any way a criterion for them.
Don't forget to check out: Salesforce Managed Services vs Inhouse Team
DML Operation on Setup and Non-Setup Objects in Salesforce
Data Manipulation Language (DML) statements to add, change and delete oracle database table data. An important aspect is that, if we are running DML on a setup object then we can’t run a DML on the non-setup object in the same transaction. It will show an error message. The error message will show ‘Mixed_DML_operation’ which can be avoided by not attempting to run the DML on both setup and non-setup objects in the same transaction.
Example to avoid such errors:-
In test class:.
First, insert a user then do the DML further.
//Test method static testmethod void setupObjectUpdate_Test() { Profile profileIdforTest = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1]; User userObj = new User(LastName = 'testUser', FirstName='test', Alias = 'test', Email = '[email protected]', Username = '[email protected]', ProfileId = profileId.id, TimeZoneSidKey = 'GMT', LanguageLocaleKey = 'en_US', EmailEncodingKey = 'UTF-8', LocaleSidKey = 'en_US' ); insert userObj; test.startTest(); system.runAs(userObj){ //Do the dml transactions //dml statement; } }
Check out another amazing blog by Anjali here: Learn All About Batch Apex Chaining in Salesforce
In the above test method example, it is simply shown that by making a separate user and then running the test area by the newly created user by using system.runAs(), the error can be avoided. If there are only setup objects then the transactions can be done in the normal way only.
In the end, I would like to add that in the world of coding we can simply manage our time and focus on better development and results, by making the smart move and coding in a way that the errors can be avoided or if errors are coming then by finding a way to resolve them. Coders can make the code run and if they are stuck they themselves make the path and overcome the errors.
Know more about the setup and non-setup objects in Salesforce and gather knowledge from experts by consulting with the top Salesforce consultants. Forcetalks has gathered all information about the top salesforce consulting companies. Approaching these top companies will let you find all the information you need to understand for setup and non-setup objects in Salesforce. Connect with the top salesforce professionals and learn from their experiences.
Happy coding!
Responses