Questions tagged [sobject]
An sObject represents an object, such as an Account or Campaign. An sObject is the base object for all objects in Apex.
608
questions
7
votes
1
answer
5k
views
How to use addError() with a dynamically derived field name? [duplicate]
I know I can add an error to a field as follows:
Account someAccount = [select id, name from Account limit 1];
someAccount.name.addError('Bad Name');
How can I do that if the field name is only ...
7
votes
2
answers
4k
views
How to accept generic "SObject" in Lightning Web Component for Flows?
I've got a custom built LWC to be used within a screen component in a flow.
My component basically renders a collection of SObjects in a distinct way.
It can also deal with different types of sObjects....
7
votes
2
answers
1k
views
Why does JSON serialization give different results when the Sobject is created from a SOQL query and when the Sobject is instantiated normally?
I am getting some very odd behavior from the JSON serializer where if the Sobject was originally instantiated from a SOQL query it will exclude any fields that were not part of my query from the ...
7
votes
1
answer
1k
views
Importing string typed data into an sobject
I have a relatively large Map<String, String> which is basically a key/value map of sobject field names and their values. Obviously, all the values are strings, but fields are not (there are ...
7
votes
1
answer
174
views
Why doesn't SFDC allow MIXED_DML_OPERATIONs anymore?
Okay, I know very well by now that SFDC does not want and often does not allow us simply insert and/or update Setup and/or "Non-setup" sObjects in the same context anymore, something I used to do with ...
7
votes
4
answers
1k
views
Determine sobject Type From Id Using SOAP API
I'm using C# and would like to determine the type of an sObject based on it's id.
I would like to pass an id to my app and have it return a list of accounts related to it. I need to identify the ...
7
votes
2
answers
4k
views
Quick way to delete/truncate all records in an org
I have a development org with a quite complex object structure and a ton of demo data.
To refactor thr structure I want to get rid of all this data.
My first thought was to use the new "Truncate" ...
7
votes
1
answer
1k
views
Track Activities value for a custom object
I have a custom object. I enable Track Activities for this custom object and then I create a managed beta. If this managed beta is installed in a new org, the track activities will be enabled for ...
6
votes
3
answers
39k
views
sObject ' ' type is not supported
Hey everyone I've been seeing this a lot lately and am trying to figure out why this error is thrown when querying the SOAP API directly. I've tried several very basic SOQL queries such as
SELECT ...
6
votes
2
answers
15k
views
What is the object that stores "files"
Which object stores the files (not attachments)? I'm looking to access this via a trigger.
Is it possible to add a field to this document/file objects?
6
votes
1
answer
9k
views
How to compare two sObjects from 2 List<Lead>()?
I'm in need of a way to see if changes were made to a reference of an object, and compare to the original values. This is independent of the trigger context variables such as oldMap + newMap.
Is ...
6
votes
2
answers
4k
views
How to create nested JSON object from custom sObject?
I am trying to create some config for front end based on config objects.
I have one custom object where I specify options that I need. Each option is separate custom object of this type. I want to ...
6
votes
2
answers
733
views
Do email results come in the same order as the list of emails
I populate a list of emails emailsToBeSent and send them all at once. However These emails are related to different sObjects. And to me it is important to know which sObject the returned results are ...
6
votes
2
answers
3k
views
Instantiate an instance of the SObject type
Is there a way to instantiate an SObject without a SOQL query?
This works :
Type t = Type.forName('Account' );
Account o = (Account) t.newInstance();
But this doesn't :
Type t = Type.forName('...
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 ...
6
votes
2
answers
1k
views
Testing code that depends on an SObject
I have a page which displays an entity that belongs to another package. In order not have a hard dependency to this package, I build a wrapper object and make this wrapper object accessible to the ...
6
votes
1
answer
804
views
Deserialize History record with read-only fields?
I'm trying to serialize, then deserialize an AccountHistory record. However, whenever I include a read-only field, such as NewValue, in the JSON, when I try to deserialize the record, I get this error:...
6
votes
2
answers
1k
views
Utility Method Returning Different Type (Set instead of List)
Previously I had posted this question awhile back: Utility Methods flexible enough for all sObject Types
Now I want to expand my method a bit to return a Set<Object> instead of a List<Object&...
6
votes
1
answer
5k
views
JSON serialize SObject including fields with null values
I've currently got a use case where I would like to JSON serialize an SObject, but include fields with null (blank) values.
According to the documentation (https://developer.salesforce.com/docs/atlas....
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 ...
6
votes
4
answers
8k
views
Is it possible to check whether the record if modified or not from apex?
I have a scenario that need to check whether the record has been modified or not. If the record ir modified by any other user except user A. Need to show an error Message.
Currently i have added a ...
6
votes
1
answer
3k
views
No such column on sobject error occurring on sObject that does have that column
When attempting to update a custom object using SF default API endpoints (/services/data/v43.0/sobjects/MyCustomObject__c/customId__c/4003) I am getting a weird error telling me that a column doesn't ...
6
votes
1
answer
256
views
Why are SObject fields returned to an LWC via @AuraEnabled Apex immutable?
I get this error:
TypeError: 'set' on proxy: trap returned falsish for property
'cvcp__ReturnToWorkType__c'
when attempting to set a value via JavaScript inside an LWC (Lightning Web Component):
sob....
6
votes
1
answer
2k
views
Unable to read SObject error in Lightning Component when record has been queried from the database
I had encountered the "Unable to read SObject" error when attempting to pass an SObject record from Lightning to an @AuraEnabled Apex method.
Based on this question, I first tried setting the "...
5
votes
4
answers
32k
views
Invalid conversion from runtime type LIST<ANY> to MAP<String,ANY>
I'm trying to make a webcall to pull data from an external webservice. After that call I would like to insert my data that comes in the form of JSON into my custom object called Company. However I am ...
5
votes
4
answers
2k
views
Can I tell if I queried a field?
I have some code that queries some fields from an object. I then use the schema to loop over all of the fields of an object. Is there a way, while I'm looping through the schema to tell if I had ...
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 ...
5
votes
3
answers
7k
views
Serialize Class to JSON with correct sObject API field names
I want to use the standard Force.com REST API to create a case remotely from another Salesforce instance in my instance.
I want to populate two fields on creation: "Subject" and "txt_UserId__c".
...
5
votes
2
answers
2k
views
Determine if an SObject has an error
Is there a way to calculate if an SObject in a trigger context has had an error added to it (either with addError or through a validation rule)?
I have some trigger processes I don't want to run if ...
5
votes
1
answer
863
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
2
answers
2k
views
Methods to Check if Sobjects are Equal
Use Case:
Need to allow changes to only one specific field on an opportunity when at a certain stage.
Problem:
How to efficiently determine within a trigger context that a only the specific field ...
5
votes
1
answer
12k
views
apex:inputField can only be used with sObjects
I am trying to create a custom visualforce page that saves new opportunity contact roles to an opportunity. I am having trouble creating the first step of listing out all contacts that relate to that ...
5
votes
4
answers
2k
views
Why am I unable to pass an Opportunity from a Lightning Component into an @AuraEnabled Apex controller method?
I have a Lightning Component with an Opportunity attribute. The controller calls a helper method, which obtains the Opportunity from the component and attempts to pass it into Apex to be saved.
I am ...
5
votes
1
answer
5k
views
convert string to sObjectfield type
I have a custom setting where I have fields api name and getting the field api name and use with sObject. At that time I am getting error cannot use string with the sObject. How can I convert the ...
5
votes
1
answer
4k
views
How to retrieve a value from a parent field with SOQL via partner API in java
I have a parent-child relationship with timesheets relating to users.
I am trying to retrieve an Employment ID field from the parent record with SOQL and this is my query, where the UserID is a field ...
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 ...
5
votes
2
answers
70
views
Codes and Values
We have clients that use a lot of codes in their day to day activity.
Eg: Take a look at the UK Government Common Basic Dataset: https://www.gov.uk/government/publications/common-basic-data-set-cbds-...
5
votes
1
answer
315
views
What is "Interaction Object State Definition"?
Just noticed this "Interaction Object State Definition" in the Classic Setup UI. Curious about what it is or will be (and Googling didn't help me). Links or description appreciated.
5
votes
1
answer
2k
views
How to get recentlyviewed objects for all users?
Salesforce REST APIs support endpoints for getting updated, deleted and recentlyviewed objects. I am interested in getting the recentlyviewed items. This endpoint returns data of the form
{
"...
5
votes
4
answers
9k
views
Creating list from custom objects with relationship [closed]
I want to create a list in order to use it in a vf page with the tag apex:pageblocktable.
The schema below is just for learning purposes, it has 3 custom objects with look up relationships.
I had ...
5
votes
1
answer
703
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 ...
4
votes
2
answers
16k
views
Setting field values generic SObject
Is there a way to instantiate an SObject?
I have done the following:
Id objId = 'a0Ci000000vd7xA';
String objName = ((Id)objId).getSobjectType().getDescribe().getName();
Type t = Type....
4
votes
2
answers
6k
views
Can someone please explain what is meant by sObject?
I am very new to the Apex programming first.And I know about Standard & Custom objects. And also the the custom objects have an extension of '__c'. I observed in the programming lot of reference ...
4
votes
1
answer
1k
views
Collection store exception adding all List<Opportunity> to List<Account>
I a have a problem in my code, i try to merge two lists into a Sobject list in order to optimize the DML operation, but i get this error during run time:
Collection store exception adding all List<...
4
votes
3
answers
6k
views
Maps: adding more (related) sObjects than key values using PUTALL method
Here's the scenario: you've loaded a bunch of account IDs as keys into your map. But now, instead of loading account records as the sObject values, you're going to load a related object, such as ...
4
votes
3
answers
9k
views
How to check if SObject has certain field?
I hope you'll help me to solve my problem :)
I've written a class that check if a Sobject has a field of a certain name
public static boolean hasSObjectField(String fieldName, SObject so){
return ...
4
votes
2
answers
3k
views
How to use GetSObject to retrieve related data in a null safe manner?
I have a lookup relationship.
If I just do the following query it works fine:
Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId];
system.debug('c:' + c);
However with ...
4
votes
1
answer
4k
views
enableChangeDataCapture' not valid in version 38.0
I’m not sure what causes this error message and I’m trying to deploy my app and getting this error message in Jenkins.
All Component Failures:
‘1. objects/Employment__c.object -- Error: Property '...
4
votes
1
answer
2k
views
Insert multiple SObject data in Salesforce as single transaction using REST calls
I am using following soObject call to insert new row in the Account table at Salesforce server :
curl -H "Authorization:OAuth use your session_id" -H "Content-Type: application/json" -d @Test.json "...
4
votes
2
answers
435
views
How can I upsert a homogeneous List<SObject>, in a good way? [duplicate]
I have some abstracted code, which at the end of some process will create a homogeneous list of SObjects.
It could be a list of Accounts, it could be a list of contacts, it could be a list of some ...