Skip to main content

Questions tagged [loop]

A loop is a sequence of instructions that is continually repeated until a certain condition is reached.

Filter by
Sorted by
Tagged with
0 votes
1 answer
79 views

Nested for loops

I would like to associate all the contacts with name test in them to an account. trigger trg1 on Account(after insert){ List<Contact> conList = [Select Id,LastName from Contact where ...
zain ahmed's user avatar
0 votes
0 answers
1k views

Get the sum of a currency field of all related Opportunity childs and grandchilds using a flow

I just started my flow journey and I can't find a solution to my problem. I have two different opportunity types. In type A I want to display the sum of the Amount field of all the subordinate records ...
Chris St.'s user avatar
1 vote
1 answer
2k views

Issue with Loop and display of list Using Salesforce flow

I have the below salesforce flow: What the flow is trying to do: On the first screen get the Account name and account number If Acc number = 1 then assign acc values to a record variable ...
SfdcBat's user avatar
  • 4,839
1 vote
1 answer
63 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
494 views

CPU Time Limit Exceeded Trying to Email 2000 Contacts

I have a junction object called AccountContactRelation which is linked to both the Contact and Account objects. I am trying to sort through the accounts, and for each one, add all the related ...
Austin Kelly's user avatar
2 votes
1 answer
6k views

Can you iterate over object properties in LWC?

I know you can use the for:each directive to loop through Arrays, but is there some way to loop through an object's properties?
jbyrd's user avatar
  • 711
0 votes
1 answer
522 views

Date.addDays not working in a loop

I have this code that creates opportunities for every day given a period start and end date. However I see that the addDays is not working as the resulting value is the same as the start date. Why ...
Pauline's user avatar
  • 395
0 votes
0 answers
191 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,765
0 votes
1 answer
351 views

ContentBlockById and For Loop

I have a problem with this Loop because there are 8 rows in the DE and when I execute the code below, the preview only shows 6 content blocks. The last one it displays, also has a loop inside and ...
Constanza Sosa's user avatar
0 votes
1 answer
101 views

Given a date, return the ID of the record that is within the Start and End dates

Object Name: Dates__c Fields: Id, Start_date__c (date), End_date__c (date), Week__c (string) Objective: Given a Date e.g '2022-01-07' from an object table that has input as so... Id Start End Week # ...
Meriç Aşaner's user avatar
0 votes
2 answers
1k views

Why does my array not show up in the template for:each?

I am trying to get a value from a list of objects to show up on the html page using the for:each directive. I have a then method that dynamically builds an array of objects that holds an id number and ...
Benton's user avatar
  • 51
2 votes
0 answers
3k views

Cannot reference a field from currentItem in the new Collection Filter node

I am trying to update a field on the triggering object using a Flow. I have filtered my options using a Collection Filter and it returns a single item. When I then try to assign it, it displays as a ...
Sachin's user avatar
  • 21
0 votes
1 answer
2k views

Can I deep clone a record but set the ID?

I have two account records. I want to move all of the data from account #1 into account #2. Is it possible to do a deep clone and set the ID? Or would I have to loop through account #1 and pull the ...
Olivia's user avatar
  • 3,491
1 vote
1 answer
6k views

Apex - Loop Through List and Set of IDs

I have a set of IDs and a soql to get list of accounts for those IDs: Set<ID> setOfIDs = new Set<ID>{//AccountIDs}; List<CustomObj> lstCustObjDetails = [Select ID, Name, Record__c,...
Jenina's user avatar
  • 35
0 votes
1 answer
418 views

looping over dynamic soql of indeterminite dimensions

Hoping someone has a clever strategy for the following scenario - I have a dynamic soql query that when assembled could be either: soql = 'select id from a'; soql = 'select id, (select id from b) from ...
Pete's user avatar
  • 91
1 vote
2 answers
1k 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
  • 123
-2 votes
1 answer
209 views

Hi guys, can you please help me rewrite the nested loop from the end of the codes [closed]

//triggers rigger MaintenanceRequest on Case (after update) { MaintenanceRequestHelper.updateWorkOrders(Trigger.New); } public with sharing class MaintenanceRequestHelper { public static void ...
Hoang Bui's user avatar
0 votes
1 answer
92 views

Re-Parenting in a loop

I need to update another developer's code that is running up against the Apex CPU limit when dealing with a large number of accounts. The code itself fired on afterUpdate trigger on the Account ...
Slava's user avatar
  • 29
0 votes
1 answer
161 views

Two inner loop need to replace with map.can we? [closed]

I am new to coding.here i want to replace the two for loop using map.can we do it? ContentVersion versionIn = [ SELECT VersionData, VersionNumber, PathOnClient FROM ContentVersion WHERE ...
Basu's user avatar
  • 23
0 votes
2 answers
96 views

Need help moving SOQL out of the loop

Hello, I need move this query out of loop: List<Lead> dupeLeads = [SELECT Id, Email FROM Lead WHERE Id != :Ld.Id AND Email =: Ld.Email]; I'm testing various guides on "bulkifying ", ...
Alberto Jiménez Domínguez's user avatar
0 votes
0 answers
133 views

Attempt to de-reference a null object but no issues found in the class

I have a Class1 and then there is another Class1_Handle. The Class1 takes a list of OPP, then loops through that and sends Opportunity ID to the Hadelar 1 by 1. The Handler then does a bunch of stuff, ...
Simple Code's user avatar
0 votes
1 answer
171 views

How to Retrieve the table same as excel table into an email using ampscript?

How to output excel table as table into an email using amp script code? but each week the number of products I feature could change up or down, how could I build the email so that it can pull in each ...
Mahi's user avatar
  • 1
0 votes
1 answer
1k views

Variable does not exist error when trying to retrieve the value from the list

List<SBQQ__QuoteLineConsumptionRate__c> quoteLineConsumptionRates = [SELECT id, SBQQ__LowerBound__c, SBQQ__UpperBound__c, SBQQ__Price__c, SBQQ__QuoteLineConsumptionSchedule__r.SBQQ__QuoteLine__c,...
Rahul Allada's user avatar
0 votes
0 answers
29 views

Some one good in flow help me please, the decision element is always taking the default path [duplicate]

Lets say I have contact1 and contact2 who have picklist stages [ New, Open, Prepecting, Nurture] in a account. Account also have similar stages form picklist. I would like to align the furthest stage ...
tough's user avatar
  • 123
2 votes
1 answer
11k views

In a flow, collection variable contains what it is supposed to but skips decision outcome, how would you handle it?

"Open" Outcome conditions Does Require Record Changed to meet criteria: true {!contactsStageText} ([Open]) Contains Open Skipped this outcome because its conditions weren't met: EDIT: ...
tough's user avatar
  • 123
0 votes
1 answer
2k views

How to filter through a collection picklist in flow, just to get the desired value?

My collection picklist variable at the end may look like, (New,New,Open,Prospecting,Propecting,New,Nurture, Demo Booked, Opt-out, Opt-out) I need to get just one value from these which is the highest ...
tough's user avatar
  • 123
0 votes
2 answers
897 views

How to switch on RecordTypeId inside a loop?

Alternative Title : How to optimize grouping each SObject records by Recordtypes public static Id sgRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Singapore')....
compski's user avatar
  • 1,391
0 votes
0 answers
618 views

Opportunity Team and Opportunity Split from a Partner field in Opportunity. Which should be preserved even if the opportunity owner is changed

what I am trying to achieve is whenever a "Partner" field is changed, it should get reflected in Opportunity Team and Opportunity Split. Meaning that When a "Partner" field in ...
tough's user avatar
  • 123
0 votes
1 answer
81 views

Create a method that invert 2 elements in a List<Integer>, should return the list with the numbers inverted.(indexes + list are passed as paramethers)

The goal is to invert 2 elements of a List. Like if I have List<Integer> integers = new List<Integers>{1,2,3,4,5,6,7}; If I call this method: invert(List: integers, index1: 2, index2: 3); ...
Giosuè Zocco's user avatar
0 votes
2 answers
767 views

Null pointer exception inside for Loop

Here is the code: for(Requests curRequest : requestList){ if (curRequest.varSRProduct!= null ){ for(SObject so : curRequest.varSRProduct){ //code } } ...
Adarsh Srinivasan's user avatar
0 votes
2 answers
695 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
1k views

How to avoid for loop inside for loop in the below code

Claim and Review are two objects a claim can have number of Reviews and a Reviewer can have have multiple claims. My requirement is weekly send notifications to reviewers for their approval on claims. ...
pree_sfdc's user avatar
1 vote
1 answer
158 views

Three FOR loops in ampscript after reading from XML

I have an eReceipt issue. I am able to get the nested loop to work to display the promo amounts and descriptions when there is only one promo per item purchased. Where I am stuck is trying to add a ...
J. Smith's user avatar
-2 votes
1 answer
310 views

For loop should iterate twice with one value in apex code [closed]

here is my code. accountList[1].ParentId = accountList[0].Id; accountsToUpdate.add(accountList[1]); accountList[2].ParentId = accountList[0].Id; ...
user99349's user avatar
1 vote
1 answer
55 views

Search List for variable for comparison using contains

I am trying to find the Name variable in a list to use the contains() method to search for the Name of the Activity_Assignment__c but am getting an error: Method does not exist or incorrect signature: ...
ForrestFairway's user avatar
1 vote
2 answers
7k views

LWC: Can a "<template for:each=" be used with an inner "<template for:each=" where the inner for-each gets its value using the key from the outer?

I was looking to do the following and I'm not sure if it's possible in LWC. I have a list of records which I'd like to loop through in the UI. I also have a map of records where the key is the iD of ...
RedQueries's user avatar
0 votes
1 answer
36 views

Salesforce too many soql queries 101 whle inserting bulk data. I need to check if the contact is all ready present or not before inserting a new conta [closed]

public static void ContactFromAccount(List<Account> NewAccountList){ list<Contact> contactList = new list<contact>(); for(Account a : NewAccountList){ ...
SFNVOICE's user avatar
-4 votes
1 answer
40 views

Explain this code for me [closed]

DateTime earliestCreated = events[0].CreatedDate; for(integer i = 0; i < events.size(); i++) { if(events[i].CreatedDate < earliestCreated) index = i; ...
BookerTCooke's user avatar
0 votes
1 answer
4k views

dynamically created query in APEX and Update the Value

Dynamically created query in APEX and Update the Value. Trying to update field value by string objectName = 'Account'; list<sobject> recordsList; string condition = 'id IN:' + recId; ...
SFDC_Beginner's user avatar
7 votes
2 answers
2k views

FFLib Selectors with SOQL For Loops

I'm considering implementation of FFLib, or at least parts of it, throughout our enterprise. Right now I'm focusing on the Selector and Query classes to consolidate our SOQL into a Selector Layer. I'm ...
Morgan Marchese's user avatar
4 votes
2 answers
669 views

Javascript loop very inefficient......Why? [duplicate]

I am not a javascript expert but thought this was a slam dunk to code until I saw the results. I am looking for help to make this MUCH more efficient. I have a simple for-loop going over a list of ...
Tom Ansley's user avatar
0 votes
1 answer
708 views

How to draw fields of different types using for:each in LWC

I'm trying to draw a set of different fields (with type text, number, picklist and other) using for:each, but I get all identical fields (they differ only in names and labels). How can this be fixed? ...
Valentin Romanov's user avatar
0 votes
1 answer
449 views

AMPScript loop to concat only non empty fields in a row

I am trying to concat all the non empty field values from a row in my DE, into a single variable (each value in the concatenated string separated by a comma). The field names are: FIELD1, FIELD2 and ...
apples-oranges's user avatar
11 votes
1 answer
1k views

Comparing Apex Loops and why Iterators are dramatically slower than for loops?

I decided to use iterators to work with collections in a functional style at some point in development, but immediately noticed a CPU time performance drawdown. So I decided to do a simple performance ...
Oleh Berehovskyi's user avatar
0 votes
1 answer
483 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
  • 333
0 votes
1 answer
851 views

AMPscript LookUpOrderedRows and Loop: if statement to check all values of a field

I'm a real novice with AMPscript, and I have some that works for listing items on an order for one customer in one-to-many relationship. Now I have another challenge, and I need to add something to ...
kimchi's user avatar
  • 19
0 votes
0 answers
95 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
  • 365
1 vote
1 answer
834 views

Map has 2 of the same keys [closed]

I retrieved a list of records that have a lookup to a parent record with a unique id. Parent record --<Child Records. I have a map that has two of the same key in it. I'm not sure how to understand ...
thinker's user avatar
  • 1,482
1 vote
1 answer
55 views

Better Code for Comparing Multiple Opps and All Their Products?

Trying to compare all Opps and their OLIs to see if there are duplicates (Opps with certain data that is the same, and all OLIs have same product and quantity) and then mark them as potential ...
number41's user avatar
  • 980
0 votes
3 answers
713 views

avoid inner loops with map?

I'm trying getting used to not creating inner loops in apex. Assume i have a Parent object Account which has child object Contacts. On Contact object i have a picklist value, with values "abc&...
AndersenAnd's user avatar

1
2
3 4 5
7