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 ...
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 ...
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....
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
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 ...
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....
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 ...
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
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....
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 ...
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
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 ...
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 ...
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>{'...
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.
...
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....
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 = ...
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(), ...
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) ...
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 ...
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 ...
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,...
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'
...
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 ...
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 ...
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 ...
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, ...
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, ...
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
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....
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sobjectfield × 55apex × 31
sobject × 24
sobjecttype × 14
describesobject × 7
soql × 4
schema × 4
visualforce × 3
lightning-web-components × 3
rest-api × 3
managed-package × 3
map × 3
describefieldresult × 3
trigger × 2
picklist × 2
relationships × 2
string × 2
tooling-api × 2
dynamic × 2
dynamic-apex × 2
describes × 2
javascript × 1
query × 1
custom-object × 1
workflow × 1