Skip to main content
6 votes
Accepted

Where is SobjectType.newSObject useful

If you want to write a utility that creates records, this function is absolutely necessary in order to be generic at all. Sure, you could also use Type.forName, but that doesn't take nearly as good ...
Adrian Larson's user avatar
  • 151k
4 votes

Any way to check a field's updateablity ignoring profiles?

The only reasonable method I know of is to use a try-catch block: try { record.put(someField, someValue); } catch(SObjectException e) { // Field could not be written } Unfortunately, this is an ...
sfdcfox's user avatar
  • 502k
4 votes
Accepted

Get List<Schema.SObjectField> from field set

List<Schema.FieldSetMember> is just what Schema.FieldSet.getFields() gives you. You can call getFieldPath() on each field set member to obtain the field's API name, and then convert to a Schema....
David Reed's user avatar
  • 93.7k
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 ...
Adrian Larson's user avatar
  • 151k
4 votes
Accepted

How can I get the list of all fields(API name,Label,type) of any sObject?

//It provides to get the object fields label. String fieldLabel = fieldMap.get(fieldName).getDescribe().getLabel(); //It provides to get the object fields data type. Schema.DisplayType ...
NITHESH K's user avatar
  • 2,555
4 votes
Accepted

Can a new SObject type or new SObject field be created via the Tooling API?

You still cannot create Custom Object with REST API, only with METADATA API. Yes, you can create a Custom Field on existing sObject, request example: HttpRequest request = new HttpRequest(); request....
Mariia Illarionova's user avatar
3 votes

Error in initializing sObjectField

The issue is that your choice of variable name is shadowing the Account SObject type. Most things in Apex are case-insensitive, so Account, account, and ACCOUNT (for example) are all equivalent. The ...
Derek F's user avatar
  • 64.1k
3 votes
Accepted

Query on ApexPageInfo object to get created and lastedmodified fields

You need to refer to ApexPage rather than ApexPageInfo. Simple SOQL query below. SELECT CreatedById,CreatedDate,Description,Markup,MasterLabel,Name FROM ApexPage
suban khoja's user avatar
3 votes
Accepted

Convert Schema.SObjectfield to string

You can't serialize SObjectField, as the error says, but it's easy to get the value as a String: public string jsondata{get;set;} List<String> fieldschema = new List<String>(); for(Schema....
sfdcfox's user avatar
  • 502k
3 votes
Accepted

How can I find the exact field names and calculations, from a reporting field's friendly name?

The reporting engine actually provides some additional fields that do not directly exist in the database. This is some special magic specific to reporting. In this specific case, Amount (converted) is ...
sfdcfox's user avatar
  • 502k
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()...
Reshma's user avatar
  • 4,069
3 votes
Accepted

setType & setField methods not available in SObject - Apex SOAP API

The sample code appears to be using the Partner API. Your example error messages indicate you are using the Enterprise WSDL (com.sforce.soap.enterprise.sobject.SObject). The Partner API is loosely ...
Daniel Ballinger's user avatar
3 votes

Finding the SObjectType from the SObjectField

I know this is a little old, but I was searching how to solve this problem and I couldn't find anything useful. This is how I solved it: Type myObjectType = MyObject__c.myField__c.class; String ...
Moises Ponce's user avatar
3 votes
Accepted

Retrieve the type of field using Schema classes

there are two key points here: get dynamically SObjectType from SObject by calling getSObjectType() get map of fields by calling fields.getMap() List<String> fields = new List<String>{'...
Oleksandr Berehovskyi's user avatar
2 votes

Dynamic Schema getDescribe

For performances, it's prefered to use Schema.describeSObjects method instead of Schema.getGlobalDescribe. I did some performance tests and found it faster (time execution) and consume less Heap size. ...
abdou elMister's user avatar
2 votes

Address field: Set Address via Apex

If your custom address field is called Delivery_Address__c, then you can do something like this... obj.Delivery_Address__City__s = 'your city'; obj.Delivery_Address__StateCode__s='ON'; obj....
Justin Largey's user avatar
2 votes

Address field: Set Address via Apex

Here's an example for a new Lead: Lead lead = new Lead( OwnerId = u.Id, FirstName = 'John', LastName = 'Doe', Email = ...
Michael Sobczak's user avatar
2 votes

Finding the SObjectType from the SObjectField

Update Spring '23 v57.0 This is now possible using the getSObjectType() method. e.g. Schema.SObjectField myField = My_Object__c.My_Field__c; Assert.areEqual(myField.getDescribe().getSObjectType(), ...
Nick C's user avatar
  • 7,230
2 votes

Where is SobjectType.newSObject useful

The question appears to be about the difference between the various newSObject methods, not about the general need for that family of methods. From my reading of the (not entirely clear) ...
Keith C's user avatar
  • 137k
2 votes

How can I find the exact field names and calculations, from a reporting field's friendly name?

The "friendly name" would be the field's Label. What you are looking for as output is its API Name. You can loop through the fields in the describe and check their label. You might have multiple ...
Adrian Larson's user avatar
  • 151k
2 votes

Null pointer exception in SchemaMap

I would recommend double check the line no 2 Schema.SObjectType leadSchema = schemaMap.get('Tools__Order'); Double check the object name here . Tools__order does not look like proper name for an ...
Mohith Shrivastava's user avatar
2 votes
Accepted

How can I correctly convert List<SObjectField> into a list of comma-separated field names to build a SOQL String?

Using syntax like Tower__c.State__r.Name shouldn't even work, as far as I knew. Regardless, if the parent object is State__c, it would ultimately give you State__c.Name. If you want to include lookups,...
Adrian Larson's user avatar
  • 151k
2 votes

Any way to check a field's updateablity ignoring profiles?

You should be able to approximate with a query on the FieldPermissions object: Boolean isFieldEditable = 0 < [ SELECT count() FROM FieldPermissions WHERE Field = 'MyObject__c.MyField__c' ...
Adrian Larson's user avatar
  • 151k
2 votes
Accepted

Schema.getGlobalDescribe().get(objectType); doesn't work with custom objects

Is your object part of a managed package? If so, you may need to deal with the namespace as well. Map<String, sObjectField> mapping = fieldMap('myNs__CO_Shuttle__c'); You can avoid a lot of ...
sfdcfox's user avatar
  • 502k
1 vote

I need an SOQL query to find all the fields in an Object which are referencing to other Objects

I think SOQL query won't be able to provide for this instead use the Dynamic apex to find out about the lookup fields for the current object (Which is basically the fields on the current object ...
Ranjit Mishra's user avatar
1 vote
Accepted

Deduce Schema.DisplayType from a sample of JSON property values

I tried to parse the JSON and deduce its type using JSONParser. I couldn't find any direct mapping between System.JSONToken and Schema.displayType, So I have created a local map. Since there is no ...
Anmol Kumar's user avatar
  • 3,751
1 vote

Deduce Schema.DisplayType from a sample of JSON property values

I'm not going to write a full example, but I think it would be safe to go with a JSON.deserializeUntyped, then decode the keys to figure out what they should be. This gives you the types Boolean, ...
sfdcfox's user avatar
  • 502k
1 vote

How to create an efficient helper method that return an object given a map of field-values?

I would recommend creating a test data factory. It is essentially just an entire class dedicated to creating the base objects that are needed for almost every apex function (accounts, contacts, cases, ...
Logie C's user avatar
  • 121
1 vote

Salesforce API for getting all case comments from Case ID

You can call an API like this to get related stuff. https://ap2.salesforce.com/services/data/v34.0/sobjects/Case/5002800000oGq8CAAS/CaseComments
Karthik's user avatar
  • 11
1 vote
Accepted

Is Scientific notation allowed in double

Yes, apex does not allow scientific notation in double, which means you cannot assign scientific notation value to a double variable as shown below Double d = -2.347774E-10; OR sObjRec....
Azeez's user avatar
  • 103

Only top scored, non community-wiki answers of a minimum length are eligible