Questions tagged [list]

A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.

Filter by
Sorted by
Tagged with
32
votes
5answers
73k views

list.IsEmpty() vs list.Size() > 0 vs list != null

I want to check the list is empty or not if not proceed further. So, which is preferable in apex and what are the differences between them? if(myList.size() > 0) or if(!myList.isEmpty()) or ...
1
vote
1answer
581 views

How to sort a custom list of Notes and Attachments by LastModifiedDate

In my VF Page I have been asked to show a list of all the Notes and Attachments in one table, and sorted by the common LastModifiedDate ... So I have a wrapper class in my custom controller: public ...
3
votes
2answers
3k views

List Exception Duplicate id error

I get an error in my trigger when i tried to insert bulk data from data loader. Error is : ERROR: SubscriberUpdateTrigger: execution of AfterInsertcaused by: System.ListException: Duplicate id in ...
0
votes
1answer
40 views

List has no row exception: Queryerror

I have below line placed in controller that fires list has no row exception. I just need to show a custom message instead when the query returns no value. Apex code: Id CI=[select ...
1
vote
3answers
1k views

How To Group Records By Value In A Specific Field?

I have a List of records of type abc__c. abc__c is a custom object. The record has a field called code__c. What I am trying to accompolish is to group the records in the list based on the code__c. ...
11
votes
4answers
4k views

Best Approach/Way to Query Single SObject record

To query a single record we have below two approach : Approach 1. Assign record to a single Account variable as shown below: Account accountToGet = [SELECT Name From Account where name = '...
10
votes
4answers
6k views

Reverse list in Apex

Can you reverse a list of objects in Apex? In Java and C#, there is a method you can call to reverse a list but I don't see one for Apex...
6
votes
3answers
7k views

How can I add a new value to a picklist using APEX?

I have queries pulling all of the information correctly but what I can't seem to find was a way to add new options to a picklist using APEX. I currently have Package__c.Products__c.add(new Schema....
1
vote
0answers
66 views

how to avoid system.limitexception too many soql queries 101 in apex classes [closed]

when I am trying to deploy the component then I was getting this error like system.limitexception too many soql queries 101 how to avoid this? ====================================== /** * @...
0
votes
2answers
1k views

Unexpected token list? [duplicate]

Getting error with this code but I can't figure it out trigger LeadConvert on Lead (after insert) { list leadsToConvert = new list(); Database.LeadConvert lc; string convertedStatus = '';...
34
votes
2answers
6k views

When To Use Set vs. List In SOQL

I have always assumed that it is better to use a Set in my query filters instead of a List. For example: Set<Id> parentIds = generateParentIds(); List<Child__c> children = [SELECT Id FROM ...
11
votes
2answers
5k 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 ...
5
votes
4answers
4k views

Better way to use Map of List

I have a map of Id to List of Sobject. To update the map i use below code snippet for(SObject so : listSObject) { if(mapSO.get(so.ParentId) != NULL) mapSO.get(so.PartentId).add(so); ...
4
votes
0answers
2k views

Subscripting a list in VisualForce

I have a list of items, and I'd like to access the first item like below, but get an error when I compile: <apex:outputText value="{!items[0]}" /> Incorrect parameter type for subscript. ...
1
vote
4answers
2k views

Assign Account to Contact based on email domain

I'm writing a Trigger to assign an Account to a new Contact based on the email domain. I have two formula fields that strip everything but the domain (i.e. acme.com) so that I can match from the ...
1
vote
1answer
2k views

How to sort a wrapper class list which has a reference to another wrapper in it

I want to sort a wrapper class list which has a reference to another wrapper in it.I tried implementing Comparable interface for both of class but it is showing error One or more of the items in ...
15
votes
3answers
30k views

Best way to remove element from list or why they kept iterator without this option

I'm studing apex now and dont understand the situation with list and iterator. In java you cant delete in any way elements from list while iterating it. So therefore developers added iterator and also ...
11
votes
3answers
2k views

Lightning: dynamic index in aura attribute with type List

related post I am having the same issue. Trying to access array with dynamic index arrayList[index] (index from aura:iteration), but Salesforce doesn't support that. Does anyone know how to do this?...
9
votes
3answers
3k views

Is it possible to Upsert a List<SObject> with external ID specified

I'm getting an error when attempting to compile my Apex: Upsert requires a concrete SObject type In my code, I'm unable to create a concrete declaration for the container which I want to upsert. ...
6
votes
1answer
219 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 ...
6
votes
4answers
27k views

List.contains in not working

I have to get subset of users who do not have records in custom table last modified in last 15 minutes. Here is my code: string query = 'Select Id FROM MyCustomObject__c where LastModifiedDate > ' ...
3
votes
2answers
4k views

Collection of List<sObjects> keyed by sObject field

Is it possible to have a Map (or other collection) of sObjects list, keyed by one lookup field of the same sObject. Something like Maps of sObjects (below code doesn't works): Map<Id, List<...
2
votes
1answer
2k views

Help displaying aggregate results in footer of pageblock table

I am trying to create a Visualforce page to display a list of related records (lookup relationship) in a PageBlockTable. I would like to include a footer row that displays the sum of one of the ...
1
vote
1answer
1k views

Error:Loop must iterate over a collection type: User

I am getting error saying'Loop must iterate over a collection type: User'.I am not able to find what actually error wants to say. List<User> listUserDeactivate = new List<User>(); Set<...
14
votes
2answers
8k views

Performance: List.get(index) vs List[index]

I want to know which approach is better in Salesforce when getting element from list. Is this faster? myList.get(0); Or is this faster? myList[0]; Using large list which above statement is more ...
8
votes
5answers
29k views

(Lightning) How do I get the selected value from a Select dropdown list & send it to a method?

I'm trying to implement a single option select dropdown list for my component, and I've gotten as far as displaying the data members and the correct values for them. However, I can't find any example ...
7
votes
1answer
3k views

Assigning VF component attribute to a List controller class variable

I have a VF page using a standard controller, a component, and a custom controller for the component. I am trying to pass a list of sObjects from the standard controller to the component's custom ...
4
votes
3answers
6k views

List query results into a string

I have a requirement that I need to display all Account Team Members for a specific Account in a text field for reporting. using this post as a guide, I can a list of the results but I cannot figure ...
2
votes
1answer
166 views

How to Use Custom Subscriber Attributes in a Triggered Email

I am using a Microsite to hold a page which allows users to generate a PDF, and then either download it, view it, or email it to someone else. I have generated the PDF successfully, but I'm having ...
1
vote
3answers
4k views

Bulk Delete from All Subscribers List

I have 55,000 records I need to delete from the All Subscribers List. It seems like the only obvious way to do this is by selecting all and deleting page by page. I will appreciate pointers on a more ...
1
vote
1answer
207 views

How can we add a new action (like Edit & Delete) for each record on the standard list page (Salesforce Classic)

How can we add a new action (like Edit & Delete) for each record on the standard list page (Salesforce Classic)?
1
vote
1answer
193 views

Unexpected difference using List<sObject> vs using Set<sObject> [duplicate]

I have sets of objects CustomObjectA, CustomObjectB, CustomObjectC... that I need to pass to a method. I would like to put them in a Map of type Map< String, Set< sObject > >, but when I try, I ...
1
vote
1answer
2k views

Error in List View Unique Name when deploying to new org

I'm trying to create Ant tasks to make it easier to implement Continuous Integration in the company I work for, and I'm facing one annoying issue when trying to deploy the package to the new org. ...
1
vote
1answer
3k views

Adding to sub list/array within apex wrapper class

I am trying to figure out how to add to this wrapper class. public class Invoice { public String Type; public LineItem[] LineItems; public class LineItem { public String ItemCode; public ...
1
vote
2answers
790 views

Looping over a list of sObjects that has more than object type

I'm trying to access a field from a list of sObjects which holds 3 different objects types. List<SObject> data = new List<SObject>(); for (sObject li : data) { String sObjName = li....
1
vote
1answer
148 views

How can I update Child records from list of Parent Records in custom controller?

I have a custom controller with a list of parent records (opportunities) and a list of their child records (opportunitylineitems). I want to save both the parent fields and child fields with one ...
1
vote
1answer
66 views

Do Maps have an Reliable Relationship between keySet() order and values() order?

Let's say I have a map, for example: Map<SObjectField, SObjectField> valueByKeyMap Assuming neither the Map nor its contents are mutated by other activity in the system, can I rely on these ...
1
vote
1answer
109 views

Assign Set of Ids in map at one go

I have below piece of code where I want to traverse to details from the base query on master object. Apex code Map<Id,set<Id>> MapOfAcctListItem = new Map<Id,Set<Id>>(); for(...
0
votes
2answers
289 views

How to insert a data from the same inputfields into a custom object

I,m trying to save data into a custom object from a repeated form in visualforce page. This is the visualforce code. Can I do do this using array? or list? or map?.. any idea?.. <apex:form> <...
0
votes
1answer
715 views

SFMC user not added to All Subscriber List

my expecttaion was once i sended an email to a new subscriber he gets automatically added to the all Subscriber list. Emails are received. I now sended emails to new subscriber with Subscriber KEy ...
0
votes
1answer
54 views

Display Relationships Between Lists on Visualforce Page

I have a list of strings. I am using these strings to populate three other object lists by querying for this string. For every iteration I am adding the lists populated to a List of lists. Ex: ...
0
votes
1answer
27 views

Error trying to remove account from list

When I run the button this error appears: Cannot modify a collection while it is being iterated. public void removerConta() { List<ContaVinculada> listContasRemover = new List<...
0
votes
2answers
81 views

Value getting stored in a weird way in List<String>

I have this below method which returns unique values of Name. And this is used in VF page in a multiselect picklist. Set<String> uniqueCustomObjectSet = new Set<String>(); ...
0
votes
1answer
35 views

Sorting a List of different object Lists by datetime

I have a List<ListWrapper> comprised of List<Knowledge__kav> and List<Community_Event__c>. I would like to sort List<ListWrapper> by date but the two inner lists have different ...
0
votes
1answer
55 views

Apex repeat shows Ids instead of field values

I have below set in my controller where I am populating a formula text field values in a set of Compliance_Incident_abv__c. Unfortunately, in page it shows only the Ids and not the ...
0
votes
1answer
320 views

Get fieldnames from List

I have the next problem, when I get the output susc I get the next line: 12:59:48:144 USER_DEBUG [32]|DEBUG|Susc: DopplerListSubscriber__c:{Id=a0246000001nTMeAAM, Contact__c=00346000002O4YvAAK, ...
0
votes
1answer
1k views

Converting list of maps into list of lists

we are getting the list output values below ({1=huffs, 2=45}, {1=huffy, 2=49}, {1=huff, 2=44}, {}, {}) I want the output as below for example: ({huffs,45}, {huffy, 49}, {huff, 44}, {}, {}...
0
votes
2answers
419 views

Split fails in the trigger

My code in unable to split hyphen. PLease have a look to my statement if I am wrong here. trigger ACCOUNT_AFTER_INSUPD_NAME on Account (before insert , before update) { /*List<Account> acc = ...