Stack Exchange Network

Stack Exchange network consists of 175 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.

0
votes
2answers
17 views

Multiple Child Records from Parent Related List: Url No longer exist

I need to create Multiple Child Records from Parent Related List but i get the Error: "URL No Longer Exists" but the data saved in the database. Also, it seem that the Parent Id does not populate ...
2
votes
1answer
21 views

How do I find list of all Permissionable Objects?

I need a way to find a list of All permissionable Objects for an organization, both Standard Object and Custom Objects. I would except to get this information from DescribeSObjectResult but it has no ...
0
votes
1answer
9 views

Not able to retrieve both SObjectType (Schema.SObjectType) for ObjectPermissions and (Schema.SObjectField) for SobjectType field on ObjectPermissions

I need to retrieve both SObjectType (Schema.SObjectType) for ObjectPermissions and (Schema.SObjectField) for SobjectType field on ObjectPermissions. When I try to access ObjectPermission.sObjectType ...
9
votes
1answer
55 views

How can I safely cast a List<sObject> to a specific concrete type?

I have a List<sObject> genericList in scope in a method. The list was created and populated elsewhere and passed in as a parameter. It could be: a List<sObject> that is homogeneous. E.g. ...
0
votes
1answer
44 views

Need Help on Modifying Code [closed]

I found this example on a dynamic hierarchy for Accounts and I need help as to how to modify it to display an account hierarchy. I am unable to figure out why I recieve this error message when testing ...
2
votes
1answer
35 views

Can you dynamically instantiate a Custom MetaData object in the same dynamic way you can an SObject?

With SObjects we can do something like: sObject sob = [Select id,name from Account limit 1][0]; Can you do the equivilent with Custom Metadata? For example does something like this exist: ...
0
votes
2answers
78 views

Dynamic Batch apex with sobject iteration

I have a batch apex which takes the record from source object (can vary like Opportunity, Opportunity line item etc) and paste the record into target object i.e Opportunity_Prod_Batch_Record__c (fixed)...
5
votes
1answer
39 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
67 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
350 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
41 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
78 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
457 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
204 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
35 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
165 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
75 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
803 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
77 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
50 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
950 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 = '...
4
votes
2answers
3k 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
278 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
108 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
1k 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
661 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
138 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
429 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
64 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 ...
8
votes
2answers
3k 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
389 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 ...
2
votes
2answers
1k 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
595 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
417 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
2k 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
177 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
657 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
76 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
351 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
597 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
294 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
63 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
717 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
2k 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
328 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
164 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
690 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
4k 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....