+ Start a Discussion
jaxdmasterjaxdmaster 

SOQL

Hi all,

 

Why below statement is working.

 

Map<Id,Account> mp = new Map<Id,Account>([select name from Account]);

System.debug(mp);

 

I am not selecting Id although code work fine. How is it working?

bob_buzzardbob_buzzard

The id comes through automatically when you carry out a SOQL statement.  Took me by surprise the first time it happened too!

SFDC_LearnerSFDC_Learner

select name from Account is nothing but

Select Id,name from Account.

 

Because the Id will automatically comes with your selected field values.