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
salmanmanekiasalmanmanekia 

Standard Fields, How and If to access them ?? {Disclaimer: NEWBIE}

Hi,

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

 

sfdcfoxsfdcfox

A standard field is one defined by the system. You cannot, by definition, create a standard field. A custom field is one that you have created, the opposite of a standard field. It appears you are throuoghly confused, because your questions don't exactly make sense, but I'm going to try to help out:

 

1) The only "key" is the ID field. Any time you are trying to insert or update a record, you'll use its ID field. That said, you can use External ID fields, which are indexed and can help you find existing records when using foreign relationships.

2) There is an API name for all fields. Sometimes it is not plainly obvious, in which case you should look at the Enterprise WSDL (Setup > App Setup > Develop > API). You are assured that Id will always exist, as every record has an ID, and that the ID will necessarily be unique.

3) A field which is a key is blessed with an index. This means it queries faster than a normal field, and can avoid "non-selective query" errors by leveraging indexes. Other than that, it behaves as a normal field; it holds the same types of data and has the same properties as a normal field.

 

I don't believe I've answered your questions, but hopefully what I've provided will give you enough ammo to ask more specific questions so we can help you resolve your issue.

salmanmanekiasalmanmanekia

Thank you soo much sfdcfox. Two questions come to my mind after reading your reply.

 

1 : If in my case for my 'Contact' object  the 'Contact Email' is the ID. So can you give an example (code) of how can i use the key/id field to insert/update the record? .

2 : How and where in the code or UI can i make any feild a key or undo it.

 

Thank you soo much your last post helped me alot :)

Savi3Savi3

Hi,

I think this may help you...

 To insert a contact record:

 

Contact c = new Contact();

c.FirstName ='fname';

c.lastname = 'lname';

c.Email = 'conemail@gmail.com'';

insert c;

 

To update contact record:

 

Contact c1=[Select id, name from Contact where Email =: 'conemail@gmail.com'];

  c1.name = 'new name';

update c1;