Questions tagged [for]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
52 views

Return Entire Object from for:each Template in Lightning Web Component (LWC)

Is it possible to return an entire object (not just a single field) from a for:each Template in LWC? Specifically, I'm not sure why I can't access the object in the same way I can a normal object in ...
David Scott's user avatar
0 votes
2 answers
70 views

Can this nested loop be done through a map?

I have the following bit of code which is a nested loop that I'd like to know if it can be replicated by using a map instead as I haven't used them before and would like to know how it would end up ...
qnt13's user avatar
  • 3
1 vote
0 answers
82 views

Map<Id, List<String>> or Map<Id, List<SObject>>, how access values?

I need to have a Map<Id, List<String>> or a Map<Id, List<Custom_Object__c>> to store this data: Id = Id of the record that is above, List<String>/List<Custom_Object__c&...
Alexia's user avatar
  • 81
-3 votes
1 answer
122 views

How to prevent loop in batch correct way [duplicate]

I have the following Batch which currently runs. I am still wandering if the way I set my for loops are correct. Is this solution the right way? I have a Quote which is related by several amount ...
Thomas's user avatar
  • 2,294
2 votes
1 answer
320 views

loop over multiple items in a list? 'Duplicate Value Error'

I am looping over a list of records and trying to set a field on those records one by one (the field value will be different for each) but my loop keeps putting the same value for each record. List<...
potato46's user avatar
1 vote
1 answer
55 views

Only showing those that Return true from a FOR AmpScript

I am searching a data extension based on an ID and returning vairables and a link from those. I was able to get it to pull all the required data and show correctly. However when I try to add a ...
Connor Tom's user avatar
0 votes
0 answers
463 views

LWC - All items in the list renders again in HTML table (For : Each Iterative) even if particular list element belonging to particular ID got changed

LWC - All items in the list renders again in HTML table (For : Each Iterative) even if particular list element belonging to particular ID got changed. Please could someone let me know how to limit ...
Ashfaq Mohammed's user avatar
1 vote
2 answers
2k 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={...
user avatar
1 vote
1 answer
1k 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 ...
Arun Kani's user avatar
-1 votes
1 answer
116 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 ...
sunny roxx's user avatar
0 votes
1 answer
162 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: ...
Dmitriy Yurkin's user avatar
1 vote
1 answer
58 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 ...
Alex Barón's user avatar
0 votes
0 answers
126 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"> &...
vanessen's user avatar
  • 2,555
1 vote
2 answers
886 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 (...
Rose 's user avatar
  • 111
1 vote
2 answers
150 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 ...
Cline's user avatar
  • 143
0 votes
1 answer
289 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 ...
Cline's user avatar
  • 143
0 votes
1 answer
322 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 ...
sfdc's user avatar
  • 321
2 votes
1 answer
2k 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 ...
sfdc's user avatar
  • 321
0 votes
2 answers
551 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 ...
jeltaboknu's user avatar
0 votes
1 answer
82 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 ...
lopsigorze's user avatar
1 vote
1 answer
5k 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 ...
RedQueries's user avatar
0 votes
1 answer
373 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', ...
Raghu's user avatar
  • 15
0 votes
1 answer
309 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<...
Foo Bar's user avatar
  • 286
0 votes
0 answers
157 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 ...
Isha's user avatar
  • 163
0 votes
0 answers
82 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 ...
CPS's user avatar
  • 335
0 votes
2 answers
313 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 = ...
CPS's user avatar
  • 335
1 vote
1 answer
889 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 ...
ajith binny's user avatar
0 votes
1 answer
61 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 ...
Cline's user avatar
  • 143
0 votes
1 answer
161 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) { ...
Nomad's user avatar
  • 15
0 votes
2 answers
206 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 ...
Andrea Voggenreiter's user avatar
2 votes
1 answer
3k 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>...
Jay77's user avatar
  • 23
4 votes
2 answers
258 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 ...
Brian Kessler's user avatar
-2 votes
2 answers
365 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....
Farkous's user avatar
  • 27
0 votes
1 answer
561 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={...
Sam77's user avatar
  • 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? // ...
GroundToCloud's user avatar
0 votes
1 answer
8k 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"> ...
Tapas Mukherjee's user avatar
4 votes
1 answer
9k 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, ...
bpilling's user avatar
  • 670
1 vote
1 answer
439 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 ...
user avatar
-2 votes
2 answers
47 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 ...
Aditya's user avatar
  • 19
-1 votes
1 answer
187 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,...
Gangadhar's user avatar
0 votes
1 answer
246 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 ...
user1902124's user avatar
0 votes
1 answer
1k 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, ...
chloe's user avatar
  • 243
0 votes
1 answer
435 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(...
Kris Webster's user avatar
2 votes
2 answers
6k 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: ...
Austin Evans's user avatar
0 votes
1 answer
713 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, ...
AbraMagic's user avatar
0 votes
1 answer
1k 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 ...
Sascha's user avatar
  • 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 ...
paulK's user avatar
  • 323
-1 votes
1 answer
74 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+'...
Annappa's user avatar
  • 2,312
1 vote
2 answers
232 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 ...
paulK's user avatar
  • 323
1 vote
1 answer
3k 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 ...
Mohammed Imran's user avatar