WebAs you learned in Apex Basics for Admins, a loop is a block of code that is repeated until a specified condition is met. Loops allow you to do a task over and over again. Apex has three types of loops. You’ve used the while and do … WebMay 8, 2024 · Map> accountMap = new Map> (); for (Account acc : [SELECT Name, Description FROM Account LIMIT 100]) { if (accountMap.containsKey (acc.Name)) { accountMap.get (acc.Name).add (acc); } else { accountMap.put (acc.Id, new List {acc}); } }
Use a For Loop to Iterate Through a List - Salesforce
WebMap resultMap = new Map (); // Iterate over all possible fields on the object to find the ones in the sObject passed in for (String fieldName : Utils.getSObjectFields (sObj.getSObjectType ()).keySet ()) { // Passed in object has the field try { resultMap.put (fieldName, String.valueOf (sObj.get (fieldName))); WebJul 11, 2024 · IF (taskWithSub.size ()>0) { //Iterate all activities with subIssue using for loop for (Task twh : taskWithSub) { if (mapname.get (twh.SubIssue__c) != null) { //code block //if twh.SubIssue__c contains value from mapname then //Subject_Details__c = //get the map key } } update taskWithSub; here update } apex map Share Improve this question pineapple saketini
Map Class Apex Reference Guide Salesforce Developers
WebMap () Creates a new instance of the Map class. T1 is the data type of the keys and T2 is the data type of the values. Signature public Map () Example Map m1 = new Map(); m1.put(1, 'First item'); m1.put(2, 'Second item'); Map (mapToCopy) WebSOQL for loops iterate over all of the sObject records returned by a SOQL query. The syntax of a SOQL for loop is either: for (variable : [soql_query]) { code_block } or for (variable_list : [soql_query]) { code_block } Both variable and variable_list must be of the same type as the sObjects that are returned by the soql_query. WebNov 4, 2024 · The Fix: Maps. Nearly any time we're iterating over two lists in nested for loops and making comparisons between every possible pair of values, which is exactly what we're doing here, we can eliminate the inner loop using a Map for significant performance and complexity gains. gyros thessalonikis