Stack Exchange Network

Stack Exchange network consists of 175 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 [loop]

A loop is a sequence of instructions that is continually repeated until a certain condition is reached.

2
votes
1answer
46 views

Waiting for results from APEX call in a for loop

I need to load a number of records more than the 2000 default limit for an SOQL query, but I need to wait until all of them are loaded before moving on. To do this, I make a request to get the total ...
-1
votes
2answers
51 views

How to remove list elements without an additional for loop?

I need to remove from the following revenueList list all elements where newRevenueDate is NULL without any additional for loops. List<Revenue__c> revenueWithNoDateList = new List<Revenue__c&...
1
vote
2answers
52 views

How can I efficiently loop through opportunities on a list of accounts?

Currently we have a few nested for loops in our codebase that are doing what is mentioned in the question, but if we data load a large amount of records we run into CPU time errors. I am wanting to ...
0
votes
1answer
37 views

How to Loop through a map that contains multiple object IDs?

Must be really simple but I am struggling with how to loop through this map. Gone through some examples but was unable to figure it out. Question is, how to loop through user IDs from TargetActorMap ...
0
votes
2answers
39 views

Lightning Event in Looping [closed]

I know it's a strange question to ask without context but what would be the implications if I have a lightning component firing an 'COMPONENT' type event every 1 second? I imagine it would be quite ...
2
votes
0answers
59 views

GTL Json data looping

I have a GTL code that loops through my JSON code. In the JSON string i have several order data but in each array there is the same adress information like so: [{ "name":"This is a name", "sku":"8547"...
1
vote
2answers
37 views

Unique Values in Ampscript Loop

Is there a way to do a Loop where it only Loops through Unique values? Customer | Store John | 111 John | 123 John | 111 John | 100 Right now I have a basic loop where it matches on ...
1
vote
2answers
173 views

Are objects from For Loops passed by reference or value?

If I have a for loop that loops through results from a database query, is the single record a reference or copied value? The reason I ask is because I am attempting to update these records, but would ...
0
votes
0answers
35 views

Populate date fields on multiple records using a formula?

So we have a custom object called 'Sessions' (child). Sessions are automatically created via a trigger for a 'Course' (parent). Now depending on the value of the 'Level' field (on the Course) object, ...
0
votes
1answer
60 views

GTL counting Json string

I have set up a GTL and AMP script that looks at my attributes where i passed in a Json string (array). This is the string: `[{"MiddleName":"der","LastName":"Test"},{"MiddleName":"van der","LastName"...
0
votes
2answers
32 views

SOQL Query Causing For Loop to Not Function

pretty simple question that I just can't figure. The first snippet updates a record just fine, but the second snippet does nothing, even though it compiles just fine. Many thanks. Why does this work: ...
2
votes
1answer
46 views

Too many SOQL queries - wanting to store in a map and check

I need to maintain a record for each month up to 10 years away, so 120 records ahead. This might be extended in the future! The code global with sharing class AccountingPeriodCreationService { ...
2
votes
1answer
175 views

Best practice using Schema.SObjectType

Wants to know please, 1) Why using the Schema.SObjectType is better than using a SOQL? 2) If using the Schema.SObjectType inside a for loop is a bad Idea... for example: Id devRecordTypeId = Schema....
0
votes
1answer
141 views

Saving data from HTTP response in a 'for' loop

Background: We're building an app, that will be periodically calling out to external web service to retrieve data in XML which we need to parse and save to Salesforce. So far: We have an Apex Job ...
0
votes
2answers
44 views

Add second element of map (multiple same ID)

I wanted to know how to get the second element of my oppTeamMemberWrapper map knowing that its ID exists in several times in the wrapper map (the ID being the ID of the parent opportunity)
0
votes
1answer
18 views

Trigger - Get all occurence of map in same get

I have a map map like that and I wanted to know if I could get all the occurrences of my key in one and the same list (without making a loop). Would you be able to do that? @future public static ...
0
votes
2answers
23 views

Apex output only showing id how to show all data in list?

I am trying to display data that is being return by an API. On my system.debug I can see the data is there but on displaying on the page it only shows an array of the ids of the list object. This is ...
0
votes
1answer
33 views

How to pass query variable from soql into loop

I am trying to bulkify a callout where I want to pass the recordtype in my loop but I get: Error: Variable does not exist: RecordType If I try public RecordType personAccountRecordType I get ...
0
votes
1answer
38 views

Sum up values(currency) from the list

Decimal totalReceived = 0.00; List<Money_Received__c> moneyReceived = [Select Amount_Received__c,Reservation__r.Total_Recieved__c from Money_Received__c where Id =: reservationId]; for(...
0
votes
2answers
23 views

Is it possible to loop through user input in a visual flow?

So if I have a textbox where the user can input account number (ex. 123,456,789), can I get the flow to separate the input by comma and find those accounts and update them? If so, can someone help me ...
2
votes
2answers
78 views

Nested for loop comparing two different lists and update

In the following nested for loop in getting duplicate id error. I think it's looping more than once and adding records again. Anyone please suggest something to enhance this code to avoid over looping ...
0
votes
1answer
31 views

How to reassign an object to the user with Role 'X'?

We have a few users with Role 'X'. We need to reassign an object to one from these users, if it's created not by one of them. But my loop choose the last one and change owner even if owner is already ...
0
votes
1answer
12 views

How to update contact fields related to a campaing

I want to update a field on the related contacts of a campaign with a field of the related campaign when the campaing is updated. I can get the contactid trough CampaignMembers but how do I get the ...
0
votes
2answers
28 views

Creating a trigger, that loops through auto number field, checks date and updates specific field to expired

I have an object named EXAM, exams have a unique Autonumber ID that starts from 0 and goes up to 10000. But this auto number is recorded as a TEXT by default. I want to create a loop, that goes in to ...
1
vote
2answers
32 views

Looping through all entries using a Primary_key, Validating and Updating the corresponding field Values

Exam is an object. It contains the following fields - exam_name(String), exam_state(picklist), exam_date(date), expiration_date(date) 'exam_name' is an AutoNumber(string) field (starts from 1 and ...
0
votes
3answers
36 views

Filter duplicates from List Query

I am trying to filter the duplicate based on a custom field. Its working fine but it is filtering only one duplicate. if there are 3 records, its showing 2 records. The below is my code. List < ...
0
votes
1answer
36 views

Generate Dynamic Query without Nested Loop

The requirement is to store object name and field name in the custom object so user can defined object and condition to display survey question. I am developing skeleton code to support the ...
0
votes
1answer
68 views

Get Set and Process in Loop

This line works: Set<Id> ids = (new Map<Id, Contact>([SELECT Id FROM Contact WHERE RecordType.DeveloperName = 'recordTypeName'])).keySet(); This line works: ws_contact.future_callout(...
1
vote
2answers
97 views

Why is my flag not working on maximum trigger depth exceeded

I have written a trigger for purchases if the purchase contains several of the same purchase detail items they should be summed up and merged as 1 purchase detail. When I use a before insert I get in ...
2
votes
1answer
33 views

Counter only adds first opportunity id

I have a testclass in which I create serveral opportunities with several values when I system debug these the values are as espected. I use a counter to add the ids from the several opportunities to ...
0
votes
1answer
37 views

How to Execute Function after For Loop? - Console Tabs

I am passing primary tab ids iteratively into a function to get the sub tub ids of each primary tab. At the end of this function I have a list of all primary and sub tabs open. How can I iteratively ...
0
votes
1answer
62 views

How can I avoid nested for loop in the below code?

Can anyone help on avoiding nested for loop in the below code: List<Account> leadAccountIds=[Select Id, OwnerId, Name FROM Account WHERE Name LIKE :Liktr]; System.debug('leadAccountIds=' + ...
0
votes
1answer
137 views

Salesforce Flow - Identify Latest Task based on Custom Date Field

I have an existing Task flow that I am looking to modify. The current flow as designed takes in the current Task record that is created under an Account, iterates through a loop, then ticks off a ...
1
vote
2answers
48 views

Differentiate loop on odd/even iteration

I am trying to set a loop organizing the result in 2 columns. However, since the @cnt variables cannot be re-set, I am quite stacked. Scenario: from a field in DE containing XML, I am extracting the ...
1
vote
1answer
74 views

Traverse a Relationship of Unknown Depth

Update: Okay so this was marked as a duplicate, which I can appreciate, because it is similar to the question posed here: Get 10+ Level Hierarchy Relationship - however, I believe mine differs ...
0
votes
0answers
46 views

List doesn't get populated in the for loop

Whole of my code works perfectly, except for this part Inside of the for loop, where the system.debugs are, the system debugs don't leave any type of message on the debug log. The "anorder.id" comes ...
0
votes
1answer
41 views

ClaimRow in a For loop

I want to give out more than one code in an email based on a number field in a DE. Currently, I'm using a for loop that goes from 1 to that number field, I have the claimrow within the loop, but for ...
1
vote
1answer
482 views

How to move my SOQL query outside for loop?

Hello I need some help moving my SOQL Query outside of my for loop to maintain best practices. I am using the code below to get the most recent opportunity of a selected account and grabbing the ...
0
votes
2answers
103 views

Ampscript won't let me set Field() in a For loop

I'm using the following bit of code to create a series of data extensions. I'm trying to create the name from a concatenation of Job_Ref and Creative_Name from a reference database. %%[ /*Using ...
0
votes
1answer
229 views

Compare Value of One Map with Key of Another Map to create new Map?

I have two maps, and am currently using a nested for loop to compare the keys of one map with the values of the other, and then placing the matching info into a new map. Is there a more efficient way ...
1
vote
1answer
30 views

Why doesn't my code enter for loop when record found?

I have an object(Huishouden__c) with a related list. I loop trough the object records with a for loop on the related record. When I debug the object in the first loop I get an Id but it does not enter ...
3
votes
2answers
55 views

Is it possible to extract the SOQL from a SOQL for Loop without loosing any advantages of using a SOQL for Loop?

The Apex Developer Guide compares SOQL for Loops against Standard SOQL Queries, and highlights certain potential advantages that developers may need or want to leverage. But putting the SOQL directly ...
1
vote
2answers
277 views

How to get first index nr/record in child loop

I have some related records to a parent record. I want to loop trough the child records and set a checkbox on the first record/index to true and all the other records to false. How do I achieve this? ...
0
votes
1answer
70 views

How to update checkbox bases on values childobject

I have this batchclass where I update a checkbox on account based on related assets. How do I set the checkbox to true If 1 of the assets is true and to false if all assets are false. I would have to ...
0
votes
0answers
27 views

Avoid loop inside loop when using multiselect value as map key

Have anyone face any issue when try to make multiselect as key before ? How to avoid for inside for for the case below? Here the snippet: for(WorkSupport__c support :[select TypeSupport__c, ...
1
vote
2answers
76 views

count number of cases in a consecutive date range

I have a requirement to keep a count of previous cases that were closed consecutively within 24hr periods on the latest closed case pseudo logic would be something like this: trigger when case is ...
0
votes
1answer
170 views

How to use Loop and Assign in Flows to clone permission sets?

I have been working on a project to clone an existing user to create a new user. I need to be able to pull all the information from the existing user's record, including permission sets. I have a ...
0
votes
1answer
708 views

Nested For Loop and SOQL Best Practice

I am in need of looping through three Objects: Opportunity, OpportunityContactRoles, and a custom object we will call CR__c. My question is: is it better to write a Wrapper class for these three ...
5
votes
1answer
354 views

Apex - Getting list of dates in month - CPU timeout

I am getting a CPU timeout from my loop. I have checked the debug logs and my start and end dates have the correct dates in them. I have tried setting the condition to be dtoday.adddays(3) just as a ...
4
votes
1answer
2k views

Invalid loop variable type expected

I am working on a class that searches for public groups, matches them to an Account Id and then takes that data to create AccountShare records for manual sharing. I am creating a Map(String, List) ...