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
Ginny MahantGinny Mahant 

How do we understand which objects can be queried with SOQL and which can be queried with SOSL ???

Workbench

Here is a screenshot from workbecnch. List of object for SOQL and SOSL differs.  How do we understand in general the objects that allow SOQL and objects that allow SOSL. 
Can we follow the rule that all objects (std, custom and metadata ) with NAME, PHONE, EMAIL FIELDS in them allow SOSL ???

Please help I can't understand .
Best Answer chosen by Ginny Mahant
Raj VakatiRaj Vakati
Option 1 : Using Dynamic apex  

using isQueryable() and  isSearchable() method in DescribeSObjectResult  class
 
// sObject types to describe
String[] types = new String[]{'Account','Merchandise__c'};
// Make the describe call
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types);
System.debug('Got describe information for ' + results.size() + ' sObjects.');
// For each returned result, get some info
for(Schema.DescribeSobjectResult res : results) {
    System.debug('sObject Label: ' + res.getLabel());
 System.debug('sObject isQueryable(): ' + res.isQueryable());
   
 System.debug('sObject isSearchable(): ' + res.isSearchable());
   
   
   System.debug('Number of fields: ' + res.fields.getMap().size());
    System.debug(res.isCustom() ? 'This is a custom object.' : 'This is a standard object.');
    // Get child relationships
    Schema.ChildRelationship[] rels = res.getChildRelationships();
    if (rels.size() > 0) {
        System.debug(res.getName() + ' has ' + rels.size() + ' child relationships.');
    }
}



Option 2: - You can find the details in the soap api guide 

Go to any object in soap api guide and you can able to see the supported calls like below

create(), delete(), describeLayout(), describeSObjects(), getDeleted(), getUpdated(), merge(), query(), retrieve(), search(), undelete(), update(), upsert()
 

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_account.htm

All Answers

Raj VakatiRaj Vakati
Option 1 : Using Dynamic apex  

using isQueryable() and  isSearchable() method in DescribeSObjectResult  class
 
// sObject types to describe
String[] types = new String[]{'Account','Merchandise__c'};
// Make the describe call
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types);
System.debug('Got describe information for ' + results.size() + ' sObjects.');
// For each returned result, get some info
for(Schema.DescribeSobjectResult res : results) {
    System.debug('sObject Label: ' + res.getLabel());
 System.debug('sObject isQueryable(): ' + res.isQueryable());
   
 System.debug('sObject isSearchable(): ' + res.isSearchable());
   
   
   System.debug('Number of fields: ' + res.fields.getMap().size());
    System.debug(res.isCustom() ? 'This is a custom object.' : 'This is a standard object.');
    // Get child relationships
    Schema.ChildRelationship[] rels = res.getChildRelationships();
    if (rels.size() > 0) {
        System.debug(res.getName() + ' has ' + rels.size() + ' child relationships.');
    }
}



Option 2: - You can find the details in the soap api guide 

Go to any object in soap api guide and you can able to see the supported calls like below

create(), delete(), describeLayout(), describeSObjects(), getDeleted(), getUpdated(), merge(), query(), retrieve(), search(), undelete(), update(), upsert()
 

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_account.htm
This was selected as the best answer
Ginny MahantGinny Mahant
Got it. Thanks Rajamohan 👍
Raj VakatiRaj Vakati
Close this thread