Questions tagged [for]
The for tag has no usage guidance.
56
questions
0
votes
1answer
56 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
49 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
90 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
232 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
109 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
27 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
250 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
126 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
42 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
28 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
145 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
132 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
684 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
191 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
466 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
980 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
66 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
123 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
933 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
524 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
75 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
76 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
118 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
300 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
4k 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
317 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
210 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
263 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
988 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
102 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
422 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
397 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
455 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
266 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
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 ...
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
91 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
564 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
114 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
926 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;
}
...