• Jason Voight
  • NEWBIE
  • 10 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
What is the best practice when initializing objects working with for loop, Is there advantages to Initalze outside the loop, oppose to Inside a loop or setting the Object as a variable and referenceing it inside the loop.A few examples.


 
//Example 1:

Account acc1 = new Account();
for (Integer i = 0, j = 0; i < 10; i++) { 
    acc1 accountToCreate =  createAccount(i);
}



//Example 2:

Account acc2;
for (Integer i = 0, j = 0; i < 10; i++) {
    acc2 accountToCreate =  createAccount(i);
    accsToInsert2.add(acc2);
}


//Example 3:

for (Integer i = 0, j = 0; i < 10; i++) {
    Account acc3 = new Account();
    acc3 accountToCreate =  createAccount();
}

​​​​​​​
Hello I was wondering what was the best way to create a map of 3 related objects. Eg. The grandchild looks up to the child, the child looks up to the parent. I know that you can use dot notation to get to the Parent from the grandchild, but was needing to go from the Top down. Would like to associate a key pair if possible
What is the best practice when initializing objects working with for loop, Is there advantages to Initalze outside the loop, oppose to Inside a loop or setting the Object as a variable and referenceing it inside the loop.A few examples.


 
//Example 1:

Account acc1 = new Account();
for (Integer i = 0, j = 0; i < 10; i++) { 
    acc1 accountToCreate =  createAccount(i);
}



//Example 2:

Account acc2;
for (Integer i = 0, j = 0; i < 10; i++) {
    acc2 accountToCreate =  createAccount(i);
    accsToInsert2.add(acc2);
}


//Example 3:

for (Integer i = 0, j = 0; i < 10; i++) {
    Account acc3 = new Account();
    acc3 accountToCreate =  createAccount();
}

​​​​​​​