Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [dynamic-apex]

Dynamic Apex enables developers to create more flexible applications by providing them with the ability to: access sobject and field describe information, access Salesforce app information, and write dynamic SOQL queries, dynamic SOSL queries and dynamic DML.

5
votes
1answer
35 views

What does “lightweight and serializable reference to an sObject” mean?

While reading documentation about Dynamic Apex and Apex Describe, I found the definition of token which says: Token — a lightweight, serializable reference to an sObject or a field that is ...
-1
votes
2answers
52 views

How to Divide a list which has set of duplicate values in it in apex

for(AggregateResult hier4: hierarchy) { fld4.add((String)hier4.get(Field1)); fld5.add((String)hier4.get(Field2)); fld6.add((String)hier4.get(Field3)); string Soqlstr3=' Select Name '...
1
vote
1answer
110 views

Dynamically Cast Map<String, SObject> To Specific SObject

We realized that often time in our code we're iterating through a list of SObjects and creating a map of String to SObject. To try and reduce how many times we're repeating this code, we were going to ...
2
votes
1answer
25 views

Dynamic sObject Lookup field throws “SObject row does not allow errors” if lookup is entered record name that do not exist in org

Feels like I'm not having a good day at all with platform :-) ... another day and another issue with platform dynamic sObjects :( So I'm trying to create an sObject record dynamically from a VF page. ...
4
votes
2answers
44 views

SObjectType.newSobject(null, true) doesn't populate default values if called in vf action method, any tips?

I'm trying to create an sObject instance using following code: Schema.SObjectType targetType = Schema.getGlobalDescribe().get(objectName); sObject sObj = targetType.newSObject(null, true); This ...
1
vote
3answers
257 views

Like Operator is not working with Dynamic Variable in SOQL Query

Here I'm trying to perform LIKE operation in SOQL when I'm passing a variable dynamically the Query is not returning the results? List<string> companies=new list<string>(); List<...
0
votes
0answers
191 views

Dynamic Field Value in Custom Button or Link Detail

I have a Dynamic Field Value or Link Detail attached to Contact/Leads, this link uses merge fields to build a link that contains Contact.MobilePhone like so for example: Button or Link URL https://...
5
votes
1answer
32 views

Can a managed package safely access custom objects that are not part of the package using dynamic Apex?

There seems to be a documentation inconsistency. The Apex developer guide, in the section on "Understanding Describe Information Permissions" https://developer.salesforce.com/docs/atlas.en-us....
-2
votes
1answer
38 views

Assign row values from one object to another object as columns or fields

I have row values as dates in one object, i.e dates within a given year. I have a second object with field names as Day1__c, Day2__c and so on till Day366__c. I want to assign the dates to the fields ...
0
votes
2answers
70 views

Dynamically get the Map of “DataType” and all “Fields”

I want to dynamically get the Map of "DataType" and all "Fields" associated with that data type . I`m trying below, but keep getting full list of the fields. I ONLY need a map where "DataType" will ...
1
vote
1answer
67 views

Impact of permissions on dynamic apex?

I'm looking for some clarification on the behavior of dynamic apex. I am seeing some inconsistent behavior around schema global describe and sobject describe field maps. In the below example ...
4
votes
3answers
674 views

Dynamic casting in apex

I'm not sure how to solve the following: public String dummy(SObject[] obj) { obj.getsomething(); } obj can be two different objects (both of them implement a method name getsomething). The name ...
1
vote
1answer
48 views

Dynamic Fields in for Loop

Is there a way to dynamically change the fields within a for loop? As an example, if I have for loop: for(Account a: myQueryResult){ if(a.parentId = fieldVariable){ Do something ...
0
votes
1answer
35 views

Dynamic record creation using Strings for field name on new record?

I have a solution that I'm working on where one object has a mapping to a field on another object using a text field. Let's say Account is the source object, I have a text field called "target field ...
1
vote
1answer
626 views

Dynamically find field value from Map

Currently I'm looping through values, based on the loop # I want to be able to get different field values. Example: Integer years = 1; for(Integer i = 1; i <= formYears; i++){ String fieldName = '...
3
votes
2answers
2k views

Display error message on particular field in VF page

In our VisualForce page, we are displaying the fields dynamically based on the user's selected fields in setting page and the order of fields displayed changes based on user's wish, which we are ...
1
vote
1answer
209 views

Compare same Object types dynamically

How to compare two types of objects (NOT SOBJECTS) at runtime? Example: Object ob1 = (String)'ab'; Object ob2 = (String)'ab'; Apparently if I debug ob1==ob2 gives me false. (false statement, see ...
0
votes
1answer
750 views

Lightning Populating Picklist Fields From Apex Controller

I am following this example to dynamically create pick lists: https://singhforce.wordpress.com/2017/01/08/turn-on-lightning-part-4-building-picklist-values-dynamically/comment-page-1/#comment-32 ...
0
votes
1answer
80 views

Dynamic Select Option in Remote Objects Visualforce. This page is not record-specific

The question is in the code comments. Thank you! <apex:page> <apex:remoteObjects > <apex:remoteObjectModel jsShortHand="js" name="myCustomObject__c" fields="Id"> <apex:...
1
vote
1answer
616 views

Get Attributes from an Apex Object Dynamically

Is it possible to get the name of the attributes of an apex class? I have a class below, is it possible to get the name of its fields at runtime? public class MyObjectApex { public String name {...
1
vote
2answers
506 views

Is it possible to get value of a static String dynamically from an apex class

I have a apex class consisting some static variables, is there any way to get the value of one of these variables dynamically? Example : public with sharing class ConstantsClass { public ...
0
votes
1answer
99 views

Need help in dynamic soql Formation

I have a requirement where in dynamic query i have to change the format of a string.Below is the way i have tried i am getting following error after adding getTempStringFormatValue method in the below ...
0
votes
1answer
314 views

Executing a batch class based on the class name or id entered in as a string or id

I am creating a page in Salesforce that lists all our batch classes and will allow you to execute each one individually. Basically I am querying every ApexClass, finding the batchable ones, and ...
0
votes
2answers
47 views

Created a dynamic string and want to fetch list size on the basis of that string [duplicate]

I have an object that is having multiple child objects. I want to perform certain actions only if the current record has child records associated with it. For this I am checking the related list's ...
6
votes
2answers
2k 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()....
1
vote
1answer
309 views

Dynamic field set with mass update

We have a VF page that allows users to mass update cases based on whatever fields are on the page. The page displays a temp case whose values are then applied to the list of selected cases. We ...
0
votes
2answers
777 views

Dynamically Set object properties to custom objects

I need to dynamically set some values to create/update records of a custom object. The main idea is to create something like this: MyCustomObject.fields["fieldName"].Value = "some value"; Does Apex ...
0
votes
2answers
458 views

apex:inputField not binding value to controller

I'm trying to update an Account from a visualforce but so far I haven't managed to be able to save the changes. I'm using apex:inputField for the user interface but when I try to save the values they ...
2
votes
1answer
246 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 ...
0
votes
1answer
1k views

Escape Sequence Single Quotes Error

I am creating a dynamic query. string s = '%' + searchText + '%'; string query = 'Select name, ShippingCity, ShippingState, ShippingCountry, rating, type, Industry, ownerId From Account Where name ...
3
votes
1answer
128 views

sObject.get(fieldname) detects changes from null to blank?

I was writing a utility class which can give the names of the fields that changed during an update trigger (I have a specific set of fields that i want to track, not all fields). My code snippet is ...
0
votes
1answer
447 views

How can I dynamically create JSON from many dot-separated strings (for example project.owner.name)

I have many strings in the custom setting with and without dot-separated field names. For example: id name owner.name owner.id project.key project.owner.name project.owner.id document.owner....
6
votes
1answer
75 views

Does SObjectType Access Guarantee Id Access?

I am writing a fluent query builder which I hope will pass security review, and I still have a few nagging questions. I will refrain from asking more than one question per question, so right now, what ...
8
votes
1answer
294 views

Working with SObjects instead of concrete custom objects (i.e., abstraction in apex)

We have a bunch of custom objects, some of which implement a specific set of custom fields of the same type. (e.g., UniqueID, ExternalID, etc.). I want to be able to write one method that takes and ...
0
votes
1answer
1k views

How to get sObject field value

This question is related to more or less that I have asked here My question is, how to get the field value from sObject to little demo you here. Here is my vfp: <apex:page controller="...
0
votes
2answers
514 views

How to bind <apex:inputField> using dynamic sObject

Is that possible to bind the sObject field in the visualforce page? I'm getting the below error but not sure its helping me but I'm sure it has to do with mySobject that I have in the inputField I ...
0
votes
3answers
213 views

How to map Dynamic sObject Mapping?

I have posted this question two times but i'm not getting the solution for that reason i'm again posting this question. First i have done the reading of two sobject fields dynamically. The two ...
0
votes
1answer
54 views

save error :unknown property 'DataInsert.fields'

Here is my apex class: global class DataInsert { // property declarations Set<String> fields ; global PageReference doInsert() { // other logic ...
4
votes
1answer
617 views

Access fields dynamically in a trigger

I need to use dynamic fields in a for loop so that i can pick up the values from different field on insertion of an object accordingly. Below mentioned are the fields which needs to be dynamically ...
0
votes
1answer
1k views

Schema.getGlobalDescribe() get ObjectType Describe

I'm trying to get the DescribeSObjectResult by writing the following code: public String fObjectName {get;set;} fObjectName = (String)Apexpages.currentPage().getParameters().get('objname'); ...
0
votes
1answer
300 views

Vague error message - duplicates value on record with id

It's vague error message and I have already spent several hours trying to find out what I'm doing but could not able to find the cause I'm trying to do SObject.clone and I'm not preserving the Id here ...
1
vote
0answers
136 views

Apex - Create WorkOrderLineItem fieldset

We have created multiple fieldset for various custom and standard objects using Apex but new "WorkOrderLineItem" object related to "Services" seems be different. Here is sample code which creates ...
1
vote
1answer
547 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: ...
0
votes
2answers
3k 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....
0
votes
2answers
266 views

how to check FLS of sObject dynamically

if(Schema.Accountr__c.getSObjectType().getDescribe().isAccessible()) In the Above line, I am checking whether that Accountr__c object data is accessible or not. My query is, can I check the FLS of ...
6
votes
2answers
399 views

Which is faster between static and dynamic getSObjects?

What is the difference in execution between . (dot) notation and getSObjects method? Omitting of course that I can parametrize with string getSObjects method. for example: Account....
3
votes
1answer
1k views

INVALID_FIELD, Foreign key external ID not found - Inserting Related Records via External Id

I am trying to insert related records via an External Id. i am using an approach described here where we create an empty parent object with the same external Id like the "real" parent. It is a self-...
7
votes
1answer
74 views

Ramifications Of Cross-Object Reference Just For Id?

The Problem I see this pattern often and it drives me crazy: Id accountId = someOpportunity.Account.Id; // just reference AccountId! OR List<MyObject__c> records = [SELECT ... FROM ...
2
votes
2answers
215 views

Dynamic method to take in a list of sObjects, cast and loop through them and perform field logic?

We currently have 2 different classes of code doing essentially the same thing on both the lead and account objects- grab the country and postal code and assign a territory. We are looking to combine ...
1
vote
2answers
402 views

Dynamic Apex SObject Iteration

I've been trying for many hours to find the correct syntax in the documentation and via other searches in Google to get some dynamic code to run. Hopefully someone here will be able to provide the ...