Questions tagged [describesobject]

Salesforce allows you to describe sObjects either by using sObject or field tokens, or the describeSObjects Schema method.

Filter by
Sorted by
Tagged with
40 votes
5 answers
118k views

Apex: Dynamically get fields for an SObject - no hardcoding

It states in Salesforce Apex docs that I can get fields for a particular SObject (standard or custom) in the following way: Map<String, Schema.SObjectField> M = Schema.SObjectType.Custom__c....
  • 401
30 votes
1 answer
2k views

New Schema.describeSObjects not working as expected

There is a new method for Schema in Winter 14 called Schema.describeSObjects. The idea as I understand the docs is that you can pass in a list of sObject names as strings, and get back the describe ...
28 votes
1 answer
11k views

Getting "__r" relationship name from Schema.SObjectType.Fields

Say I have a master-detail relationship between two objects, Schematic__c and Part__c. I can SOQL query the master from the detail: [SELECT Schematic__r.Name FROM Part__c] If I'm building a query ...
25 votes
3 answers
21k views

Finding if which users have a record type available to them using SOQL

I would like to be able to execute a SOQL query that will allow me to see which users have access to a certain record type for a certain object. For example, if I have a case record type called Phone ...
  • 3,403
23 votes
5 answers
6k views

What is an easy (and fast) way to find a object named based on a parentid?

I have an app which is fired from a trigger on FeedItem and FeedComment. I can easily grab the posting user, date, parentid and type. However I am finding it difficult to rapidly determine the object ...
  • 231
18 votes
3 answers
9k views

Is there anyway to get the name/label of a field without doing a field describe?

I want to get the name and label of all the fields for multiple sobjects in one transaction and that will easily hit the governor limits. Is there anyway I can get the label/name without using a ...
  • 243
16 votes
1 answer
10k views

Account.sObjectType.getDescribe() vs Schema.sObjectType.Account

What is the difference in below two lines of code for getting the Schema.DescribeSObjectResult? // Get the sObject describe result for the Account object Schema.DescribeSObjectResult dsr = Account....
  • 510
15 votes
2 answers
2k views

Does anybody have a good way of mapping a key prefix to an object type?

I want to be able to reliably take an ID and map it to the appropriate object type so I can query the object in question. Before now I've tried using the global decsribe info, looping over the ...
  • 25.1k
14 votes
4 answers
7k views

How to tell whether a field is required or not in Apex by describe fields

I want to know how I tell whether a field is required or not in an Apex controller. In my controller I get the record id and then get the object of that record by a describe call, then I get all the ...
  • 1,935
14 votes
2 answers
14k views

Generic SObject update pattern

Question I know that it is possible to update a generic of List<SObject>, But what is the best approach to generate that list without knowing the SObjectType, only the ids ? Sample: List<...
13 votes
1 answer
11k views

Get all Parent and child objects related to the current object

I have a string which contain the name of a sobject. Now I want to get all the objects related to this object. Also want to get which kind of relationship it have with these object.
  • 3,773
13 votes
1 answer
2k views

DescribeSObjectResult missing fields when executed in managed package

Problem Description Not being able to use both custom and managed fields in a managed package when fields share the same API name (with different namespaces). When using the DescribeSObjectResult....
  • 143
12 votes
4 answers
2k views

Finding the SObjectType from the SObjectField

As part of the implementation of an API, I would like to be able to find the SObjectType from the SObjectField: public class MyClass { // Fields are from various SObjects public void myMethod(...
  • 133k
11 votes
9 answers
61k views

Retrieve API names of All object in Salesforce ORG using SOQL

How to write SOQL query to retrieve all the object Name and API names of Sobject in Salesforce
11 votes
2 answers
716 views

Apex method to find out if SObject is a setup object

Regular SObjects and Setup Objects can't be mixed in DML otherwise you'll experience a Mixed Dml Exception. How can Apex code find out if a given SObjectType is such a setup object? System.assert(...
10 votes
2 answers
2k views

How to efficiently determine the `name` field of an sobject for dynamic query?

Is there a more efficient way to determine the name field of an sobject other than iterating through all the fields obtained via DescribeSOBjectResult? Often, the name field is simply Name but in ...
  • 4,076
10 votes
2 answers
10k views

Access to State and Country Picklist values through Apex or API?

I recognize that State and Country Picklists are still a "Beta" feature, but does anyone know if, in Summer 13, its possible to get at the State and Country Picklist Values through either the Apex ...
  • 9,453
10 votes
1 answer
476 views

Drawbacks of using SObjectField.toString() over SObjectField.getDescribe().getName()

I often do '' + field where field is an SObjectField to get the field's API name. I like that much more than the clunky verbose field.getDescribe().getName(). So is there a reason I should not do it ...
9 votes
3 answers
12k views

converting string to Schema.SObjectField

I have created an API But struggling in converting String to Schema.SObjectField as If there is any possible way to cast string into Schema.SObjectField field type for example Account.example__c to ...
  • 2,563
9 votes
1 answer
1k views

Why is KnowledgeArticleVersion not in Schema.getGlobalDescribe()?

It's a bit inconvenient that this returns null: system.debug( Schema.getGlobalDescribe().get('KnowledgeArticleVersion') ); While this does not: system.debug( KnowledgeArticleVersion.getSObjectType()...
  • 2,584
9 votes
1 answer
705 views

Is there is any way to get standard field api name from standard report types reports in apex?

I want to get the api name of the standard field being used in Reports of Standard report types. I used describe methods to get the columns used in a report. I analysed some of standard reports ...
9 votes
1 answer
3k views

Field Sets & Dynamic DML & Describing Fields Included in Field Set

I am attempting to write generic code which will use a fieldset, allowing for dynamic creation of a query. This bit is documented well enough in dynamic DML examples from SFDC. In addition to the ...
  • 22.7k
9 votes
1 answer
152 views

Can an Object Definition's ID be obtained programmatically?

I've noticed that SF related lists are anchored (#) by a concatenation of the current record's Id, an underscore, the Id of the related list's object definition, and then "_target" (e.g. #...
  • 193
8 votes
1 answer
640 views

Name field of Group sObject is Not Nillable but returns null

I request the metadata for the sObject Group via: GET /services/data/v32.0/sobjects/Group/describe/ HTTP/1.1 In the resulting JSON i see the following metadata at the fields property: { ... ...
  • 133
8 votes
2 answers
2k views

What does object.isQueryable() actually mean?

What does is actually mean when a user can 'query' an Object? In other words: what rights does a user have when the Object.isQueryable() returns True? Pages like this only say that isQueryable ...
8 votes
2 answers
5k views

How to list down all Standard/Custom Objects and ignore System(Internal) Objects

There's always a requirement to pull ALL standard and custom objects using describe call ignoring all system/internal objects. Is there a way for same? One of option is to reference ProcessInstance ...
  • 1,231
7 votes
3 answers
25k views

How to get Id of a object

Is there any way to find out the Id of an object,object may be custom or native like if I have a custom object i.e Test__c and when I write some query to get the Id then Id must be return in this ...
  • 347
7 votes
1 answer
1k views

How to get a visualforce tab url in apex code

I have a requirement where when I click on a link need to to direct to a visualforce tab. So how to get the VF tab url dynamically using apex code. Thanks in adavance.
7 votes
1 answer
2k views

How to get list of All Objects enabled with Activities?

Is there anyway we can find all Objects which have Activities enabled, in APEX?
  • 5,768
7 votes
1 answer
6k views

Dynamically retrieving page layout fields

Is it possible to dynamically retrieve the fields on a certain layout? Possibly through something like DescribeLayout()? I'm having trouble finding examples on how to build a lightning component with ...
  • 191
7 votes
1 answer
2k views

Salesforce API via the Python beatbox module

I am new to accessing Salesforce data via the API. I am using the beatbox library for Python. My code: import beatbox sf = beatbox.PythonClient() sf.login('my user name', 'my password + security ...
  • 71
7 votes
1 answer
374 views

Standard field accessiblity inconsistent : feature or simply strange?

UPDATE: Thanks to @ca_peterson I could clarify the issue below and it all drills down to FLS. But even having identified FLS as the reason, the behavior is still odd and I have addressed it in this ...
  • 34k
6 votes
2 answers
2k views

Test if a field is available on arbitrary SObject record without using Describe calls

I have many Custom Objects in my package that have a common custom field Version__c. One part of my app serializes and deserializes records to/from Json. While deserializing I want to change this ...
6 votes
1 answer
269 views

Can we describe all the page names in salesforce

We need to get all custom page names into the select box. Is there any way that we can describe all pages like objects
6 votes
1 answer
1k views

Is there a Class.forName() equivalent for Apex

I'm looking to dynamically instantiate a class by its name. How can I do that in Apex? I thought about a factory method with a series of if-else statements, but am not satisfied with that as it isn't ...
  • 3,655
6 votes
3 answers
6k views

How to find only those Schema.SObjectType types that are visible in the Schema Builder

I can find a map of all String -> Schema.SObjectType types by invoking Schema.getGlobalDescribe(). However, that includes a lot of object types I'm not interested in (like casecomment, ...
  • 3,655
6 votes
1 answer
744 views

How to guard a FeedItem insert when code is executing in a Force.com Site?

I have some code that is used both through a normally licensed user and through a "Site Guest User" for a public Force.com Site. I am aware that for the latter type of User Chatter capabilities are ...
  • 133k
6 votes
1 answer
2k views

Update Record via @RestResource class, return related SObject

I'm trying to create a REST API class that will allow the following: POST Object ID Update(ObjId); ('Touching' the record, fires triggers on Salesforce) Find SObjects on a custom object that have ...
  • 185
6 votes
1 answer
373 views

REST API returns different results based on the base URL

Problem: Hitting the REST API from JS (inside a VF page) seems to be returning and old (or cached) version of the page layout. Examples: https://eu6.force.com/services/data/v40.0/sobjects/Contact/...
6 votes
1 answer
807 views

$ObjectType and picklistValues attribute

I've tried to use {!$ObjectType.Case.fields.Status.picklistValues} but it doesn't work Error: Unsupported type common.api.soap.wsdl.PicklistEntry encountered. Based on the documentation I see ...
  • 3,201
5 votes
2 answers
38k views

Get Label For SObject API Name

I have an exhaustive list of custom objects whose API Names and labels does not match. I end up opening each object in order to determine if the label has matching API Name.I want to see the API Name ...
5 votes
2 answers
4k views

Creating sobject using if i know object api name in string

I have an sObject which I know it's api name (without namespace prefix). How can I create a reference to it?
  • 4,503
5 votes
2 answers
3k views

Dynamic Schema getDescribe

I have two variables: public String selectedObject {get; set;} //selectlist public String selectedField {get; set;} //selectlist public String selectedDataType {get; set;} //text They are the ...
  • 665
5 votes
2 answers
3k views

System.LimitException: Too many describes: 101.?

I am getting this error as i have used getdescribe under for loop.Can some tell me how should i solve this..how to create map for this .please help. Thanks Map<String, Schema....
  • 1,751
5 votes
1 answer
861 views

Error when I populate lookup with external id using .put method

You can populate lookup fields using an object with an external id field populated like so: Custom_Object__c o = new Custom_Object__c(Account__r=new Account(External_ID__c='123')); insert o; ...
5 votes
1 answer
2k views

How to get a list of all Quote sobjects using apex/soql

It appears that Quote is a SF SObject, yet the following code renders the following error: [SELECT Id From Quote] sObject type 'Quote' is not supported. If you are attempting to use a custom ...
5 votes
3 answers
292 views

How to differentiate LIST apart from HIERARCHY setting in Apex?

My Apex code needs to dynamically reflect on user-defined Custom Settings. But the user could use a List or Hierarchy depending on their needs, so I need to be a bit careful manipulating each type. ...
5 votes
1 answer
3k views

Access the Related List Label for a Lookup relationship

I've searched high and low, and I can't seem to figure out the Apex syntax I need to use to access the Related List Label for a Lookup relationship. It shows up in the objectTranslation XML as ...
  • 4,441
5 votes
3 answers
1k views

Getting LastModifiedDate of Admin changes

Let's say you have a details page of a Contact. I would like to be able to track changes that were made to Contact, such as field name changes, field type changes, etc. I assumed that there ...
  • 2,700
5 votes
1 answer
383 views

Get list of "first-class" Salesforce objects

I'm working on a managed package that will allow users to select an object in their org and create a mapping with an external service. I noticed that Schema.getGlobalDescribe() returns a plethora of ...
  • 10.8k