Questions tagged [for]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
28 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', ...
0
votes
1answer
29 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<...
0
votes
0answers
28 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 ...
0
votes
0answers
26 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 ...
0
votes
2answers
54 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 = ...
1
vote
1answer
37 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
1answer
48 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 ...
0
votes
1answer
63 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) { ...
0
votes
2answers
52 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
1answer
116 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>...
4
votes
2answers
235 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
2answers
121 views

Trigger After Insert - relate Case field with ContractId [duplicate]

Use case : Once contract is created with : record type = B2C AccountId = Case.AccountId ContactId = Case.ContactId GEG_Correspondance_Offre_Produit__r.Type_Energie__c = Case....
0
votes
1answer
34 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={...
0
votes
0answers
30 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
1answer
867 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"> ...
1
vote
1answer
682 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, ...
0
votes
0answers
15 views

How can I compare elements from a SOQL in a for loop?

I need to compare contract[0] from the same Account with the contract[1], if they have same values as in the specific fields that I'm using in SOQL I don't need to add it on my map.So if contract[1] ...
1
vote
1answer
62 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 ...
-2
votes
2answers
27 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 ...
-1
votes
1answer
32 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
1answer
150 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
1answer
295 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, ...
0
votes
1answer
37 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
2answers
1k 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
1answer
286 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
1answer
598 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 ...
2
votes
2answers
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 ...
-1
votes
1answer
67 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+'...
1
vote
2answers
153 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 ...
0
votes
1answer
1k 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 ...
2
votes
2answers
608 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
78 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=' + ...
3
votes
2answers
95 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
1answer
154 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\', \'...
0
votes
1answer
3k 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 ...
1
vote
1answer
397 views

Dynamic Fields in for Loop

Is there a way to dynamically change the fields within a for loop? As an example, if I have for loop: for(Account a: myQueryResult){ if(a.parentId = fieldVariable){ Do something ...
1
vote
1answer
5k views

System.assertEquals for records in a list? Test class

I have a batch class that inserts Journal records after updating Account records... I am new to apex and cannot think how to test the inserted records in the test class. I have a list to get the ...
0
votes
2answers
336 views

Test Class coverage for For loop

My Trigger trigger ProductDefinitionTrigger on Product_Definition_Detail__c (before insert) { Set<string> s = new Set<string>(); List<Product_Definition_Detail__c> lst = [select ...
0
votes
2answers
217 views

Marketing Cloud: Using AMP for to iterate through emails stored in a single string

I am new to AMP, and currently trying the following with for: set @len = indexOf ([listofemails],';') if @len > 0 then for @part = indexof([listofemails],';') to 0 do ...
0
votes
1answer
280 views

How to create report for Notes object content?

I have a requirement in which client needs monthly data of all the notes related to every lead . This result in huge data which I am doing manuallly now. I query data from workbench and prepare ...
0
votes
1answer
39 views

How to tell why a loop gets stuck?

I am trying to make email campaigns for two people both people need 6 buy campaigns and 6 sell campaigns. They have 5 parameters 3 of which are the same for all 12 of each person campaigns, the other ...
0
votes
3answers
1k views

Avoiding Apex CPU Time Limit Exceeded

I have read so many posts about maps today but I just can't seem to get them to apply to my use case. I have an object called transactions and each transaction is related to an account. I am trying to ...
0
votes
0answers
105 views

Apex heap size too large : Error for fieldset

I have to copy field values from Object Business_Plan_abv__c to Business_Plan_Approval_Process_Data_abv__c where API Names are exactly matching. For that I am using fieldset on Business_Plan_abv__c ...
-5
votes
2answers
409 views

code coverage for FOR loop in Test class

Unable to cover the code coverage from if condition inside for loop. public class cwrapper{ apply__c g = new apply__c(); selected = false; public cwrapper(apply__c a, boolean selected){ ...
0
votes
1answer
1k views

how to break loop from for and form a string value again?

I have map which size is 10.from the Map from each 3 keys i have to form a string. then the string is set to empty.from the next (3 to 6) map keys again i want to form a string. Please guide me Apex ...
0
votes
3answers
1k views

How to use Map instead of for loop?

We have a Case related to an Opportunity, and whenever a particular Case is created with any of 3 specific stages, it should send an email to the opportunity Account manager regarding the changes in ...
3
votes
2answers
488 views

Increment Array Position After Every Button Click

I have a tricky requirement that I am not sure is entirely possible. I have a custom "Skip" button on the Case page layout. This button allows you to skip to the next Case in an list, if the status ...
0
votes
2answers
306 views

Using FOR Loop to pull specific row and all subsequent rows from a lookup

I've been having some difficulty getting my loop to work properly and was hoping someone could take a look. The campaign is a recipient is assigned a tier (in this case 1-8), the audience data ...
-4
votes
1answer
47 views

how to split list into multiples of 10

for( MetadataService.Metadata metaDataService : createFieldList) { system.debug('metaDataService '+metaDataService ); createFieldArray[i] = metaDataService; i++; system.debug('...
0
votes
0answers
36 views

Comparing Object References In Trigger Exceeds CPU Limit

I have a trigger in which I want to cater for the requirement to compare records during a bulk insert or update. I want to make sure of the following: No 2 records in the bulk being inserted/updated ...