Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 887

An sObject represents an object, such as an Account or Campaign. An sObject is the base object for all objects in Apex.

0 votes

Casting SObject record to Task object wipes out all related data

Likely cause is the specific behaviour of the deserialization methods. Try JSON.deserializeUntyped instead: Task taskRecordFromString = (Task) JSON.deserializeUntyped(jsonString); Your JSON.deseriali …
Keith C's user avatar
  • 137k
4 votes
Accepted

How to Dynamically cast the type of an 'Object' in apex at runtime

The getType method you are calling directly returns a DisplayType value rather than a String so change your code to: DisplayType displayType = record.getDescribe().fields .getMap() .get(fieldN …
Keith C's user avatar
  • 137k
1 vote

I need to update all Contact Fields dynamically , I am trying throught Schema.SObjectType bu...

SObjectField f = fieldItems; if (String.isNotBlank(con.get(f))) { existingContact.put(f, con.get(f)); } because the SObjectField can be used directly as Apex has map-like syntax for dynamic access of SObject … See the SObject Class documentation. (JavaScript does offer the syntax you used.) I also removed the assignment of the existingContact value to itself as that seems pointless. …
Keith C's user avatar
  • 137k
1 vote
Accepted

Add List of Inserted Id's to generic sObject List

You can convert the Id value into a record of the correct type (as all instances must have a specific type) and assign the record the Id using this pattern: List<SObject> inserteds = new List<SObject … >(); for (Database.SaveResult result : results) { if (result.isSuccess()) { SObjectType t = result.getId().getSObjectType(); SObject r = t.newSObject(result.getId()) …
Keith C's user avatar
  • 137k
21 votes

Howto wildcard SELECT * to query all fields of objects in APEX?

I suggest that rather than relying on some utility class, you become familiar with the platform's APIs so you can compose the appropriate solution each time you want to query all the fields, particula …
Keith C's user avatar
  • 137k
1 vote
Accepted

Insert record from static resource csv

If you can change the header row to contain the field API names not label text then you can use code like this: String[] headings = filelines[0].split(','); for (Integer i = 1; i < filelines.s …
Keith C's user avatar
  • 137k
1 vote

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

There are many other methods available too - see SObject Methods. Custom objects all have these Custom Object Standard Fields. … When you have an SObject you can get its SObjectType via its getSObjectType() method. An Id also has a getSObjectType() method. …
Keith C's user avatar
  • 137k
0 votes
Accepted

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

* Test.createStub doesn't work for SObject/SObjectType/SObjectField. … = null) return System.hashCode(field); else throw new InvalidStateException(); } } // Equivalent of SObject public class Obj { Type type; SObject o; …
Keith C's user avatar
  • 137k
7 votes
Accepted

What happens when I edit an sobject in a Set?

Equality and the hash code value are based on all the properties of the SObject which makes sense. … There is an SObject-specific nasty case: if you put SObjects in a set before they are persisted, persisting them will set an Id in the SObjects and your set will be broken in any following logic. …
Keith C's user avatar
  • 137k
2 votes

Retrieve object type via id using apex

.); call at the end: Id id = 'xxxxxxxxxxxxxxx'; SObjectType t = id.getSObjectType(); SObject[] records = Database.query('select Id, Name from ' + t + ' where Id = :id'); System.debug(JSON.serializePretty …
Keith C's user avatar
  • 137k
2 votes
Accepted

Iterate over a few objects in a single loop?

You can use this dynamic access technique (all SObjects support map-like methods): for (Sobject record : kbList) { String stringField = (String) record.get('StringFieldApiName'); ... } to avoid … If you do need type-specific logic, the relatively new switch is a good way to do that: for (Sobject record : kbList) { switch on record { when Faq__kav f { // f is a reference …
Keith C's user avatar
  • 137k
1 vote

Collection read only : Unable to add to set

So instead create your own mutable (writeable) set: Set<Id> accIds = new Set<Id>(); for(List<sObject> sob: searchList) { Set<Id> tempIds = (new Map<Id,SObject>(sob)).keySet(); accIds.addAll(tempIds … ); } Personally I would write the logic like this: Set<Id> accIds = new Set<Id>(); for(List<sObject> sobs: searchList) { for(sObject sob: sobs) { accIds.add(sob.Id); } } …
Keith C's user avatar
  • 137k
1 vote

Query and Retrieve all records from Recycle Bin for backup using APEX

You will need to do a separate query for each SObject type with IsDeleted = true in the where clause: there is no "query by any type" mechanism. …
Keith C's user avatar
  • 137k
2 votes
Accepted

Is it possible to cast an sObject to another object that is dynamic?

But there are are get methods in the SObject class for this case where the field names can be used in string form: List<sObject> objects = database.query(queryString); for (sObject o : objects) { …
Keith C's user avatar
  • 137k
1 vote

FIELD_INTEGRITY_EXCEPTION Error in Test class

Given that AssetList holds a list of Patent__c objects: Public static List<Patent__c> AssetList; it is pretty unlikely that the following statement and similar statements are correct because lookup …
Keith C's user avatar
  • 137k

15 30 50 per page