Skip to main content

Questions tagged [generics]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
47 views

Can we rely on reference when it comes to changing Map items changing?

My code for(FieldDefinition def : [SELECT QualifiedApiName, EntityDefinitionId, EntityDefinition.QualifiedApiName FROM FieldDefinition WHERE EntityDefinitionId in :...
pincet's user avatar
  • 941
-1 votes
1 answer
532 views

Generic lightning web component [closed]

I want to create a related list with LWC that i can use for all object. Can someone help me with any ideato solve this problem.
Mohamed Chakri's user avatar
0 votes
1 answer
3k views

How to use custom metadata to map generic JSON

I want to create a generic REST API Webservice where the configuration of mapping fields can be done trough custom meta data. How would I set this up?. I want to be able to have an administrator add ...
Thomas's user avatar
  • 2,320
0 votes
2 answers
1k views

Is it possible to Generically deserialize a Json string wit nested arrays in Apex

I want to be able to Generically deserialize a Json string with nested arrays for a web-service, since the structure isn't known beforehand and kan change a lot. I did some reading a seems doable but ...
Thomas's user avatar
  • 2,320
1 vote
1 answer
4k views

Cannot deploy flow, Getting error 'Screen component 'ComponentName' is missing a type mapping 'T'

I have created a flow screen component that work for multiple object. In the flow, I have created a collection variable. I have created an LWC component that uses the collection variable. When I try ...
lambad's user avatar
  • 385
0 votes
2 answers
832 views

updating reference field using generics sObject

I am trying to perform upsert on opportunity based on external Id. I am building the opportunity objects based on sObject as I am using that function for other objects too. Now Opportunity object ...
Hunt's user avatar
  • 245
0 votes
1 answer
951 views

Tips to generalize code in apex with Map<string, set<string>> and Map<string, set<SObject>> and how to call method of SObject

I am working on some generalization of my code and I'm struggling with some cases which are irritating me because I think I'm having code duplicity. 1) I'm often working with some map<string, set&...
yeye's user avatar
  • 125
1 vote
0 answers
100 views

Create dynamic triggers based on user selection from managed package [duplicate]

I have a requirement where I need to create two triggers inside a managed package. So, when the package is installed, the admin has a choice to either use the default objects available in the package ...
Prakash Raj's user avatar
8 votes
3 answers
6k views

How to accept generic "SObject" in Lightning Web Component for Flows?

I've got a custom built LWC to be used within a screen component in a flow. My component basically renders a collection of SObjects in a distinct way. It can also deal with different types of sObjects....
Christoph's user avatar
  • 1,022
1 vote
2 answers
1k views

Generic function - Custom meta data type

I would like to do a generic function to get custom meta data type records and return it as a Map. In a first time with just one field , that means Map<String,String> and in a second time with ...
Raphael D's user avatar
  • 636
0 votes
1 answer
3k views

How to get recordtypeid from generic object

I want to be able to pass an object, and recordtypelabel as string into a controller and get the recordtypeId. How do I achieve this. I currently get variable does not exist for the custom object. @...
Thomas's user avatar
  • 2,320
0 votes
2 answers
472 views

Is it possible to create a generic Map swapper?

I have a method: public Map<Object, Object> swap(Map<Object, Object> valueByKeyMap) { Map<Object, Object> keyByValueMap = new Map<Object, Object>(); for (Object key : ...
Brian Kessler's user avatar
1 vote
2 answers
2k views

Is it possible to convert Map<Object, List<Object>> to Map<Id, List<SomeConcreteSObject>> without a loop?

As a Salesforce developer, I am frequently working with Maps and am looking to abstract the process of generating maps from SObject lists. I've created the following helper class: private class ...
Brian Kessler's user avatar
-2 votes
1 answer
171 views

How to create a Map with generics Id and String?

How to create a Map<Id, String>([SELECT Id, Name from Account]);? The query returns Map<Id, Account>. I want to get a Map<Id, String> without using loops and without having to ...
lemdev's user avatar
  • 427
1 vote
1 answer
674 views

Dealing with Generics in Apex

I have some code that i want to try and emulate generics for. I know there are no generics in Apex but is there something we can do instead? Let me explain (String) sfBorr.get('SSN__pc'); sfBorr is ...
Ben Arnao's user avatar
  • 427
8 votes
1 answer
544 views

If I know the API Name, how can I get and work with the Schema.ChildRelationship?

Like many SFDC developers, we have SObjects which are related to other custom relationships. So, for example, MyCustomObject__c could have a relationship with MyCustomRelationship__c which in Apex we ...
Brian Kessler's user avatar
6 votes
2 answers
2k views

In Apex, can I detect if an Object is a Map, regardless of parameterized types?

When I declare a Map, I need to give the types, e.g.: Map<Id, SObject> sObjectByIdMap = new Map<Id, SObject>(); We can assign map to generic values as Objects: Object value = ...
Brian Kessler's user avatar
10 votes
2 answers
12k views

What is the best way to cast/convert Map<String, SObject> to Map<Object, Object> and back again?

To reduce code duplication, at the risk of type safety, I have some method: public Map<Object, Object> doSomething(Map<Object, Object> inputMap) { Map<Object, Object> outputMap; ...
Brian Kessler's user avatar
2 votes
1 answer
79 views

How can I abstract building maps from SObject Lists in a good way? [duplicate]

I frequently find I want/need to map a list of SObjects by a value other than it's own Id. So, I'd like to abstract this process to make it reusable. For example, I might want to map Contacts by ...
Brian Kessler's user avatar
4 votes
2 answers
449 views

How can I upsert a homogeneous List<SObject>, in a good way? [duplicate]

I have some abstracted code, which at the end of some process will create a homogeneous list of SObjects. It could be a list of Accounts, it could be a list of contacts, it could be a list of some ...
Brian Kessler's user avatar
1 vote
1 answer
1k views

Generic SObject Utility to dynamically set field values from Map

I'm trying to create a generic utility method which takes a List of sObjects and a Map of fieldNames to fieldValues. I'd like to, for example, do the following: List<Lead> leadList = [SELECT Id ...
Mike's user avatar
  • 1,209
6 votes
3 answers
2k views

Does apex support generics?

I don't know if Apex supports generics but how can I make the below class more generics where I should be able to pass any data type? below is the example: the problem I have is this: public class ...
Nick's user avatar
  • 7,153
8 votes
1 answer
2k views

Pros and cons of generic SObject list vs multiple lists of objects

For one of the requirements I have to write code to update multiple records of different objects. Originally I was planning to do the obvious: get needed records, change some value, update these lists,...
Novarg's user avatar
  • 5,294
13 votes
2 answers
12k views

How to write a generic list<t> method that will cast at runtime?

I recently tripped across the need to take a list of objects (instances of a class--not sobjects) and split them into smaller lists of 200 members each. The unit test below shows the code inside a ...
tggagne's user avatar
  • 465
5 votes
3 answers
6k views

Getting a type of the generic object

How to get a type of the generic object? I have a method that gets as parameter some object. It can be realy everything. In my example it is a list of strings. But it can be a map or set or some other ...
Sergej Utko's user avatar
  • 22.1k
7 votes
1 answer
6k views

Is it possible to create a method that uses generics? [duplicate]

... or at least pass in a specific class? Here is what I have right now: private static invoice_response GetResponse(String jsonResponse) { invoice_response deserialized = (invoice_response) ...
AngryHacker's user avatar
  • 1,481
3 votes
1 answer
2k views

Is it possible to write a method that accepts both SObjects and Apex Class Instances?

I have an Apex method that takes a list of SObjects, a source field name, and a destination fieldname. For each SObject in the list, it looks at the source field, does some work, and populates the ...
Jason Clark's user avatar
  • 12.1k
33 votes
1 answer
8k views

Generic Apex Trigger

So I was kind of throwing round the idea of making a generic apex trigger that is callable by multiple objects. Say you have the following sObjects: Account Sales__c Sales_Contacts__c And I wanted ...
gfppaste's user avatar
  • 845
14 votes
1 answer
6k views

How do I use Type.forName to deserialize a generic list of SObjects?

When the new Apex type methods were added in Summer '12, it was possible to do Type t = Type.forName('MyClass'); MyClass newObj = (MyClass)t.newInstance(); What is the equivalent when I want to ...
metadaddy's user avatar
  • 16.5k
5 votes
1 answer
76 views

How to get the old Test Class UI back? Or possible workarounds with the new UI?

Is there anyone else who is sorely missing the old test class UI where it shows the entire list of Apex classes covered by running one test class? Another good feature of the old UI was that you could ...
Shumon Saha's user avatar
  • 4,652
7 votes
2 answers
4k views

What is "Skip to main content"?

In any Salesforce page, if no element is in focus and you press Tab⇄, a hidden element Skip to main content is put into focus. What does Skip to main content do?
Shumon Saha's user avatar
  • 4,652
10 votes
1 answer
8k views

What is the correct JSON to deserialize a map of sObjects?

I'm trying to store a map of sObjects in a static resource. I want to be able to store default values for test setup methods. I was able to get it working with the following JSON in the static ...
Greg Grinberg's user avatar
9 votes
4 answers
4k views

How do you deserialize json into the correct virtual class?

Let's say I have a virtual class and two classes that extend it and I am getting a JSON response that could be either one of those classes. Is there a way to deserialize the JSON into the appropriate ...
Greg Grinberg's user avatar
39 votes
2 answers
20k views

Can you use generics in Apex?

While researching the possibility of using generics in apex I can across a blog with this: "Generics are partially supported in Apex, you must be using them with Collections and Batch Apex." ...
Ryan Elkins's user avatar
  • 7,697