26
votes
Accepted
What governor limits impact Apex Describe methods?
As mentioned, describe limits have been removed entirely. Just for completeness, there are a few remaining limits that are affected by these describe calls, but consumption is negligible. These limits ...
20
votes
Accepted
Get Label For SObject API Name
You can get the label using the DescribeSObjectResult:
DescribeSObjectResult describe = SObjectType.MyApiName__c;
system.debug(describe.getLabel());
Another common syntax is:
DescribeSObjectResult ...
18
votes
Accepted
How can I get the API Name of a related EntityDefinition?
Both the EntityDefinition and FieldDefinition objects have a field called QualifiedApiName that does what I am looking for:
MyMetadata__mdt mapping = [
SELECT SObjectType__r.QualifiedApiName
...
17
votes
Accepted
Get SObjectType from 'ObjectName' without using getGlobalDescribe()?
Generically speaking, you can do this:
public static Id getRecordTypeIdForObject(String objName, String recTypeName) {
return ((SObject)Type.forName('Schema', objName)
.newInstance()
...
16
votes
Accepted
Performance Impact of DescribeSObjects vs. Individual Describe Calls?
Getting the individual describes is significantly faster. Depending on your situation, it is anywhere from 14 to 850 times as fast!
Describing Many Objects Once
The first continuum I profiled is the ...
14
votes
Accepted
Account.sObjectType.getDescribe() vs Schema.sObjectType.Account
There is no difference except the latter becomes less verbose when you drop the optional Schema. portion. Every time you type:
SObjectType.Account
instead of:
Account.sObjectType.getDescribe()
you ...
13
votes
Accepted
What is the difference between creatable vs. updatable on Schema.DescribeFieldResult
Many fields cannot be changed once populated, such as Audit Fields. Run this script:
for (SObjectField field : SObjectType.Account.fields.getMap().values())
{
DescribeFieldResult describe = field....
8
votes
Accepted
Dynamically retrieving page layout fields
You can synchronously pull details of a page layout in Apex using the Apex Metadata API. Here's a quick example of walking through the layout metadata, freely adapted from Trailhead:
List<Metadata....
6
votes
What governor limits impact Apex Describe methods?
There is no limit for Describe Call in Salesforce.
As per the below document, There were few limits before Summer'14 release and it was remove post Summer'14 release.
For more information:-
https:/...
6
votes
Get SObjectType from 'ObjectName' without using getGlobalDescribe()?
Depending on how you want to use it, the alternative is to sfdcfox's approach is to cache the global describe in a static variable with lazy instantiation e.g.
global class MyUtils {
private ...
6
votes
Accepted
sObjectField Class Methods getLabel()
As you mentioned, you need to call getDescribe(), which returns a DescribeFieldResult.
SObjectField field = Opportunity.AccountId;
DescribeFieldResult describe = field.getDescribe();
String label = ...
6
votes
how to check FLS of sObject dynamically
You could do something like:
((sObject)Type.forName('Account').newInstance()).getSObjectType().getDescribe().isAccessible();
Or you could do a global describe and get the values from the returned ...
4
votes
How do I find the field type of parent/grandparent fields etc?
Your approach is not tenable. There are many scenarios where the lookup name may not match the object type. Your logic for custom lookup fields only even works for standard objects.
You should take a ...
4
votes
FieldPermissions.Field contains strings longer than described maximum
How can Field contain a string longer than the length advertised by the API?
In this case, some of the fields being permissioned may have a length longer than 40. For example, there is a standard ...
4
votes
Accepted
Check if a object is undeleteable
The documentation on DescribeSObjectResult shows a method called isUndeletable():
for (DescribeSObjectResult result : results)
system.debug(result.isUndeletable());
Or you can simply do:
...
3
votes
Salesforce Metadata API - Easy Way To Get Entity Relationships / Joins?
If you just want a simple mapping of which objects are related to which others, you could roll your own naive implementation fairly simply. You could even hook it up to a REST service. Just for fun...
...
3
votes
Accepted
Constructor not defined: [System.SelectOption].<Constructor>(String)
Your parentheses are not quite right. You have one extra after your fieldPath.
options.add(new SelectOption(
String.valueOf(fieldSetMemberObj.getFieldPath()),
String.valueOf(fieldSetMemberObj....
3
votes
Accepted
is it possible only get writable fields from schema.sobjectfield
You cannot get only editable fields using Schema.getGlobalDescribe(). You need additional check.
Map<String, Schema.SObjectField> fields = Schema.getGlobalDescribe().get('Account').getDescribe()...
3
votes
Does SObjectType Access Guarantee Id Access?
All records that you can view in the UI should have an Id, because that's how they're displayed and referenced in the database. There are actually a small handful of objects that either do not have an ...
3
votes
sObjectField Class Methods getLabel()
You can get a field's label using the following one-liner:
String label = Account.Name.getDescribe().getLabel();
System.debug(label); //prints 'Account Name'
3
votes
Accepted
how to check that custom (or standard) field represents Id
You use instanceOf to determine if a value is an Id or not:
Set<Id> result = new Set<Id>();
for(SObject item : source) {
Object fieldValue = item.get(idFieldName);
if(fieldValue ...
2
votes
Accepted
DescribeSObject for Wrapper class
The mechanism you are looking for is called reflection in e.g. Java but such a mechanism has not been made available in Apex. It may eventually be - see this 8 year old idea Apex Reflection.
You don'...
2
votes
DescribeSObject for Wrapper class
No, it is not possible to dynamically describe custom object types (Apex Class). This functionality is only available for custom SObject types. If you want to use it dynamically, you will likely need ...
1
vote
Accepted
Impact of permissions on dynamic apex?
There should be no impact of user permissions or sharing settings on the behavior of dynamic apex (except when executing anonymously Understanding Describe Information Permissions).
There seems to ...
1
vote
How do I find the field type of parent/grandparent fields etc?
Without calling out to the Metadata API, there isn't a great way to determine this generically. One possibility is to run the query against one record and use that record to try to determine types.
...
1
vote
Accepted
Get Attributes from an Apex Object Dynamically
I think this question is a duplicate, but I can't find any previous such questions at the moment, so here we go.
Apex has very limited reflection capabilities. What you want isn't possible ...
1
vote
Performance Impact of DescribeSObjects vs. Individual Describe Calls?
I re-ran the this scenario and looks like Schema.describeSObjects seems to have better performance now when compared to SObjectType.getDescribe for individual objects, I'm assuming salesforce must ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
describes × 26apex × 16
describesobject × 7
dynamic-apex × 7
describefieldresult × 4
fls × 3
visualforce × 2
permissions × 2
sobject × 2
list-view × 2
label × 2
sobjectfield × 2
lightning-aura-components × 1
lightning × 1
soql × 1
rest-api × 1
custom-object × 1
soap-api × 1
metadata-api × 1
governorlimits × 1
metadata × 1
salesforce-id × 1
relationships × 1
wrapper-class × 1
bestpractice × 1