I am new to SOQL. How do I fetch the country,state,city of an account?
I have tried this but have an error.
Select AccountNumber,name, BillingAddress.City from Account
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI am new to SOQL. How do I fetch the country,state,city of an account?
I have tried this but have an error.
Select AccountNumber,name, BillingAddress.City from Account
Here you can found a list of all SOAP API fields accepted in Account (standard fields)
If you need the Billing Address fields you can use:
SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry FROM Account
or with ShippingAddress...
SELECT Id, Name, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry FROM Account
even you can retreive Longitude and Latitude from each one.
Good luck!
BillingCity
BillingCountry
BillingState
are the correct API Names
To check the object's field correct API Name use describe call in developer console and check all fields label Name and corresponding API Name in debug log
for(Schema.SobjectField strFld: Account.SobjectType.getDescribe().fields.getMap().Values())
{
system.debug('-----Label Name----'+strFld.getDescribe().getLabel()+'-------API Name--'+strFld.getDescribe().getName());
}
Select name, BillingCity, BillingCountry, BillingState from Account