Looking for Advice for a Dynamic Loop

Hi All,

I have a part of my application that requires me to create 105 blank records (each slightly different) that are then updated in a subsequent step.
For each weight (1-15) I need create a compliment of zones 2-8.

My logic above works, but I was wondering if there was a better way to do this instead of replicating things 105 times. I’m obviously looking into loops, but I’m unsure how to incorporate the logic I’m looking for into the blocks that I need.

As a side note (and anticipating the question of “why do it this way”) the “update” portion of the logic is as follows

The issue I run into is that the upsert doesn’t work if the where clauses that is finding my objectId returns null which is what I’m trying to work around.

In such a case I can give you some general advises, because the nuances of implementation depends on your inner app logic.

(1)
loop – is a preferable solution, you may nested loops if the amount of “variable” values more than one and they are depends one on another.

(2)

The issue I run into is that the upsert doesn’t work if the where clauses that is finding my objectId returns null

Is the “if” statement wouldn’t fit this logic? What I mean: if the request with where clause returns null – you just doesn’t do anything, or return empty collection. The Bulk Upsert shouldn’t fail in this case.

Thanks Oleg,

I’d appreciate it if you could point me to a few examples of leveraging a nested loop. More curious on which blocks make sense to use together.

WRT to the upsert, the where clause is returning a null objectId in some situations (when the object does not already exist). What I would prefer is that a new object is created when the where clause returns a null value. I’m going to play around with some other blocks to try to work this logic in, but I thought that this is what should be happening with upserts in general. Is there anything in my logic that appears off to you?

Aaron

I recommend using the CSV API service for this:

Generate a CSV document in your logic and use the service API to import the data.

Nested loop is one loop which is put into another one:
(Just for example)
image

It’s up to you, what fields and how you need to modify during iteration.
So on each iteration you create the object, modify its fields (some of them are formed based on iteration counter or another object), and put them to the collection.
The next step is you make an upsert with the collection of objects.