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
kryan0618kryan0618 

Select Opportunity Contact Role Mailing State Code

Hi,

I am trying to modify APEX code which pulls Contact Mailing information because we have enabled the State/Country Picklist processing. I get an error message the Code field does not exist??

Example APEX code:
        List<OpportunityContactRole> ocrs = [select ContactId, Contact.AccountId, Contact.Email, Contact.Phone, Contact.Fax, Contact.MailingCity, Contact.MailingCountry, Contact.MailingPostalCode, Contact.MailingStateCode, Contact.MailingStreet, Contact.Name, Id, Role, Opportunity.AccountId, OpportunityId from OpportunityContactRole where opportunityId in :Oppties and role in ('Billing Contact','Shipping Contact')];

All documentation I see says I should be using 'MailingStateCode' to pull the data I want.

This is the error message I receive:
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger OpportunityBillingContactInfo caused an unexpected exception, contact your administrator: OpportunityBillingContactInfo: execution of BeforeUpdate caused by: System.QueryException: No such column 'MailingStateCode' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.: Class.opportunityHandler.opptyBillingContactInfoHandler: line 9, column 1

Thoughts??
 
doravmondoravmon
You should go to setup-Customize-then found your field there ~ usualy the field name is __c, like select ContactId__c,Contact.AccountId__c...... you can find all field name under Customize field ~

Let me know if you still have questions ~
kryan0618kryan0618
But it is not a custom field. It is a new standard field due to enabliing the State and Country Picklists. The documentation says the field on the Contact object should be 'MailingStateCode' to get to the two character values for State. However, I cannot seem to get to it via OpportunityContactRole.
doravmondoravmon
if you go to a contact page, there should have a little arrow on the right ~ click it, then click view field ~ maybe u can find ur field there~