Questions tagged [for]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
2 answers
174 views

What is the best way to replace the if true condition in LWC

I know that we can't write a specific condition in <template if:true={specificcondition}> LWC HTML file. However what is the best way to implement next HTML code : <template for:each={...
1 vote
1 answer
20 views

How to change the owner for dashboard and reports?

Some dashboards and reports not working after disabling the left employee login. So I want to assign a new owner to the existing dashboard and reports. Could you guide me how to change the owner name ...
-1 votes
1 answer
38 views

how to merge two For Loop

if(sObjectType == 'Order') { List<order__c> list_Order = new List<order__c>(); // todo=merge both the for Loop for(SObject obj : s_object){ order__c ...
0 votes
1 answer
49 views

How to populate records into specific wrapper structure?

There is an external system, from which I need to pull (via REST request) information about, let's say, brands and their categories. After the request, I need to collect the data in such structure: ...
1 vote
1 answer
49 views

Logic problem, it is possible? Add more quotelineitems if it has more than 1 on quantity

Hello Guys. My method does not work correctly. What it does is call another method inside a loop, the functionality is to take each quotelineitem from the quote until it finishes collecting all the ...
0 votes
0 answers
20 views

Add quotelineitem depending of quantity

Hello Guys. My method does not work correctly. What it does is call another method inside a loop, the functionality is to take each quotelineitem from the quote until it finishes collecting all the ...
0 votes
0 answers
51 views

Two level iteration not working in LWC

I have two level of iteration in LWC, and the second iteration is not displayed even if there are contents in it : <template for:each={calendarCol} for:item="ccd"> &...
  • 2,413
1 vote
2 answers
234 views

What is the difference between soql for loop vs soql list

As per the documentation it mentions ) (soql for loop) retrieves all sObjects using a call to query and queryMore whereas (list for loop) retrieves a number of objects records. It is advisable to use (...
  • 31
1 vote
2 answers
67 views

Why is the table generating too many rows (LWC)?

As you can see in .js, the table has only 1 row, but it is generating 5 rows... I don't understand why. .js file import { LightningElement,track } from 'lwc'; export class Table extends ...
  • 123
0 votes
1 answer
147 views

How could I avoid nested for each in a HTML (LWC component)?

I'm starting to create a modal like in this picture, but I only got it doing nested for each (line 42 and 43 of the .html) for the table. That's not good practice, right? So how could avoid it? I ...
  • 123
0 votes
0 answers
55 views

Refactor Nested For Loops Help

I am trying to unwind a multitude of nested loops and one of which that is causing CPU timeouts is the one listed below. I know I need to make a map outside of the loops and then call mapNameOfOldLoop....
  • 3,245
0 votes
1 answer
88 views

Javascript calculation returning incorrect value

In my excel sheet I'm using this formula =10615.30152 *(1+$B$9-$B$10)^L4 here $B$9= 2.75% and $B$10 = .20% and L4 changes for each row from 0 to 30 In my javascript I'm trying to calculate value like ...
  • 321
2 votes
1 answer
615 views

For Loop in Aura JS taking long time to Process

I have a Aura Component, inside which I'm doing some calculation inside for loop. In the for loop, I'm iterating around 3100 records, which is taking lot of time to process. Since the event on which ...
  • 321
0 votes
2 answers
247 views

Nested select record for each element in list

I have some List with values and i need to get record from sobject for each element from that list. So it looks like that. But its very close to limitations. Any ideas gow to do it? Its necessary to ...
0 votes
1 answer
25 views

Soql for list of id until result

So i have list id and query soql until I get the result. It looks like that, i want to query that soql for each id until i get result. It doesn't work good, but no error. FieldId__c is id from ...
1 vote
1 answer
3k views

LWC: Refresh for:each loops when new Array item added

I have 2 LWC components and loop through data in the following structure periods period.stages stage.details Within stage.details I render a table/form for each detail. After the table/form I have an ...
0 votes
1 answer
157 views

Loop must iterate over collection: Contact

I'm trying to executing this logic in my console. But getting an error. Please correct me List<Contact> conList = new List<Contact>(FirstName='Test', LastName = 'T', ...
  • 15
0 votes
1 answer
79 views

how to loop through a list of lists of different objects?

Let's say I have several different lists of objects: typeA[] Alist = [ ... ]; typeB[] Blist = [ ... ]; typeC[] Clist = [ ... ]; And I want to perform the same operation on each list: for (List<...
  • 327
0 votes
0 answers
80 views

Create a dynamic query for each item in for loop

Hi I want to create a dynamic query for each item in for loop , but again I don't want to execute that query in the for loop, right now since I am creating a query in for loop, I am no option but ...
  • 135
0 votes
0 answers
57 views

Why I cannot update the Account ID on this for loop?

for (Account acc : newAcc_lst) { System.debug('to15format Test 1-> ' + acc.id); Id to15convertString = acc.id; System.debug('to15format Test 2-> ' + to15convertString); String ...
  • 185
0 votes
2 answers
177 views

Update both Pricebook2 and PricebookEntry objects using just one for loop

Having the next code: for (WrapperTest pb : pbs_lst) { Pricebook2 newPB2 = new Pricebook2(); PricebookEntry newPBE = ...
  • 185
1 vote
1 answer
258 views

Can we use custom settings in SOQL queries?

I need to use run a query based on the value in custom settings. Delete_Lookup__c is my custom settings. I need to change the output of query based on the values in custom settings. global class ...
0 votes
1 answer
56 views

For loop inside For

I want to avoid this For loop inside another For... Is there any way for my situation? public class ManagerAccountTeamMember { public static Boolean isFirstTimeBEFORE = true; public static ...
  • 123
0 votes
1 answer
90 views

SOQL to be outside of for loop [duplicate]

I am new to Apex and I am trying to make SOQL to be outside of FOR Loops but then my trigger stopped working. Here is my code: trigger AccountFieldUpdate on Contract (after insert, after update) { ...
  • 5
0 votes
2 answers
93 views

CPU limit exceedance due to too many for-loops

I try to recreate the 7 Level deep Account hierarchy in my code. The code is working fine except that if the hierarchy in a real life example is too large, I get a CPU timeout error. I assume the ...
2 votes
1 answer
1k views

How to avoid nested for loop condition for code Optimization?

public void execute(Database.BatchableContext BC, List<FinServ__FinancialAccount__c> scope) { Set<String> Acc_Numbers = new Set<String>(); Map<String,List<Id>...
  • 23
4 votes
2 answers
252 views

If I Use a Loan Pattern is Salesforce smart enough to do a SOQL for loop?

As we know, Salesforce does some magic when you do something like: for (List<Account> accountList: [SELECT Id, Name FROM Account WHERE Name LIKE 'Acme%']) { // do stuff } ... such that the ...
-2 votes
2 answers
217 views

How to relate a Case with a Contract using Apex? [duplicate]

Use case : Once contract is inserted with : record type = B2C AccountId = Case.AccountId ContactId = Case.ContactId GEG_Correspondance_Offre_Produit__r.Type_Energie__c = Case....
  • 29
0 votes
1 answer
209 views

pass index of for:index value to js

I want to get the value of each tile href value using a function getHref is there a way wherein I can pass the index value to my js as part of getHref parameter. <template for:each={...
  • 1
0 votes
0 answers
31 views

Compare two Set <String> and return list<String> that does'nt exist in Set2 [duplicate]

I am getting the desired result, but I want to avoid the nested FOR in my code. However my attempt failed. This is the best I could do. Can someone please guide me how I can avoid the nested FOR? // ...
0 votes
1 answer
5k views

Get value of lightning-input and lightning-combobox from for loop in LWC

I am displaying data in LWC from an array in a for loop. The loop is using both lightning-input and lightning-combobox for inputs. <template for:each={tobeOppProduct} for:item="data"> ...
2 votes
1 answer
5k views

LWC - Multiple table rows for each iteration in for:each - where do I put the key?

I am converting an Aura component to LWC, and have hit one issue. In the Aura component two table rows are created for each iteration. However, in the LWC, I cannot create two rows for each iteration, ...
  • 628
1 vote
1 answer
246 views

Nested array/for loop

The code below is working so far. Now I added two fields to the visualforce page (selected_year_1 selected_year_2) where the user can select a year (2016/2017/2018...) for both fields. This years ...
's user avatar
-2 votes
2 answers
34 views

How do I test the FOR loop data for this code?

I have written a test class for a class and its coverage is above 75% but I want to increase it and found that a particular for loop is not being covered(written Between ** below). Please help me with ...
  • 19
-1 votes
1 answer
93 views

writing a program for Transferring ownership owner to owner for all objects

I'm writing a program for transferring ownership dynamically. But It has to work for all objects. Public Class TransferOwnership{ @AuraEnabled public static string tranferRecordOwnership(String obj,...
0 votes
1 answer
190 views

No SOQL in for loop

Re-factoring this below code to avoid SOQL in for loop. In this case below soql is for different object than the object passed in param. The solution I am trying needs for loop inside for loop, wonder ...
0 votes
1 answer
715 views

Values in map overwritten by new ones

I have a Map where I put a String and a Decimal. Both of these fields are updated based on the day of the week. The String field can be converted into a date field since it's populated by the day, ...
  • 223
0 votes
1 answer
164 views

Getting Values Outside a For Loop

I am really struggling with getting some values I need outside a for loop. public class Zenefits_Time_Off implements Schedulable, Database.AllowsCallouts { public void execute(...
0 votes
2 answers
4k views

How to iterate over Map with same key, but different values?

I have this map: for(Opportunity opp: [Select Id, AccountId From Opportunity Where Id IN :SetIds]){ mapAcctOpp.put(opp.AccountId, opp.Id); } When I try to iterate over this map like this: ...
0 votes
1 answer
539 views

AmpScript lookup function: Display data from multiple columns in a data extension?

I'm creating an email to display subscriber's order details. All the data is stored in one spreadsheet/data extension. The columns include OrderID1, OrderType1, OrderID2, OrderType2, OrderID3, ...
0 votes
1 answer
962 views

AMPScript For Loop Dynamic Variable

I am trying to get a dynamic variable set inside a script block with AMPScript. Here is what I got: FOR @i = 1 to 5 DO TreatAsContent( Concat( "SET @Test", @i, " = ", 'some value' ) ) NEXT @id ...
  • 31
2 votes
2 answers
1k views

Complicated FOR loop nesting. Having trouble cleaning up legacy code

I am trying to tidy up some really bad legacy code from an old developer and I'm trying to get rid of these nested for loops. The code below shows what I'm currently working with. I've fixed this ...
  • 303
-1 votes
1 answer
72 views

For loop isnot working as expected in Lightning [closed]

For loop is not executing properly for article Length 1 & 2. If Article Length 3 its failing. var article = response.getReturnValue(); alert('article lenght:'+article.length+'...
  • 2,264
1 vote
2 answers
204 views

Cannot move query outside of FOR loop?

REQUIREMENT: Need to move the query outside of the FOR loop in Opportunity trigger. PROBLEM: After moving query outside of the FOR loop, I receive an error when trying to save a new Opportunity ...
  • 303
0 votes
1 answer
2k views

Using Maps instead of nested for loops in APEX

Hi i'm really new to Salesforce development in the following code I'm trying update existing record to inactive but, not the coming record on two different conditions. I'm a bit confused in the last ...
3 votes
2 answers
951 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
1 answer
91 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=' + ...
  • 5
3 votes
2 answers
157 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 ...
0 votes
1 answer
195 views

Remove queries from For loop

I have a batch class global Database.queryLocator start(Database.BatchableContext bc){ return Database.getQueryLocator('Select Field1__c, Field_2 from Object1__c where Status__c in (\'New\', \'...
  • 1,123
0 votes
1 answer
5k 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 ...
  • 3,245