Salesforce Compound Field

Salesforce Compound Fields

Compound fields group together multiple elements of primitive data types, such as numbers or strings, to represent complex data types, such as a location or an address.

Address compound fields are accessible when API version v.30 and later, If you’re making an attempt to accessing the address field in your trigger or apex code check that the API version isn’t below v.30.

The list of available Address fields are,

  • Accuracy
  • City
  • Country
  • CountryCode
  • Latitude
  • Longitude
  • PostalCode
  • State
  • StateCode
  • Street

How to access each field in a compound field

public class mytest {public string vardata='ranbir';
public void hello(){
for(user userObjchamp : [Select id,address from User where id in : trigger.new])
{
Address addrObjchamp = (Address) userObjchamp.address;
if(addrObjchamp != null){
String city = addrObjchamp.city;
String street = addrObjchamp.street;
String state = addrObjchamp.state;
String postalcode = addrObjchamp.postalcode;
String country = addrObjchamp.country;
}
}
}
}

Consideration

  • Compound fields are read-only
  • Compound fields are accessible only through the SOAP and REST APIs. The compound versions of fields aren’t accessible anywhere in the Salesforce user interface.
  • You can’t use compound fields in Visualforce — for example, in an <apex:outputField>. To access or update field values, use the individual field components.
  • Custom geolocation and location fields on standard addresses aren’t supported with email templates.
  • You can’t use compound fields in lookup filters, except to filter distances that are within or not within given ranges. You can use distance lookup filters only in the Metadata API.
  • The only formula functions that you can use with compound fields are ISBLANK, ISCHANGED, and ISNULL. You can’t use BLANKVALUE, CASE, NULLVALUE, PRIORVALUE, or the equality and comparison operators with compound fields.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ranbir Kumar Das

Ranbir Kumar Das

260 Followers

I M Believer, Helper, Chaser, Thinker, Rich, Explorer, Prayer, Boss, Freedom, Fearless, Investor, Faith, Creator, trillionaire, CSM, Salesforce certified