Find your content:

Search form

You are here

Apex Syntax for "Empty" sObject


I'm looking for the logical syntax to determine if a sobject is empty.


MyObject obj = new MyObject();
system.debug(obj == null);

The debug returns "False" -- I want the syntax so it returns True when there's no values within the sobject.

Attribution to: Salesforce Wizard

Possible Suggestion/Solution #1

The '==' operator will return true if the left hand and right hand sobjects have the same value in every field. Thus you will need to instantiate an empty version of the object and compare your candidate to that. E.g. assuming candObj is the instance of the sobject you want to check:

MyObject__c emptyObj=new MyObject__c();

Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content