Search code examples
cloudsalesforceapex-code

Standard Fields, How and If to access them?


I have couple of objects, In which i have defined a few custom field and one field as a standard field.

First, i will try to explain the reason why i have defined one field as a standard field.

The couple of object which i have defined represents the record and in my app if the record is already in the system i have to update its values. For every object i have been given a key like for eg for 'Contact' object i have been given 'Contact Email ' as a key. So, i have made the contact email as the standard field while the contact name as the custome field.

So, my question is,

1 : that does it even matters that if the key is custom or standard field ?

2 : Why there is no API name for standard field. how can one access standard field from apex code without it having the API name?

Also last but not the least

3 : what is the significance of having a key, i mean if a field is key then in what way is it seperate from other field .

Thanks


Solution

  • 1) Assuming you want your key to be unique, have you considered how you will handle this using a standard field? There is no out-of-the-box way to enforce uniqueness with a standard field. There is an Idea Exchange request for such a feature.

    That said, you can create a custom field that accepts the value from a standard field (via a workflow or trigger), and force the custom field to be unique.

    You can also just use a custom field and not use the equivelant standard field: per your example. you could easily create a custom field with the label "Email" and simply hide the standard Email field from the page layouts and/or profiles.

    2) Standard fields definitely have API names.

    3) Are you asking for the definition of a key field?