Search Results
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 |
An sObject represents an object, such as an Account or Campaign. An sObject is the base object for all objects in Apex.
6
votes
Accepted
convert string to sObjectfield type
You can access SObject fields using Strings (as well as using SObjectField tokens): see the get and put methods listed in the sObject Class documentation. … But if you want to do that it is possible via this map for any SObject:
Map<String, SObjectField> m = SObjectType.Account.fields.getMap();
PS
The way that you access fields using strings (or SObjectField …
6
votes
List all fields of query with subquery
To access the related lists you first need to cast the generic SObject type to the correct type:
List<Contact> contactList = new List<Contact>();
for (SObject sob : query_result) {
Contact c = (Contact … methods:
for (SObject sob : query_result) {
List<SObject> caseList = sob.getSObjects('Cases');
List<SObject> taskList = sob.getSObjects('Tasks');
// Do whatever you want here with the lists …
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 …
2
votes
Can I set sobject id in a method?
Assigning the id in the constructor of the SObject does work. …
17
votes
Accepted
How to use addError() with a dynamically derived field name?
You could vote for this Provide an additional addError method on SObject that accepts a field name idea, but as it has got nowhere in the last 5 years there is no reason to expect any progress in the next …
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 …
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. …
3
votes
problem with sObject as parameter
Your local variable:
decimal smallQtyPenalty = 1;
is hiding the class name smallQtyPenalty. (That is the compiler has discarded its idea that smallQtyPenalty is a class name in favour of thinking t …
3
votes
Accepted
How to prevent refreshes from blowing out sobjects and tables
I suggest that you add a field to the SObject called something like "ApplicableOrganizationId" and then route all access through a method that looks something like this:
public String getCallbackUrl() …
1
vote
Accepted
building an sObject from a json string in VF page
If the JSON string has names that exactly match the SObject field names then you can use code like this:
var s = '{"Field1__c" : "Hello", "Field2__c": "World"}';
var o = JSON.parse(s);
var sob = new sforce.SObject …
0
votes
Display sObject fields on Visualforce
Converting the field names into a single string risks matching a field called e.g. "Name" with some other field such as "OtherName__c". So one piece of advice is to keep the fields separate:
// Field …
11
votes
Accepted
How to create nested JSON object from custom sObject?
I suggest building and serializing nested maps for this:
Map<String, Object> m = new Map<String, Object>();
for (options__C opt:options) {
m.put(opt.Name__c, new Map<String, Boolean>{
…
7
votes
Accepted
apex:inputField can only be used with sObjects
The apex:inputField value u.contact must correspond to an SObject field. That is typically done by u being a reference to an SObject and contact being an SObject field name. … For your example, that SObject field would be lookup field to Contact. …
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 …
1
vote
Accepted
Getting field value dynamically while using describefieldresult
DescribeSObjectResult d = Account.SObjectType.getDescribe();
List<String> fields = new List<String>(d.fields.getMap().keySet());
String soql = 'select ' + String.join(fields, ', ') + ' from Account where Id = :id';
SObject …