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 [collection]

The tag has no usage guidance.

1
vote
1answer
32 views

Optimize code by reducing many If-else Conditions?

If-else code which I have written. I want to optimize it. (Using maybe Collection). Can someone show me how to do it? if(form.first_name.value == '' && form.last_name.value == '' &&...
1
vote
2answers
118 views

Exception not being caught; System.FinalException: Cannot modify a collection while it is being iterated

Why is this Exception not being caught? I read that System.LimitException is not caught but didn't see anywhere about System.FinalException. Non-Working Code @AuraEnabled public static List<...
0
votes
1answer
31 views

How to merge these two map into one map?

Set<ID> folderIDS = new Set<ID>(); Map<ID,Custom_Folder__c> foldersToUpdate1 = new Map<ID,Custom_Folder__c>(); Map<ID,Custom_Folder__c> foldersToUpdate2 = new Map<ID,...
0
votes
2answers
130 views

Basic Map And I am Stuck in FOR Loop [duplicate]

Here is my Map Map<id,List<Custom_Report_2__c>> mapreports= new Map<id,List<Custom_Report_2__c> >(); for( Custom_Report_2__c cr:cr1){ mapreports.put(cr....
1
vote
1answer
53 views

How to keep displaying set of fields on visualforce with “Add a new item” action again and again

I have a requirement where I have to display fields on visualforce page and then whatever user enters into those fields, fetch them and create a record out of it. I am able to do that one time but I ...
0
votes
0answers
11 views

Live agent API returning data always in ASC order

We are adding list for search result while hitting the live agent API call. This is returning always data in ascending order. Is their any way by which we can define the order for data collection ...
1
vote
1answer
330 views

how to get value from map when wrapper class is the key

I have a wrapper class of picklist values and labels. I am creating a map with picklistValues and List as key and value types. Now, I am getting an error won this line -- objResults.get(...
0
votes
0answers
14 views

Salesforce Flow: transform a coma separated list to a collection

I have a case when multiple values are submitted via Web-to-Case form in a single text field. The task is to create as many lookup relationships from the list as values listed. Before going APEX I ...
-3
votes
1answer
31 views

Why are these collections not equal?

I am currently working on the list concepts of apex and working on this piece of code: List<Integer> ages = New List<Integer>(); ages.add(10); ages.add(20); List<Integer> one = New ...
0
votes
1answer
43 views

Is there any documentation evidence that order of Map keyset converted to List is preserved?

When we execute a code Map<String, String> tm = new Map<String, String>{ 'Monday'=>'\u041f\u043e\u043d\u0435\u0434\u0456\u043b\u043e\u043a', 'Tuesday'=>'\u0412\u0456\u0432\u0442\...
1
vote
1answer
73 views

How to build and serialize

Keith C's answer builds the following "config" output: config: {option1: {isActive: true, isRequired: true}, option2: {isActive: true, isRequired: true} } by looping ...
1
vote
1answer
269 views

Facing “common.apex.runtime.impl.ScalarList@a1324f1f”

I have a child object to contact called"ObjectA".I have a discipline field(text) in the child object and I have the same field in Contact too.Now If I insert 4 child records with different contact ids,...
0
votes
2answers
25 views

Looping Collection doesn't show same order they have

I created a collection (list, set) for Decimal Values. Following are the collection values and their corresponding debugs from debug log I added values to collection and following is the debug. ...
2
votes
1answer
166 views

Flow and InvocableMethod Simple Question

How would I create an array of the values from the flow and pass them into the APEX @InvocableMethod? My method is taking in a list of Strings: @InvocableMethod public static List<String> ...
2
votes
4answers
446 views

Apex equivalent to associative array?

I have the following list definition in my Apex controller: List<Object> mylist = new List<Object>(); And I would like to do something like: mylist.add({ key : objKey, label : ...
4
votes
1answer
255 views

Generic parameter not accepted for sets?

While working on some code for a utility method to remove values from a List, I wrote this method signature, which accepts a List<Object>: public static List<sObject> Exclude(List<...
1
vote
2answers
710 views

Get Unique keys map and Repeated keys map

Trying to form a two maps. One should contain only unique key and its values and another should have repeated keys and its values. Name Position User1 Developer User2 Designer User3 ...
2
votes
2answers
93 views

Retrieving results from a map

I'm trying to work with and understand maps. I have the following map and I don't know how to retrieve one of the results from it, can some one explain what I'm doing wrong? Map<String, ...
10
votes
3answers
793 views

Why Set<Sobject> doesn't support DML operation

As we know that set<Sobject> and list<Sobject> are collection type. So basic question I do have why Set doesn't support DML operation ? We can perform DML on List<Sobject> but why ...
0
votes
3answers
51 views

set to string conversion

Set<ID> objIDs = new Set<ID>(); //objIDs is used to store the user Id's i have two id in ObjIDs, for example: 0054E000001jEoUQAU, 0054E000001lC07QAE. How to query the email address ...
2
votes
3answers
176 views

How to Create a Read-Only Collection? [closed]

I want to create a collection (List or Set) which can behave like Trigger.New context. Means If we use the collection out side of it's class, we should not be able to add any element in this ...
0
votes
1answer
21 views

What is the Correct collection class structure to hold SOQL subquery results?

I've got a scenario where a status field on the parent object needs to be updated to reflect the status of the most recently created child object. To solve this, I've done a SOQL with a subquery :- ...
6
votes
1answer
183 views

Doesn't Set<T> collection implement Iterable<T> interface? [duplicate]

I am trying to join String elements of Set with semicolon. Set<String> elements = new Set<String>{ 'foo', 'bar' }; System.debug(String.join(elements, ';')); getting the ...
0
votes
1answer
246 views

List<string> how much values/Size can it store?

I am Mapping my XML -> String xml; total characters stored into the above string. which needs for iteration of 100's of related records, now I am into a list string -> LIST<STRING> ...
0
votes
1answer
141 views

any shortcut to get set<String> from map<Id,Set<String>> ?

Map<String,Set<String>> st= new Map<String,Set<String>>(); st.put('one',new Set<String>{'1','2'}); Set<string> ss = new Set<String>(); ss.addAll(st.values())...
15
votes
2answers
9k views

List.contains() method in Salesforce

Is there any specific reason why salesforce did not provide list.contains() method. Edit 1: The below methods are added to List class and are available after Spring 18 release to Sandboxes and ...
0
votes
1answer
325 views

Making multiselect picklist value of a record to Map as Key value

In Product I have a multiselect picklist called Zonelist. I just need to have the Zonelist value in a Map collection. For example: Product Name - HP Monitor Zonelist - Zone1; Zone2; Zone3; How can ...
3
votes
1answer
339 views

Pass Case Ids collection to visual workflow from Case List View Custom Button and update cases taking from input screen

Requirement From Case list View, user will choose one or more cases and will click on "Update Due Date" button, where it will show a screen to choose the "Due Date". Due Date screen And finally ...
0
votes
1answer
29 views

Map Clarification

I have declare the collections in trigger code: Set<String> markets = new Set<String>(); Map<string, Map<Date,Holiday__c>> holidays = new Map<string, Map<Date,Holiday__c&...
1
vote
0answers
810 views

Removing duplicates from a SObject Collection in Visual Flows

I am trying to tackle creating multi-touch campaign attribution using visual workflows and am running into a particular use case. To look at all of the Campaigns that are related to the Opportunity, ...
1
vote
1answer
2k views

Compile Error: Loop must iterate over a collection type: Map<Id,List<Event>>

In the code below, I get an error on the bolded line. Says Loop must iterate over a collection type: Map> Any idea how to troubleshoot? Map<Id, List<Event>> events = new Map<Id, List&...
1
vote
1answer
97 views

Not sure why but apex:repeat returning Previous rows of the List

I have a Custom object Quote_Bundle_Product__c and Bundle__c and Product_Quantity__c scenario is : i have developed one visualforce page and that has functionality like user will select ...
0
votes
2answers
2k views

Sorting a List<Asset> by a date

I have fetched assets sorted by date using SOQL query. When I do for(Asset a:lstAsset) and add a to a list, the sort order from the SOQL query is lost. I want the sort order to be retained. Is there ...
0
votes
2answers
65 views

Converting list to map have improper output

Tring to convert List <MBT_SFFB__Facebook_Page__c> to Map<String,MBT_SFFB__Facebook_Page__c> These are the fields in Object :- MBT_SFFB__Facebook_Page__c Select ID,...
0
votes
0answers
162 views

Two different object with same API name, one is part of managed package. Getting collection store error

I have installed a managed package on my org. That managed package has an object with same API name as one of my custom objects. I have a trigger on my custom object where I query my object and assign ...
0
votes
1answer
553 views

How to compare two Different Object Values in Trigger?

I have one Object called "BillingEvent" It has 4 fields. Ordernumber_c, vinnumber__c, CenterExitDate__c, MADCDate__c I have another Object called "Vehicle".It has 6 fields. Ordernumber_c,...
0
votes
1answer
40 views

How to reduce time taken to insert 40000+ records in salesforce using trigger

i am inserting 40000+ records one time in my organization. suppose as per my requirement 19543 record is satisfied to my condition. but 1 to 19542 records are cross checked(unsatisfied ) in my ...
2
votes
1answer
112 views

Is there a better way to order my collection?

I'm trying to display a chronological list of CaseHistory records to display case edits. I have the following code: public Map<CaseHistory,String> getHelpdeskHistory() { List<...
17
votes
1answer
305 views

Is there a specific reason why we can't upcast Sets?

As most stories here begin, I was writing some code for a project that I was working on, and stumbled across an oddity when writing some unit tests. I was testing a method that has a Set<sObject>...
1
vote
1answer
104 views

SOQL for a collection

Is it possible to do a "SOQL for loops" for a collection? I want to know the number of Assets for each AccountID. At first time I created a set that contains the AccountID and I used the SOQL for ...
6
votes
1answer
91 views

iterator() on a set. Reason for it not being in the Apex Doc?

Although not documented as a set method, iterator() seems to work just fine on sets: set<String> strings = new set<String> {'a','b'}; system.debug(LoggingLevel.INFO,'next() on set ='+...
7
votes
1answer
11k views

Convert a Map Values to a List of values

How to convert Map to List, here is what I have tried but getting the error: List<Product2> productList = new List<Product2>(); productList.addAll(mapProducts.values()); Error: > ...
-3
votes
2answers
2k views

When should I use Maps and when should I use Lists in Apex? [closed]

I am bit up confused while selecting from Maps and List whilst working with Apex Triggers, can anyone please explain?
1
vote
1answer
156 views

How to compare values in Excel file before uploading?

Inserting excel file using apex, I have 4 columns in file,Column-1 (Name) can contain duplicate values. I want to perform check if column-1 has same values (for example A) and column-2(codes) has ...
-4
votes
1answer
991 views

Convert list<list<string>> to list<sobject>

I have a output JSON which has object rows in a variable called values. Ex: values=((01uo00000030BpcAAE, 01to0000001pRBx, 913840, test1, 100), (01uo00000030BphAAE, 01to0000001pRBx, 9137, ...
2
votes
2answers
6k views

How to check the map key value with field value?

I am trying to write condition in the class if "field1__c is not equal to map1 key value and field2__c is not equal to map1 key value " then it should throw an error. After assigning when I checked ...
2
votes
0answers
54 views

Lightning collection databinding is broken on Summer 16 [duplicate]

In Spring 16 I have used controls binded to collection values, and it's been working flawlessly until recent release <aura:component > <aura:handler name="init" value="{!this}" action="{!c....
0
votes
2answers
927 views

How to Remove duplicate records from two lists?

I have two lists mainGroupLinkerIPGlist and toCopy. i want to compare these two lists and remove the duplicates from them. for this i have created a set method and added both the lists to the ...
0
votes
1answer
397 views

how to use map/set for getting the value by the key name

I am not familiar with the data collections and want the solution. requirement is like: I want to have object name in the where statement for query like: select id , Name from Documents__c where ...
11
votes
2answers
3k 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 ...