Activity Forums Salesforce® Discussions What is the difference between Id(objString) and Id.valueOf(ObjString) in Salesforce?

  • Abhinav

    Member
    September 15, 2016 at 4:59 pm

    Hi Mohit,

    The first is casting. The second is calling a static method on the Id class.

    One major advantage of the former is that it is more null safe.

    Id idVal1 = (Id)null; // works
    Id idVal2 = Id.valueOf(null); // blows up

    First one is better.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos