SOQL FIELDS() Function

FIELDS(ALL) – Select all the fields of an object.
FIELDS(CUSTOM) – Select all the custom fields of an object.
FIELDS(STANDARD) – Select all the standard fields of an object.

In each case, FIELDS() respects field-level security so it only shows the fields that you have permission to access.

FIELDS() is limited to returning 200 records.

FIELDS(ALL) and FIELDS(CUSTOM) are not supported in Apex due to being unbounded, having sets of fields that the API can’t determine in advance.

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_fields.htm?_ga=2.106773379.1216528802.1671603324-1158522964.1660054937

Enable Field- and Object-Level Permissions Checking Using WITH SECURITY_ENFORCED in SOQL Queries

List<Contact> contactsWithSecrets = [
	SELECT 
		Name, Social_Security_Number__c
	FROM 
		Contact 
	WITH SECURITY_ENFORCED
];

If fields or objects referenced in the SELECT clause using WITH SECURITY_ENFORCED are inaccessible to the user, the query throws an exception indicating insufficient permissions and no data is returned.

There is a new restriction while querying Polymorphic lookup fields using WITH SECURITY_ENFORCED. Polymorphic lookup fields are relationship fields that can point to more than one entity.

1. Traversing a polymorphic field’s relationship is not supported in queries using WITH SECURITY_ENFORCED.
2. Using TYPEOF expressions with an ELSE clause is not supported in queries using WITH SECURITY_ENFORCED.
3. The Owner, CreatedBy, and LastModifiedBy polymorphic lookup fields are exempt from this restriction, and do allow polymorphic relationship traversal.

It is recommended, using WITH SECURITY_ENFORCED in Apex classes or triggers with an API version 45.0 or later.