The different data types and field types available in Salesforce Tutorial

Data Types And Field Types in Salesforce Tutorial.

Last updated on 29th Sep 2020, Blog, Tutorials

About author

Karthikeyan (Sr Technical Manager )

He is a Proficient Technical Expert for Respective Industry & Serving 11+ Years. Also, Dedicated to Imparts the Informative Knowledge to Freshers. He Share's this Blogs for us.

(5.0) | 14526 Ratings 1387

Data types and field types in sfdc :In this tutorial we are going to know about What are the different data types, Different types of Field types. In General both data types and field types have the same names in the user names. We use different Data types depending on the condition.

Generally in API there are 5 different data types. They are

    1. 1.ID.
    2. 2.String.
    3. 3.Boolean.
    4. 4.Double.
    5. 5.Varies by type

We can group different field types depending on the Data types.

IDLook up relationship, master-detail relationship
StringAuto number, email, phone, multi select pick list, text, text area, long text area, rich text area, data category group reference and URL
BooleanCheck box
DoubleCurrency, Formula, number, percent and roll-up summary.
Varies by typeFormula Field
Subscribe For Free Demo

Error: Contact form not found.

Different Field Types

Auto number:

when auto number data types is selected a system-generated sequence number that uses a certain display format that we define. Auto generated number will be increment for every record we create.

Formula:

When Formula data type is selected we are able to derive different Formula expressions that derives values. The formula field is updated every time when there is a change in source field. It is a read-only field type.

Roll-up Summary:

Roll-up Summary is also a read-only field type. By using this Roll-up Summary data types we are able to make some mathematical calculations like Sum, Minimum, Maximum values of a afield in a related list or the record count of all records listed in a related list.

Lookup Relationship:

This type of Data type links two objects. we can link on object to another object by Lookup relationship. This data type field allows user to select a value from popup list.

Master-detail relationship:

Master-detail relationship also links two objects but it creates a special type of parent-child relationship between the two objects.

Checkbox:

If a user wants boolean function like true or false this Checkbox data types is used.

Currency:

Currency field type allows user to enter INR or any other country currency values in the record.

Date:

Allows user to enter date or we can select the date from popup calendar.

Date/ time:

Date and Date/Time field types are different from each other. In Date/Time the user can select date from popup calendar and also current time is entered in the Date/Time field.

Email:

Allows users to enter Email address.

Geolocation:

Allows users to enter altitude and longitude values.

Number:

Allows users to enter numbers.

Percent:

Automatically percentage sign is added .

Phone:

Allows users to enter Phone Number.

Picklist:

Allows users to select only on list from a group of lists that we defined. Picking one among many.

Text:

Allows users to enter combination of both letters and numbers.

Text Area:

Allows users to enter up to 255 characters of letters and numbers.

Text area (Long):

Allows users to enter up to 32,768 characters on separate lines.

Text Area (Rich):

Allows users to enter formatted text, add images and links up to 32,768 characters on separate lines.

Text(Encrypted):

Allows users to enter any combination of letters an numbers and store them in encrypted format.

URL:

Allows users to enter a valid website address.

Picklist (multi-select) : Allows users to select many from a group of list that we defined

Custom Field Types

Salesforce supports many different field types. Pick the right type, or convert an existing one.

When you have data that doesn’t match any of the standard fields, your administrator can create a custom field for that data. For example, use a Middle Name field for contacts.

The first step in creating a custom field is choosing the type of the field. This table includes a description of each custom field type. Additional field types may appear if an AppExchange package using those field types is installed.

Course Curriculum

Get Hands-on Practical Salesforce Training with Instructor-led Classes

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum
TYPEDESCRIPTION
Auto NumberAutomatically assigns a unique number to each record. The maximum length of any auto-number field is 30 characters, 20 of which are reserved for prefix or suffix text. Not available for external objects.
CheckboxAllows users to check a box, indicating a true or false attribute of a record. When using a checkbox field for a report or list view filter, use “True” for checked values and “False” for unchecked values. The Data Import Wizard and the weekly export tool use “1” for checked values and “0” for unchecked values.
CurrencyAllows users to enter a currency amount. The system automatically formats the field as a currency amount. This formatting is useful if you export data to a spreadsheet application. Not available for external objects. NOTE Salesforce uses the round-half-to-even tie-breaking rule for currency fields. For example, 23.5 becomes 24, 22.5 becomes 22, −22.5 becomes −22, and −23.5 becomes −24.Values lose precision after 15 decimal places.
DateAllows users to enter a date or pick a date from a popup calendar. In reports, you can limit the data by specific dates using any custom date field.
Date/TimeAllows users to enter a date or pick a date from a popup calendar and enter a time of day. There are visual and behavioral differences for Date/Time fields in Lightning Experience and Salesforce Classic. In Lightning Experience, the date and time fields are separate, and the initial time is set to 12:00 PM when you select a date in the calendar. In Salesforce Classic, the date/time field is a single field. You can set the field to the current date and time by clicking the date and time link next to the field. The time of day includes AM or PM notation. In reports, you can limit the data by specific dates and times using any custom date field.
EmailAllows users to enter an email address of up to 80 characters, which is validated to ensure proper format. If this field is specified for contacts or leads, users can choose the address when clicking Send an Email.You can’t use custom email addresses for mass emails or list emails.Emails sent to a record’s custom email address fields aren’t logged against that record.NoteNOTE This field can be encrypted using Shield Platform Encryption.
External Lookup RelationshipWhen you create an external lookup relationship field, the standard External ID field on the parent external object is matched against the values of the child’s external lookup relationship field. External object field values come from an external data source.
FormulaAllows users to automatically calculate values based on other values or fields such as merge fields. Not available for external objects.NoteNOTE Salesforce uses the round half up tie-breaking rule for numbers in formula fields. For example, 12.345 becomes 12.35 and −12.345 becomes −12.35.
GeolocationAllows users to specify a location by its latitude and longitude. Geolocation is a compound field that counts toward your org’s limits as three custom fields: one for latitude, one for longitude, and one for internal use. Not available for external objects.
Hierarchical RelationshipCreates a hierarchical lookup relationship between users. Allows users to use a lookup field to associate one user with another that neither directly nor indirectly refers to itself. For example, you can create a custom hierarchical relationship field to store each user’s direct manager.
Indirect Lookup RelationshipAn indirect lookup relationship links a child external object to a parent standard or custom object. When you create an indirect lookup relationship field on an external object, you specify the parent object field and the child object field to match and associate records in the relationship. Specifically, you select a custom unique, external ID field on the parent object to match against the child’s indirect lookup relationship field. The child lookup field’s value comes from an external data source.
Lookup RelationshipCreates a relationship between two records so you can associate them with each other. For example, opportunities have a lookup relationship with cases that lets you associate a particular case with an opportunity.On a standard or custom object, a lookup relationship creates a field that allows users to click a lookup icon and select another record from a popup window.On an external object, the lookup relationship field references 18-character Salesforce IDs that are stored in an external data source. Those IDs are matched against the parent object to determine which records are related to each other.On the parent record, you can display a related list to show all the records that are linked to it. You can create lookup relationship fields that link to users, standard objects, or custom objects. If a lookup field references a record that has been deleted, Salesforce clears the value of the lookup field by default. Alternatively, you can choose to prevent records from being deleted if they’re in a lookup relationship.Lookup relationship fields are not available in Personal Edition.Lookup relationship fields to campaign members are not available; however, lookup relationship fields from campaign members to standard or custom objects are available.
Master-Detail RelationshipCreates a relationship between records where the master record controls certain behaviors of the detail record such as record deletion and security.Not available for standard objects or external objects, although you can create a master-detail relationship field on a custom object that links to a standard object.Master-detail relationships cannot be used with campaign members.
NumberAllows users to enter any number. This number is treated as a real number and any leading zeros are removed.NoteNOTE Salesforce uses the round half up tie-breaking rule for number fields. For example, 12.345 becomes 12.35 and −12.345 becomes −12.34. Salesforce rounds numbers referenced in merge fields according to the user’s locale, not the number of decimal spaces specified in the number field configuration.When you use Einstein Prediction Builder to build a prediction, a custom field is created for storing and displaying the prediction scores on records. Or, you can create a predictive custom field manually, enable it as an AI prediction field, and enter its name and label when building a prediction in Einstein Prediction Builder. For example, display how likely a customer is to pay an invoice on time.
PercentAllows users to enter a percentage number as a decimal—for example, 0.10. The system automatically converts the decimal to a percentage—for example, 10%.NoteNOTE Values lose precision after 15 decimal places. Also, if you enter a value with more than 15 decimal places and add a percent sign to the number, a runtime error occurs.
PhoneAllows users to enter any phone number. Character limit is 40.Salesforce automatically formats it as a phone number.If you are using Salesforce CRM Call Center, custom phone fields are displayed with the Click-to-dial button, allowing click-to-dial functionality. Therefore, Salesforce recommends that you do not use a custom phone field for fax numbers.NoteNOTE This field can be encrypted using Shield Platform Encryption.
PicklistLets users select a single value from a list that you define. Available for external objects only with the cross-org adapter for Salesforce Connect.
Picklist (Multi-select)Allows users to select more than one picklist value from a list that you define. These fields display each value separated by a semicolon. Available for external objects only with the cross-org adapter for Salesforce Connect.
Roll-Up SummaryAutomatically displays the record count of related records or calculates the sum, minimum, or maximum value of related records. The records must be directly related to the selected record and on the detail side of a custom master-detail relationship with the object that contains the roll-up summary field. For example, a custom field called “Total Number of Guests” displays the number of guest custom object records in the Guests related list. Not available for external objects.
TextAllows users to enter any combination of letters, numbers, or symbols. You can set a maximum length, up to 255 characters.NoteNOTE This field can be encrypted using Shield Platform Encryption.
Text (Encrypted)Allows users to enter any combination of letters, numbers, or symbols that are stored in encrypted form. You can set a maximum length of up to 175 characters. Encrypted fields are encrypted with 128-bit master keys and use the Advanced Encryption Standard (AES) algorithm. You can archive, delete, and import your master encryption key. To enable master encryption key management, contact Salesforce. Not available for external objects.NoteNOTE This field can be encrypted using Classic Encryption. If your org uses Shield Platform Encryption, use Text to create an encrypted text field.
Text AreaAllows users to enter up to 255 characters that display on separate lines similar to a Description field.
Text Area (Long)Allows users to enter up to 131,072 characters that display on separate lines similar to a Description field. You can set the length of this field type to a lower limit, if desired. Any length from 256 to 131,072 characters is allowed. The default is 32,768 characters. Every time you press Enter within a long text area field, a line break, and a return character are added to the text. These two characters count toward the 131,072 character limit. This data type is not available for activities or products on opportunities. The first 999 characters in a standard rich text area or a long text area are displayed in a report. For custom fields, only the first 255 characters are displayed.NoteNOTE This field can be encrypted using Shield Platform Encryption.
Text Area (Rich)With the use of a toolbar, users can format the field content and add images and hyperlinks. The toolbar allows the user to undo, redo, bold, italicize, underline, strike-out, add a hyperlink, upload or link to an image, modify alignment, add a numbered or non-numbered list, indent, and outdent. The maximum field size is 131,072 characters, inclusive of all the formatting and HTML tags. The first 999 characters in a standard rich text area or a long text area are displayed in a report. For custom fields, only the first 255 characters are displayed. The maximum size for uploaded images is 1 MB. Only gif, jpeg, and png file types are supported. Not available for external objects. There are visual and formatting differences for rich text areas in Lightning Experience and the Salesforce mobile app, compared to Salesforce Classic.
TimeAllows users to enter a time of day, including hours, minutes, second, and milliseconds. Append a “Z” at the end to denote Greenwich Mean Time (GMT).17:30:45.125, 17:30:45, 17:30, and 17:30:45Z are all examples of valid entries. The time displays in a 12-hour notation with AM or PM. The displayed time depends on the Locale setting on the Company Information page in Setup.
URLAllows users to enter up to 255 characters of any valid website address. Only the first 50 characters are displayed on the record detail pages. When a user clicks the field in Salesforce Classic, the URL opens in a separate browser window. In Lightning Experience, internal URLs open in the same window and external URLs open in a separate browser window. In Salesforce console apps, the URL opens in a new workspace tab. In Lightning console apps, internal URLs open in a new workspace tab and external URLs open in a separate browser window.

Data Types:

A data type in a programming language is a set of data with values having predefined characteristics. Examples of data types are: integer, floating point unit number, character, string, and pointer. Usually, a limited number of such data types come built into a language. The language usually specifies the range of values for a given data type, how the values are processed by the computer, and how they are stored.

Apex is a strongly typed, object-oriented programming language. Just like any other  programming language, Apex has variety of data types that you can use.

1).Primitive Types-

This data types include String, Integer, Long, Double, Decimal, ID, Boolean, Date, Datetime, Time and Blob. All these data type variables are always passed by value in methods.  Another point to note is in Apex, all variables are initialized to null when declared. You must explicitly initialize to non-null values before using. 

Data TypeDescription
BlobA collection of binary data stored as a single object.
BooleanA value that can only be assigned true, false, or null. For example:Boolean isWinner = true;
DateA value that indicates a particular day. Unlike Datetime values, Date values contain no information about time. Date values must always be created with a system static method.
DatetimeA value that indicates a particular day and time, such as a timestamp. Datetime values must always be created with a system static method
DecimalA number that includes a decimal point. Decimal is an arbitrary precision number. Currency fields are automatically assigned the type Decimal.
DoubleA 64-bit number that includes a decimal point. Doubles have a minimum value of -263 and a maximum value of 263-1. For example:Double d=3.14159;
IDAny valid 18-character Force.com record identifier. For example:ID  =’00300000003T2PGAA0′;
IntegerA 32-bit number that does not include a decimal point. Integers have a minimum value of  -2,147,483,648 and a maximum value of  2,147,483,647. For example:Integer i = 1;
LongA 64-bit number that does not include a decimal point. Longs have a minimum value of -263 and a maximum value of 263-1. Use this data type when you need a range of values wider than those provided by Integer. For example:Long l = 2147483648L;
StringAny set of characters surrounded by single quotes. For example,String s = ‘The quick brown fox jumped over the lazy dog.’;
TimeA value that indicates a particular time. Time values must always be created with a system static method.

2).sObject Types-

This is a special data type in Apex. sObject is a generic data type for representing an Object that exists in Force.com. It could be Standard object like Account, Opportunity etc., or Custom object that you define.  Following are some of the examples of sObject variables –

  • Sobject s = new Account();
  • Account a = new Account();
  • CustomObject__c c = new CustomObject__c();

As you can see above, your custom objects have an extension of __c to distinguish from the Force.com standard objects. Fields from the sObject variable can be accessed using the dot notation.

3).Collections-

Apex has 3 types of collections. Lists, Sets and Maps.

  • A list is like an array, a sequential collection of elements with first index position as zero. List can contain elements of primitive types, sObjects, user-defined objects, Apex objects or even other collections. A list can contain up to four levels of nested collections. List can contain duplicate elements.
  • A set is also a collection of elements and elements can be of any data type. Unlike list, set contains unique elements and elements in set are not in any specific order.
  • A map is a collection of key-value pairs. Keys and values can be any data type. Keys are unique and map elements must be accessed by the key as the order of  map elements are not reliable.
Salesforce Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

4).Enums-

Just like in other programming languages, Enum type represents a fixed set of named constants.

An enum is a data type which contains fixed set of constants. It can be used for days of the week (SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY and SATURDAY) ,directions (NORTH, SOUTH, EAST and WEST) etc. The enum constants are static and final implicitly.

Conclusion

Salesforce has become synonymous with CRM. Organizations can use Salesforce for contact management, customer engagement, workflow creation, task management, and opportunity tracking. You can also collaborate with colleagues, run analytics, and access Salesforce from a mobile dashboard.

Are you looking training with Right Jobs?

Contact Us

Popular Courses