• Alan Mc Carthy
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi folks,
I am asking about the theory involved here. What is the real difference between inserting a list of SObjects, and inserting Sobjects individually? Surely as long as the same number of records is going into the database, the operations should consume the same resources. For some code to show what I mean:
// Good
List<Contact> myContacts = new List<Contact>();
for( Integer i = 0; i < 1000; i++) {
    Contact myContact = new Contact(LastName = 'John');
    myContacts.add(myContact);
insert myContacts;


// Bad
for( Integer i = 0; i < 1000; i++) {
    Contact myContact = new Contact(LastName = 'John');
    insert myContact;
So in the code the 'Good' example will avoid governer limits and the 'Bad' example will run into problems... but aside from the governer limits the database would end up identical in each example. So what exactly is going on here?

Thanks for you help!
 
Hey guys, I have a boolean variable called myBool. I want myBool to be true if conditions A, B and C are all met, and false otherwise. The easy way is to declare myBool and leave it null, create an if statement, and update the value of myBool to true or false based on the results of the if statement.

For the sake of prettier and less cumbersome code, I was wondering if there is a method you can call which acts like the Salesforce formula function 'AND'. The way AND works is that you give it some boolean arguments and if every argument evaluates to TRUE, then the whole AND function evaluates to TRUE. What is handy about this is that the arguments can be equations... so you could have something like : AND( 1 + 1 = 2, 2 + 2 = 4), and this would equal TRUE.

So is there a way to do this using Apex? The exact use case, if it helps to understand my question, is the following: I want to be able to write the following code: Boolean myBool = (equation). For equation I would like to insert a value on each side and see if they are the same (and the values could be any data type). If the values are the same, then myBool would be TRUE.

Any help would be greatly appreciated!
 
Hi folks,
I am asking about the theory involved here. What is the real difference between inserting a list of SObjects, and inserting Sobjects individually? Surely as long as the same number of records is going into the database, the operations should consume the same resources. For some code to show what I mean:
// Good
List<Contact> myContacts = new List<Contact>();
for( Integer i = 0; i < 1000; i++) {
    Contact myContact = new Contact(LastName = 'John');
    myContacts.add(myContact);
insert myContacts;


// Bad
for( Integer i = 0; i < 1000; i++) {
    Contact myContact = new Contact(LastName = 'John');
    insert myContact;
So in the code the 'Good' example will avoid governer limits and the 'Bad' example will run into problems... but aside from the governer limits the database would end up identical in each example. So what exactly is going on here?

Thanks for you help!
 
Hey guys, I have a boolean variable called myBool. I want myBool to be true if conditions A, B and C are all met, and false otherwise. The easy way is to declare myBool and leave it null, create an if statement, and update the value of myBool to true or false based on the results of the if statement.

For the sake of prettier and less cumbersome code, I was wondering if there is a method you can call which acts like the Salesforce formula function 'AND'. The way AND works is that you give it some boolean arguments and if every argument evaluates to TRUE, then the whole AND function evaluates to TRUE. What is handy about this is that the arguments can be equations... so you could have something like : AND( 1 + 1 = 2, 2 + 2 = 4), and this would equal TRUE.

So is there a way to do this using Apex? The exact use case, if it helps to understand my question, is the following: I want to be able to write the following code: Boolean myBool = (equation). For equation I would like to insert a value on each side and see if they are the same (and the values could be any data type). If the values are the same, then myBool would be TRUE.

Any help would be greatly appreciated!