Skip to main content
2 réponses
  1. 26 août, 07:07

    Hello @Hitesh Sharma

     

    Lists, Sets, and Maps are fundamental Apex collection types in Salesforce, differing primarily in how they organize, store, and retrieve data. 

     

    1. List (Ordered Shopping List) 

       What it is: A row of items kept in the exact order you put them in. You can have identical items twice. 

       Salesforce Use Case: Holding a batch of records straight out of a database query (like a list of 50 new Contacts) where sequence matters. 

    2. Set (Unique ID Bag) 

       What it is: A bag that holds items, but no duplicates are allowed. If you drop the same item in twice, it only stays once. 

       Salesforce Use Case: Collecting unique Account IDs from incoming records so you can search the database safely without running duplicate queries. 

    3. Map (Name-to-Phone Number Directory) 

       What it is: A pair system where a unique "Key" points to a specific "Value" (like a person's name linked to their phone number). 

       Salesforce Use Case: Matching a record ID (Key) directly to its parent Account or Contact record (Value) for instant lookup. 

     

    Best Practices 

    - No Queries in Loops: Never run database queries inside loops; fetch data into a List or Map first. 

    - Use Sets for IDs: Put record IDs into a Set when filtering via WHERE Id IN :mySet to keep code clean and fast. 

    - Pick the Right Tool: Use a List for order, a Set for uniqueness, and a Map when you need to find a record instantly by its ID

0/9000