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
Nitesh Acharya 19Nitesh Acharya 19 

Object Reference Issue

I have a contact Id as a String and I need to reference it to Contact Object without an SOQL query.
Is the below code a correct method?

String sId = '0037F00000YLe60';
Contact abc = new Contact(Id=sId);

I am facing issues, when I am using the above code in my scripts, it is giving me lot of reference issues. (field values do not come over as expected). Kindly advise.
 
Raj VakatiRaj Vakati
Your code will through an error when you are trying to refer the other fields  .. the reason is you instantiate the new reference for the contained object with below code just with ID and there is no other values are available .. 
Contact abc = new Contact(Id=sId);

then the only way to do it request and do it or if you have all the contact reference anywhere reuse it ..