Yes, when it’s ajar… we all know it.
But what about these two snippets of code?
Account a = new Account( Name='Test1', Description='Door1' );
Account a = new Account( ); a.Name = 'Test2'; a.Description = 'Door2';
So, what about them? They seem the same – I mean they do the same thing I’ve just used a slightly different syntax, so what?
Well our friend SalesForce doesn’t see them as the same. And I’m sure that you already knew that… but I didn’t so I’m writing it down for posterities sake but that’s up to me.
Why then doesn’t SalesForce see them as being the same after all they do the same thing? Yes they do and you will get the same result from both of them. The difference comes about when SalesForce starts counting the number of script statements that you executed. The first constitutes one, whilst the second three. Obvious, I hear some say, who cares, I hear others say… and you’re right it is when you look at it. Yet at the same time it starts to make a bit of a mockery of the governor limits. My example is trivial but imagine setting ten fields on an object version one suddenly becomes 10 times more efficient in SalesForce’s eyes – stick that in a loop and you’re starting to look at big differences, yet you’re achieving the same outcome.
The example above isn’t the only place we’d see this effect: including methods as parameters to other methods, combining if statements, they’d all have the same effect.
It’s definitely nothing to lose sleep over and certainly not something that should be fixed. It’s more something to be aware of especially if you can see you code heading towards the script statements limit – just remember it’s more of a semi-colon count than anything else.
Pointless rant over.