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
kailash chandrakailash chandra 

document.sObjectType not working in apex class

document.sObjectType throwing an error in apex class 
Variable does not exist: sObjectType 
While it is working fine in anonymous window.
Please help me
Best Answer chosen by kailash chandra
Raj VakatiRaj Vakati
The following code is wokring for me 
 
// Verify that the generic sObject is an Documenet sObject
System.debug(Document.sObjectType);
Complete code tried
// Create a new account as the generic type sObject
sObject s = new Account();

// Verify that the generic sObject is an Documenet sObject
System.debug(Document.sObjectType);

// Get the sObject describe result for the Account object
Schema.DescribeSObjectResult dsr = Document.sObjectType.getDescribe();

// Get the field describe result for the Name field on the Account object
Schema.DescribeFieldResult dfr = Schema.sObjectType.Document.fields.Name;

// Verify that the field token is the token for the Name field on an Account object
System.assert(dfr.getSObjectField() == Document.Name);

// Get the field describe result from the token
dfr = dfr.getSObjectField().getDescribe();