🌐
Salesforce Developers
developer.salesforce.com › docs › atlas.en-us.apexcode.meta › apexcode › langCon_apex_collections_lists.htm
Lists | Apex Developer Guide | Salesforce Developers
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.
🌐
Decodeforce
decodeforce.com › blogs › apex-list-methods-and-examples
Salesforce apex list class and methods with practice examples
A comprehensive guide on apex list methods and how to use them for various list manipulation in salesforce with practice examples.
🌐
TutorialsPoint
tutorialspoint.com › apex › apex_collections.htm
Apex - Collections
// Define a new map Map<string, string> ProductCodeToProductName = new Map<string, string>(); // Insert a new key-value pair in the map where '1002' is key and 'Acetone' is value ProductCodeToProductName.put('1002', 'Acetone'); // Insert a new key-value pair in the map where '1003' is key and ...
🌐
SFDC Kid
sfdckid.com › 2019 › 04 › salesforce-apex-collection-list.html
APEX COLLECTION : List - SFDC Kid
Now let's cook this recipe with the help of an example : ... In the above example, we have created str list and findlist list. In str, we have defined string s1,s2,s3 then by using add method it adds s1,s2,s3. Then in the second list, we add str in second list findlist. Then by using get(1) method, it will get value inside 1 and store inside x and return finally x i.e. Ravi. That's it !! In this way, you can use the apex collection List.
🌐
SFDC Stop
sfdcstop.com › 2021 › 09 › list-data-structure-in-apex-apex-data.html
List Data Structure in Apex | Apex Data Structure Tutorials by SFDC Stop - SFDC Stop
List in apex can store elements of any data type. It can store: Integer, String, Boolean and any custom data type as well. For example: Account, Contact, Employee__c (Custom Object) etc.
🌐
Salesforcepoint
salesforcepoint.com › 2017 › 04 › salesforce-apex-collections-list-list.html
Salesforce Apex Collections: List & List Methods with Examples | Salesforce Lightning Web Components, Aura Components, Apex Triggers, Apex REST API Integration
Example : List<Integer> ages=new List<Integer>(); ages.add(10); ages.add(20); ages.add(20); System.debug(ages); // { 10,20,20} add(index,element) : This method is used to add new Element at the given index.
🌐
Sfdcmeet
sfdcmeet.com › development › apex-in-salesforce › list-in-apex-collections › list-examples-part1
List Examples Part1 – Salesforce CRM Online Training and Knowledge Sharing
List<String> names = new List<String>{'Sam','Ram','Ravi'}; 0 1 2 ——————————- | Sam | Ram | Ravi | ——————————- ... Examples : 1.
🌐
Code With Sally
codewithsally.com › home › blog archive › beginner’s guide to salesforce apex: an introduction to collections – lists, sets, and maps
Beginner’s Guide to Salesforce Apex: An Introduction to Collections - Lists, Sets, and Maps
March 20, 2024 - We talked about the two most common List methods, “add()” and “get()”, before. But there are plenty of other useful methods you can use with Lists! In this section, I’ll show you a few examples of these methods.
🌐
Salesforce
trailhead.salesforce.com › learn › apex basics for admins › use collections
Understanding Apex List Collections and Usage
There are different ways to declare lists in Apex. This example uses array notation in order to set the list size. This code declares a list of strings called groceries, and sets its size to 4 strings. The empty groceries list looks like this: An item’s sequential position is a number called its index. The index is how we reference items. You probably learned to count starting with the number one.
Find elsewhere
🌐
S2 Labs
s2-labs.com › home › lists in apex
Lists in Apex | Salesforce Developer Tutorials
August 6, 2025 - These elements can be any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. ... Suppose there is a list, (‘Violet’, ‘Indigo’, ‘Blue’, ‘Yellow’, ‘Red’, ‘Purple’).
Rating: 4.7 ​ - ​ 874 votes
🌐
Sfdcmeet
sfdcmeet.com › development › apex-in-salesforce › list-in-apex-collections
List in Apex Collections – Salesforce CRM Online Training and Knowledge Sharing
listNames.remove(1); //index always starts with zero System.debug('After an element in index 2 is removed : ' + listNames);
🌐
S2 Labs
s2-labs.com › home › lists initialization in apex
Lists Initialization in APEX | Salesforce Developer Tutorials
August 6, 2025 - The syntax for initializing a list in Apex involves specifying the type of the list and creating a new instance of it. Here is the basic syntax: ... This is the most common method to initialize a list. ... This method allows you to initialize and populate the list at the same time. ... You can initialize a list using another list. ... You can also use the `addAll` method to initialize a list with the values from another list.
Rating: 4.6 ​ - ​ 675 votes
🌐
GitHub
github.com › ChuckJonas › wtfapex
GitHub - ChuckJonas/wtfapex: A list of funny and tricky Apex examples
A list of funny and tricky Apex examples. Contribute to ChuckJonas/wtfapex development by creating an account on GitHub.
Starred by 126 users
Forked by 19 users
🌐
Sfdc99
sfdc99.com › home › data collections – lists, sets, and maps
Data collections – lists, sets, and maps - Salesforce coding lessons for the 99%
October 22, 2013 - Preface – This post is part of the Core Apex Tools series. Data collections are simply groupings of any data type. You’ll use data collections often because they go hand in hand with SOQL. Lists are the first and most important of the three data types: List peopleToSpam = [SELECT Id, Email ...
Top answer
1 of 2
3

Building an APEX List of Values with Cascading References

@Frank Schmitt was close in his solution with his query suggestion:

select "name" from (
  select * from dns_servers where id = :P5_NS_ID)
where "type" = :P5_REC_TYPE_ID

To get over the errors you encountered however requires a few reminders of the rules behind the type of Oracle APEX element you are trying to create, a LIST OF VALUES QUERY. Here's a screenshot of the Examples for query based LOVs posted in the Apex developer area:

Note that there needs to be TWO columns in the output of your query. The value in position 1 is the DISPLAY VALUE (what is shown in the selection dialogue that uses it.) And RETURN VALUE (what is actually returned as the input value to the page item that shows the options from the query.

You may also be having some difficulty with implementing the logic of cascading input parameters. Below is an example of how to figure it out.

Setting up the Example Schema, HR-EMP

Here are the table structures used in my example:

DEPT

CREATE TABLE  "DEPT" 
   (    "DEPTNO" NUMBER(2,0), 
        "DNAME" VARCHAR2(14), 
        "LOC" VARCHAR2(13), 
     PRIMARY KEY ("DEPTNO") ENABLE
   )
/

EMP

CREATE TABLE  "EMP" 
   (    "EMPNO" NUMBER(4,0) NOT NULL ENABLE, 
        "ENAME" VARCHAR2(10), 
        "JOB" VARCHAR2(9), 
        "MGR" NUMBER(4,0), 
        "HIREDATE" DATE, 
        "SAL" NUMBER(7,2), 
        "COMM" NUMBER(7,2), 
        "DEPTNO" NUMBER(2,0), 
         PRIMARY KEY ("EMPNO") ENABLE
   )
/

ALTER TABLE  "EMP" ADD FOREIGN KEY ("MGR")
    REFERENCES  "EMP" ("EMPNO") ENABLE
/
ALTER TABLE  "EMP" ADD FOREIGN KEY ("DEPTNO")
    REFERENCES  "DEPT" ("DEPTNO") ENABLE
/

This example will use three LOV queries:

  1. The first LOV Query is in page item: P3_FIRST_CHOICE is independent of any value. It offers the user a choice of DEPARTMENT values.

    SELECT DNAME || ', ' || LOC as d, DEPTNO as r
      FROM DEPT     
    
  2. The second LOV Query is in page item: P3_SECOND_CHOICE and relies on the input of the selection for P3_FIRST_CHOICE.

    SELECT distinct JOB d, JOB r
      FROM emp
     WHERE emp.deptno = :P3_FIRST_CHOICE
    

    This makes P3_SECOND_CHOICE the first CASCADING PARAMETER value, so the cascading LOV Parent Item is: P3_FIRST_CHOICE. For a given department the user may select a specific JOB.

    Notice that even if the return value is the same as the display, TWO columns are required in an LOV query output.

  3. The third LOV Query is in page item: P3_THIRD_CHOICE and relies on the input of the selections for: P3_FIRST_CHOICE and P3_SECOND_CHOICE.

    SELECT ENAME d, EMPNO r
      FROM emp
     WHERE DEPTNO = :P3_FIRST_CHOICE
       AND JOB = :P3_SECOND_CHOICE
    

    P3_THIRD_CHOICE has a CASCADING PARAMETER dependency and offers a selection of employee names who have records that match the selected DEPARTMENT and JOB values from the first two form selection items.

  4. There is an optional fourth query which populates a report on the EMPLOYEE that is selected from the third LOV selection list.

Your APEX form design may look something like this:

How to Get New Parameters From Cascading Form Input Items

This is the example query form:

Entry Selection for the FIRST CHOICE (Department):

Entry Selection for the SECOND CHOICE (Job):

Entry Selection for the THIRD CHOICE (Employee):

Final Output: Individual Query by Selected Employee

2 of 2
1

I'm not an APEX expert, but this query looks broken - you're returning a single column called server_name from your inner query, and you're trying to reference two columns called "name" and "type" in your outer query.

If your table dns_servers indeed contains columns called "name" and "id", I'd suggest returning all columns from the inner query:

  select "name" from (
    select * from dns_servers where id = :P5_NS_ID)
  where "type" = :P5_REC_TYPE_ID
🌐
TutorialsPoint
tutorialspoint.com › apex › apex_arrays.htm
Apex - Arrays
//Defining array String [] arrayOfProducts = new List<String>(); //Adding elements in Array arrayOfProducts.add('HCL'); arrayOfProducts.add('H2SO4'); arrayOfProducts.add('NACL'); arrayOfProducts.add('H2O'); arrayOfProducts.add('N2'); ...
🌐
GitHub
github.com › SalesforceSFDC › Apex
GitHub - SalesforceSFDC/Apex: Apex triggers, classes, web services,... · GitHub
The values for the set are passed in curly braces. Set<String> My_String = new Set<String>{'a', 'b', 'c'}; ... A map is a collection of key-value pairs where each unique key maps to a single value.
Starred by 117 users
Forked by 83 users
Languages   HTML 58.7% | Apex 35.5% | ObjectScript 4.3% | JavaScript 1.5%
🌐
Salesforcetrainingindia
salesforcetrainingindia.com › home › list class in salesforce apex
List Class in Salesforce Apex
October 1, 2024 - Lists in Apex are dynamic, meaning they can grow or shrink in size as elements are added or removed, making them highly flexible for various programming scenarios. This class provides a range of methods to manipulate and interact with the elements, such as adding, removing, and accessing elements by their position.