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
Beatriz MinguezBeatriz Minguez 

Contact.PostalCode

Regarding using SOQL to assign and retrieve attributes, I need identify the Postal Code of the Contact and I do not know how to name it?

Imagine I am having the following code:

Contact[] cts = [SELECT Contact.LastName, Contact.Postal_Code FROM Contact WHERE LastName =: sName OR PostalCode =: sPostalCode]; 
  
        System.debug('Last Name forund + cts[0].LastName);
        System.debug('PostalCode found' + cts[0].PostalCode);

The problem is that Contact.PostalCode can't be found and I do not know how to name it. 

Anyone can help me?

Thanks!

Bea
 
Best Answer chosen by Beatriz Minguez
logontokartiklogontokartik
Hello Bea,
The field name for the PostalCode is MailingPostalCode

So your SOQL will be
Contact[] cts = [SELECT LastName, MailingPostalCode FROM Contact WHERE LastName =: sName OR MailingPostalCode =: sPostalCode]; 
  
        System.debug('Last Name forund + cts[0].LastName);
        System.debug('PostalCode found' + cts[0].MailingPostalCode);
All the address fields on Contact start as Mailing, so its MailingStreet, MailingCity, MailingState, MailingCountry, MailingPostalCode

Thank you

 

All Answers

logontokartiklogontokartik
Hello Bea,
The field name for the PostalCode is MailingPostalCode

So your SOQL will be
Contact[] cts = [SELECT LastName, MailingPostalCode FROM Contact WHERE LastName =: sName OR MailingPostalCode =: sPostalCode]; 
  
        System.debug('Last Name forund + cts[0].LastName);
        System.debug('PostalCode found' + cts[0].MailingPostalCode);
All the address fields on Contact start as Mailing, so its MailingStreet, MailingCity, MailingState, MailingCountry, MailingPostalCode

Thank you

 
This was selected as the best answer
Beatriz MinguezBeatriz Minguez
Thank you!!!!

Is there any documentation where I can look for the name of the fields?
 
Carlos Campillo GallegoCarlos Campillo Gallego
Prashant MaxsteelPrashant Maxsteel
Thanks Carlos, that was really helpful.
Is there some place on Developer or something where I can check the current Object Fields and their Column level mappings?