You need to sign in to do that
Don't have an account?
Newbie10
Object declaration
Can somebody please explain what below code does
sobject s = new account();
Account a = (Account)s;
object obj = s;
a = (account)obj;
I am particularly interested in what happens at stack/heap when object obj = s happens.
i could see in developer console a [object Object] value for obj.But cannot figure what exactly happens internally or what is the purpose
Code source is Apex developer guide
Object is a completely generic type that can be anything (it doesn't have to be a SObject). For example you can assign an Integer or String to the "Object" type like so:
SObject has to be referencing a table that exists in Salesforce (or generic SObject which has get and put methods on it)
All Answers
You're just really casting the objects back and fourth... Some of this is based off assumption but I'm assuming the class hierachy would be something like this:
Object
SObject extends Object
Account extends SObject
Now to you're specific interest about what happens to the heap, nothing will happen. Like a lot of the other OOP languages, it is simply a memory pointer reference that you're assigning to different variables.
Try this code sample:
Based off the trace statements nothing happens to the heap...
H sean ,
What is the difference between object and sobject.
Thanks
Object is a completely generic type that can be anything (it doesn't have to be a SObject). For example you can assign an Integer or String to the "Object" type like so:
SObject has to be referencing a table that exists in Salesforce (or generic SObject which has get and put methods on it)
By table you mean Objects.Thans for the nice info
Thanks Sean
Just one more quick clarification
What is the difference between
Object obj = (Account)s; and
Object obj = s;