Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [for]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
33 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
33 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
44 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
46 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
107 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 ...
1
vote
2answers
879 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
65 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
84 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
395 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
282 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
67 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
59 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
50 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
1k 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
117 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
2k 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
201 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
190 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
214 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
610 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
97 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 ...
0
votes
1answer
348 views

how can i revise this to avoid nested for loops?

for(String name : nameList ){ for(WrapperClass wrap : WrapListRun){ if(name == wrap.acc.Name){ accountWrapperList.add(wrap); } else if(name == wrap.con.Account....
-5
votes
2answers
349 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
867 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
840 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
363 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
192 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
46 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
35 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 ...
3
votes
1answer
3k views

Formula filed to display image, works in classic not in lightning

The below formula displays green red or yellow in the field based on the calculation. It works fine in classic view but not in Lightning. I read that as of Winter 15 images were not supported in ...
0
votes
2answers
89 views

Need to remove SOQL inside for loop

Below is my code snippet.Need to remove SOQL from for loop. for(Invoice_CU__c inv:Trigger.new){ List<Exchange_Rate__c> abc = [SELECT Exchange_Rate_to_Euro__c FROM Exchange_Rate__c where ...
6
votes
2answers
422 views

How to perform Soql query outside for loop?

I am inserting the opportunity line item based on the values of custom object. I am able to achieve this if I add the soql query inside for loop.But that is not an optimized solution. Can anyone ...
0
votes
1answer
94 views

FOR UPDATE in a Subquery?

I am assigned a POC project to consciously attempt a record and its children from one block of code and the other block of code would try to see how an update on such locked records behave. I am fine ...
1
vote
2answers
750 views

Cannot populate field value on new record with trigger

I am trying to write a simple trigger that will populate field values on a newly created record. I'm using standard objects: Account and Opportunity I have two custom fields on the Account object ...
-1
votes
1answer
29 views

using for getting the count of ids [closed]

i have a requirement like this,in my working project, for (Sobject aggregrate: aggregratecountList) { totalCount = Integer.valueOf(aggregrate.get('ID')); break; } ...
1
vote
1answer
1k views

Error:Loop must iterate over a collection type: User

I am getting error saying'Loop must iterate over a collection type: User'.I am not able to find what actually error wants to say. List<User> listUserDeactivate = new List<User>(); Set<...
2
votes
1answer
63 views

For loop for Map giving me various errors

I am unable to get a for loop for Maps working, I am new at this if you could, I would greatly appreciate it. I am just trying to iterate the the Trigger.oldMap keys, and, everything I try gives me a ...
3
votes
0answers
338 views

Lightning Component for Visualforce issue for Guest User

In answer to this thread - Expose Lightning App via Sites (and embed via Canvas) - Doug has mentioned that there is bug for guest user when using LC4VF. "There is currently an issue (actively being ...
0
votes
1answer
30 views

Need design help - weservice Real Time import of data to Salesforce and export as excel

Need to build export to excel functionality on salesforce but the tricky and imoortant part is that data resides in some other cloud system not salesforce. I have nearly 1 Million records in the ...
4
votes
1answer
118 views

Apex aggregrateresult error

Any help why I'm unable to add this? List<AggregateResult> revenue = [select SUM(Daily__c) rev, Client__r.Name from Commissions__c]; Integer totalMonthlyRevenue = 0; for ( AggregateResult i :...
1
vote
1answer
358 views

Reduce SOQL Queries

For every Account in AccountList, I need to make 2 different callouts - when a contact exists and 2nd when no contact exists. How can I reduce the no of SOQL queries in the below code. for(Account ...