Questions tagged [reflection]

Reflection allows a developer to essentially modify the behavior of the code at runtime. Currently there is little support for reflection in Salesforce.

Filter by
Sorted by
Tagged with
0
votes
2answers
283 views

How can I get dynamic API name in apex?

I have an question,I created a FieldSet named Detailed_Content in several sObjects,now I want get one of sObjects's Detailed_Content FieldSet,like the following code: public List<Schema....
1
vote
1answer
582 views

How can I create a Map<Id, Account> from a List<sObject> parameter when I know all the records are Accounts?

I'm doing some work with the ESAPI Library. In particular, when updating records it is used to enforce FLS with the following method: global SFDCAccessControlResults.UpdateResults updateAsUser( ...
1
vote
1answer
2k 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
65 views

Send object name into a function

I was trying to pass an object name to a function as an String but I was 99% sure that it won't work and it didn't work. So I am wondering how is it possible to send an object name to function. void ...
3
votes
1answer
205 views

Managed package cannot see a class from another managed package

We have a following setup: a managed package pkg_a which provides a global virtual class Cls_A to be extended a managed package pkg_b which contains a global class Cls_B that extends pkg_a.Cls_A a ...
6
votes
2answers
1k views

Dynamically calling methods in Apex

Assume this simple class in a managed package namespaced PKG: global class Semaphore { private static Boolean m_isLocked = false; global static Boolean lock() { m_isLocked = true; } ...
4
votes
1answer
2k views

Type.forName(namespace, classname) returns null in managed package

I'm trying to pass a class name from a subscriber org up into a managed package, to make the package extensible. The package is going to use Type.forName(namespace, classname) to create an instance of ...
0
votes
2answers
740 views

Using getSobject to fetch the parent Account of an Account

I would like to dynamically fetch the parent Account of an Account in a similar fashion to the way it's done in the selected answer to this question. However, this doesn't seem to work in this case. ...
5
votes
3answers
254 views

How to differentiate LIST apart from HIERARCHY setting in Apex?

My Apex code needs to dynamically reflect on user-defined Custom Settings. But the user could use a List or Hierarchy depending on their needs, so I need to be a bit careful manipulating each type. ...
2
votes
1answer
245 views

What are all the public methods for Messaging.SingleEmailMessage

I am wrote a wrapper class that builds Messaging.Email instances but need to test that the Messaging.Email object is built properly. The published API at https://www.salesforce.com/us/developer/docs/...
0
votes
2answers
676 views

How can I mock a query of ApexClass for testing?

While recently working on a large project where unit test executions would run upwards of 2 hours, we realized we could get a performance gain by avoiding touching the database (e.g. SOQL and DML) ...
37
votes
6answers
26k views

How to get the Runtime-Type of an Object dynamically (for Primitive Data Types and SObjects)

Is it possible to get the Type of an Object (it's not an SObject)? String s = 'test'; doSomething(s); public static void doSomething(o Object) { // need to find out if o is a string or an ...
33
votes
3answers
15k views

Return Name of class from instance of that class

I need a quick approach to something like: MyClass mc = new MyClass(); String theName = ClassNameProvider.getName(mc); // returns 'MyClass'
7
votes
2answers
4k views

How to get the attribute class list

Does exist on apex something like Class.getDeclaredFields? I need to loop on class attributes dynamically : public class MyClass { public type1 att1; public type2 att2; ... public void function() { ...
2
votes
2answers
1k views

How to get fields in deeper object tree levels with reflection

I'm constructing a dynamic query to get some fields from the database. I use a root object for that purpose and branch out from it. My_Custom_Object__c -> Account__r.Id So if I want to get an ...
9
votes
2answers
5k views

How to invoke a method of an apex class at run time

We have a usecase where we need to invoke an instance of a class and invoke a method at run time using string. I know with reflection i can instantiate a class. But how do we invoke a method of a ...