Skip to main content

Questions tagged [sobjecttype]

A token representing a custom or standard SObject type in Apex. Akin to Class in Java, but the token's getDescribe method must be called to get detailed information.

Filter by
Sorted by
Tagged with
0 votes
1 answer
438 views

Schema.sObjectType.(...).isUpdateable() method is returning true but should return false

In short, I'm trying to follow the PMD Source Code Analyzer Project, and I realized that before making an update I must validate whether the user has permission to change the field (ApexCRUDViolation)....
Noops's user avatar
  • 3
2 votes
0 answers
846 views

Cannot access sObjectType 'OrgWideEmailAddress'

I am encountering an exceptionally unusual issue. I have a User A (running under Profile A). This profile has minimal permissions. It has only Permission Set A Permission Set A gives "View Setup ...
jreid42's user avatar
  • 121
0 votes
1 answer
172 views

Cannot create IsAccessible statement for User object

I'm trying to create this statement: if(User.sObjectType.getDescribe().isAccessible()){ User userData=[SELECT id, Profile.Name FROM User WHERE id=:user.id]; return userData.Profile....
CPS's user avatar
  • 365
0 votes
1 answer
423 views

Typecast to SObject list to SObjectType passed to a method

I have a list of SObject and SObjectType parameters passed to a method sObjectTypeRecord in the below method contains Lead.SObjectType,it can also contain any other SObjectType like Account....
Madhurima's user avatar
  • 1,425
0 votes
1 answer
3k views

(Schema.SObjectType) || Method does not exist or incorrect signature: void

I'm trying to list the Record Types that a user has access to. Unfortunately, this cannot be done through SOQL Query (IIRC) and the only choice I have would be to either use Schema.SObjectType (Apex) ...
VanceSOQL's user avatar
  • 103
0 votes
1 answer
1k views

Retrieve the type of field using Schema classes

I am trying to create a generic class to retrieve the type of a field for any sObject. I am struggling with the following part of the code: String[] fields = ['Id','Name']; for(sObject o : ...
arpit gupta's user avatar
2 votes
2 answers
282 views

How to get the local object from a string in the managed package?

Our managed package has a namespace, say DemoApp, and a custom object named Form__c, the client's org also has a custom object Form__c According to the doc here: https://developer.salesforce.com/docs/...
Adam's user avatar
  • 469
0 votes
2 answers
357 views

Is it possible to get parent SObjectType from sObjectField token?

Is it possible to get SObjectType dynamically from field token like Account.Name?
Grzegorz Połuch's user avatar
0 votes
1 answer
62 views

try/catch vs describe calls inside for loop which has more performance impact?

We have a generic method which is called in a for loop for each record where we try to get a value of a field using Sobject get method. Before getting the field we have to make sure that field ...
Isha's user avatar
  • 163
2 votes
1 answer
436 views

Attempt to de-reference a null object when using alternative to getGlobalDescribe

In the following code String myString = 'Account'; SObjectType sObjType = ((SObject) Type.forName(myString).newInstance()).getSObjectType(); When myString = a object name does not exist i get a ...
Vneq's user avatar
  • 79
1 vote
1 answer
144 views

Apex: How to figure out actual sobject that has been queried having only AggregateResult type

To narrow down the problem - we have a method like this: private static Object doSomeProcessing(List<AggregateResult> records) { ... // need to add additional logic here based on sobject ...
wesaw's user avatar
  • 3,130
0 votes
1 answer
244 views

Iterating Over the Sobject

Hi I need to to iterate over the sObject as --> Schema.PicklistEntry for this i have created the for loop to iterate over it but getting below error, can anyone help me out for this. {`List<...
RajAryan's user avatar
0 votes
1 answer
1k views

Unable to pass object Name in the SObject for loop to call methods Dynamically

I am trying to optimize my code, instead of using object Name in if else I want to pass the SObject parameter and combine below code Instead of using separate objects I am trying to merge if else ...
user62694's user avatar
4 votes
1 answer
812 views

How do I tell if a custom metadata type field is a Field Definition?

I have the following code: public static void getFields(){ SObject obj = (SObject) Type.forName('Health_Cloud_Integration_Settings__mdt').newInstance(); DescribeSObjectResult describe = obj....
MetadataBaiter's user avatar
3 votes
1 answer
312 views

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

The Tooling API is great - very easy to use from Apex code by making HTTP calls containing straightforward JSON. Two questions: Is it still not possible to create a new SObject type e.g. ...
Keith C's user avatar
  • 136k
12 votes
2 answers
3k views

What is a good pattern for recursion blocking in generic trigger handlers?

Here I'm talking about a handler that covers all the TriggerOperations and that accepts SObjects of arbitrary type. And the recursion problem is where a change caused by a trigger results in that ...
Keith C's user avatar
  • 136k
5 votes
1 answer
967 views

Mocking SObjectType to make tests independent of 3rd party managed packages

When unit testing code that interacts with SObjects in other managed packages, being able to mock those SObjects would be helpful so the packages don't have to be installed to run the unit tests. The ...
Keith C's user avatar
  • 136k
0 votes
2 answers
329 views

SOQL statements cannot query more than 20 different child types error

I have the following piece of code public static void fetchRelatedRecords(String primaryRecordString){ SObject primaryRecord = (SObject)JSON.deserialize(primaryRecordString, SObject.class); ...
Madhurima's user avatar
  • 1,425
2 votes
1 answer
6k views

How to get child relationship name from Parent Object in Apex

In the following piece of code, i am trying to do a dynamic parent - child query public static void fetchRelatedRecords(SObject primaryRecord){ String recordId = (String)primaryRecord.get('Id');...
Madhurima's user avatar
  • 1,425
0 votes
0 answers
494 views

isUpdateable method return false on without sharing class

I having a visualforce page with a controller(without sharing) I have tried both method: - Schema.sObjectType.Opportunity.isUpdateable() - Schema.DescribeSObjectResult - isUpdateable() Both of them ...
manhnt.bkit's user avatar
1 vote
1 answer
48 views

How to eliminate if/elseif/else chain for SObjectType variables? [duplicate]

In a few places I have code of this nature: private static void myMethod(SObjectType t) { if (t == Claim__c.SObjectType) xyzForClaims(); else if (t == Account.SObjectType) xyzForAccounts(); ...
Keith C's user avatar
  • 136k
14 votes
1 answer
3k views

Most efficient way to switch on SObjectType?

It is a bit odd we can't evaluate a switch statement directly on SObjectType, so I am trying to determine conclusively which workaround is the most efficient. Just to verify, I tried to compile this ...
Adrian Larson's user avatar
  • 151k
2 votes
1 answer
4k views

Retrieve SObject using Schema SObjectType class

I am trying to create a dynamic class to retrieve a record for update. I struggle with the following part of the code: targetSObject = new sor.getSObjectType()(ID = sObjectID); For example, if this ...
Matthew Metros's user avatar
3 votes
1 answer
4k views

Trigger: Find out the name of the object the trigger is firing for?

Is it possible for the trigger to see the name of the object it's firing for? Say can I make the OpportunityTrigger be aware that the object name it's firing for is Opportunity without hardcoding the ...
Arthlete's user avatar
  • 4,957
0 votes
1 answer
271 views

Get sObjectType by ExternalID

Same as we can do using sobject ID, do you know if it's possible to get sObjetType of an object using it's externalID ? Something like this is it possible ? Id sobjectId = Id.valueOf(externalId);...
Bryce's user avatar
  • 442
1 vote
1 answer
2k views

How can I pass a custom object type as a parameter in a method call?

I am working on a Lightning Component and I am trying to refactor my code. I have four combo boxes set up to query junction objects. The selection for object one determines what fills the list for ...
Bradley S's user avatar
12 votes
2 answers
3k views

How to distinguish between ContentDocument and ContentNote?

There seems to be some unusual stuff going on with SObjectType for the enhanced note ContentNote (ERD) object and the underling ContentDocument (ERD) structure. For example, both these return a ...
Keith C's user avatar
  • 136k
0 votes
2 answers
3k views

dynamic SObjectType.getDescribe().isAccessible()?

I have a Lightning component with a search bar that uses Apex to search Cases, and another that searches Opportunities. For example: @AuraEnabled public static List<Case> searchCases(String ...
PatMcClellan__c's user avatar
1 vote
1 answer
5k views

System.QueryException: sObject type 'OpportunityLineItem' is not supported

We get this script exception (in managed package) emailed from a customer instance. Apex script unhandled trigger exception by user/organization: XXXXX/YYYYY pkg1.ProductOppStockCheck: ...
Pasan Eeriyagama's user avatar
3 votes
1 answer
1k views

Why should I even use the SObject type for the aura:attribute type?

Sometimes I see code using the SObject type as an aura:attribute type and I don't see why! <aura:attribute type="Account" .. It feels like it behaves the same as "Map", it's just a javascript ...
itsmebasti's user avatar
  • 6,477
6 votes
1 answer
513 views

Apex differentiate between Lookup field to master detail field

Is there a way to differ between regular Lookup field to a MasterDetail field? When calling to getDescribe() on a field both of them holds the type of REFERENCE. EDIT: After further investigation, ...
omri_saadon's user avatar
6 votes
1 answer
5k views

Apex differentiate between RichTextArea, LongTextArea and TextArea

When calling getDescribe() on a custom field I get the field data. Although, I need to know when the field is Text Area (Long), Text Area (Rich) or just TextArea. When seeing the result from ...
omri_saadon's user avatar
5 votes
1 answer
429 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 ...
Charles T's user avatar
  • 11k
1 vote
2 answers
739 views

Null pointer exception in SchemaMap

I am trying to find whether a given field resides in a particular Sobject. I am using the code When I try to run this code, I am getting null pointer exception in line no. 3. I guess schemaMap ...
Aruna's user avatar
  • 427
2 votes
1 answer
208 views

Null Pointer if sObjectType isn't Case

I have the apex trigger below that is meant to check the WhatId on a new Task if the WhatId belongs to a case. The trigger then populates fields on the related Case for ActivityDate and Task Type. ...
Marc Swan's user avatar
5 votes
4 answers
214 views

Is it possible to get the label or describe from an SObjectTypeToken?

In my controller, I have some SObjectType property: public SObjectType myProperty { get; private set; } I want to get the label (or better yet the entire describe) of this object in Visualforce ...
Adrian Larson's user avatar
  • 151k
13 votes
2 answers
18k views

Get SObjectType from 'ObjectName' without using getGlobalDescribe()?

I'm working on rewriting a utility method that gives record type ids without using SOQL queries. I found two ways to do this: Schema.getGlobalDescribe().get(objName).getDescribe()....
Avinash's user avatar
  • 2,111
0 votes
0 answers
469 views

Get SObjectField with same API Name dynamically across SObjects

I have a unique situation. I have several different SObjects that are using the same field API names and I'm trying to get them dynamically by passing the SObjectType. For instance. This is for a ...
Andrew L.'s user avatar
  • 857
1 vote
2 answers
20k views

assign values to a Map<Id,List<SObject>> in an apex trigger

I have below code where I face error as incompatible type. Can someone please help me resolve it? I can't get how to populate it. Apex Code Map<Id,List<Account_Territory_Loader_vod__c>> ...
Testing_SFDC's user avatar
  • 2,950
1 vote
0 answers
2k views

Unable to query PermissionSetAssignment object

I have a method in my package's postInstall script that is trying to check to see if the user has access to edit custom settings. In the method, I query the PermissionSetAssignment object. When I run ...
Suryatej Mukkamalla's user avatar
1 vote
1 answer
2k views

Create Customize cloning , copying old to new record

UPDATE: AFter I have tried with the @Adrian approach I'm getting the following error now: |EXCEPTION_THROWN|[65]|System.DmlException: Insert failed. First exception on row 0; first error: ...
Nick's user avatar
  • 7,064
3 votes
2 answers
1k views

How does SObjectType.newSObject() works?

From the documentation > SObjectType Class I see that we can instantiate a new sObject from the SObjectType class Could you tell me how does the code below create a new Account regarding the required ...
benahm's user avatar
  • 2,627
4 votes
1 answer
1k views

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

I'm trying to create an object of SObject class and then setting its type to Lead and setting one of the fields for Email. Eventually, I want to pass this object in findDuplicates() method. But the ...
Udit Desai's user avatar
1 vote
1 answer
7k views

How to get field of an object dynamically

I am trying to build a VF component. One of the feature of the component is the ability to show the fields related to an object dynamically. For example - if my component is used in an VF page like: &...
SfdcBat's user avatar
  • 4,811
4 votes
2 answers
2k views

Where is SobjectType.newSObject useful

I was going through a document at the SObjectType class where there was a method named - newSObject(recordTypeId, loadDefaults). I see that using this method one can create a new Sobject with default ...
SfdcBat's user avatar
  • 4,811
1 vote
1 answer
169 views

Insantiate list dynamic one line

So I am able to return the sobject of a list like so: //sobjectlist = list of records passed into fuction. Schema.SObjectType sotype = sobjectList.getsObjectType(); Now this gives me sotype with ...
Genko's user avatar
  • 636
2 votes
1 answer
186 views

Standard SObject which are not exposed by Salesforce

I would like to know if there is Standard SObject for Changeset or Package? I noticed that 033 is prefix for Package and 0A2 is key prefix for Changeset. However, neither of there objects are not ...
Patlatus's user avatar
  • 17.2k
0 votes
1 answer
1k views

From Parent ID, dynamically derive child's lookup field name/token

I'm trying to save a new record dynamically, but I'm having a problem with a lookup field. For instance, I'm able to get the parent object with the id. Id relatedID = '<someId>'; SObjectType ...
Andrew L.'s user avatar
  • 857
3 votes
2 answers
448 views

DescribeFieldResult.getSOAPType() returns type not in enum list

Was working on some generic apex, and wrote a few lines of code to get the SOAPType of a field based on the type and the name. Went off, and worked on some other areas, and wrote something which used ...
battery.cord's user avatar
  • 8,845
2 votes
1 answer
371 views

Opportunity.IsPrivate via Apex but not Developer Console?

I'm trying to query all of my Opportunity fields at runtime by using Schema.SObjectType.Opportunity.fields. This seems straightforward, but I am seeing some strange behavior when I put some of my ...
loneboat's user avatar
  • 387