function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rajendra Prasad 44Rajendra Prasad 44 

Sobject doubt

I am confused by fallowing Sobject statement 
'Account a = (Account)s' .  Could you explain it? 
Ajay K DubediAjay K Dubedi
Hi Rajendra,
'Account a = (Account)s' in this line 's' is a variable which might hold the Account information and you are typecasting it to Account type.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Ajay Dubedi
Ravi Dutt SharmaRavi Dutt Sharma
Think of 's' as on object which is returned by another method. Now 's' can be anything. It can be an Account, a contact or any other sObject. As a caller, I know that the retunred 's' will always be an Account. But the method who is returning it, that method might be returning it as a generic sObject. To store this generic sObject in a variable of type Account, you need to first type cast it into Account. 

As a caller, if you know that 's' will be an Account, you will typecast it as below:
Account acc = (Account)s;

As a caller, if you know that 's' will be a Contact, you will typecast it as below:
Contact con = (Contact) con;