Salesforce Tutorial# 5: Object Relationships and Formula Field in Salesforce

In this 5th article in our Salesforce learning journey, we will have some more insights on Salesforce Object Relationships. We will also see how Formula Field in Salesforce is defined.

Salesforce Objects Relationships:

Relationships are used to connect Salesforces objects with each other. We can define three relationships on salesforce objects based on their scope of data sharing, deleting, accessing, etc. To read more in this please refer our previous article Overview of Database Concepts (Salesforce.com)

Differentiation between One-to-Many and Many-to-Many

The basic difference between these two relationships is One to Many relationships is defined using master-detail (lookup relationships) whereas Many to Many relationships is always defined on two master objects.

So that many-to-many relationship can have links like each record of one master object linked to multiple records from another master object or vice versa.

Lookup is a One-to-Many type of relationship in which two objects are linked together but has no effect on deletion or security. Whereas in normal One-to-Many relationship when a record of the master object is deleted, its related detail records are also deleted.

Introduction of Primary-Keys & Foreign-Keys (Conceptual Knowledge)

A Primary key is a column or set of columns that uniquely identifies the record in the table. When a primary key is defined using multiple columns, the data from each column is used to determine whether a record/row is unique. When we defined any column or columns as primary key, there are some constraints that should be satisfied by the primary key that is column value should not be null (Null Constrains) and data should be unique (Unique Constrains.)

A Foreign key is a set of one or more columns in a table that refers to the primary key in another table. Foreign key does not necessarily always point to the primary key, but the basic idea behind foreign key is that any column that is unique to identify that record/row.

Roll-up Summary Field

A roll-up summary field is a custom object field which calculates values from related records or the records in a related list. The roll-up summary field is created to display a value in a master record based on the values of fields in a detailed record. A roll-up summary can be defined on the Master-Detail relationship only.

Formula & Cross Object Formula Field in Salesforce:

Formula Field is a read-only field whose value is evaluated from the formula or expression defined by us. We can define the formula field on both standards as well as custom objects. Any change in expression or formula will automatically update the value of the formula field.

We can define the formula field for 7 types:

  1. Number
  2. Currency
  3. Percent
  4. Date
  5. Date/Time
  6. Checkbox
  7. Text

Cross Object Formula Fields are the fields that are based on a Cross-object formula.

The cross object formulas are defined on two related objects and reference merge fields on those objects.

This field is built on child objects. It is also known as Reference formula. We can apply cross-object fields up to 10 levels.  Cross-object formulas can reference merge fields from a master object as well as if the field is at a detailed side then it can merge field from a master-detail relationship. Cross Objects formula can also be defined on lookup relationships.

Steps to Create Date, Text and number formula field in Salesforce

Steps to Create Formula Field

  1. Open Accounts page from setup
  2. Create New Field
  3. Select Formula and click Next
  4. In Field Label, type Label for the formula field. (The Field Name will get populate automatically)
  5. Select the type of data the formula should return. (E.g. Currency, Date, Text etc.)
  6. Click Next. (Formula Editor will get open.)

Create Date Formula Field

Choose field type as a formula

 New Custom Field

 Write Label to Field Label and select return type as Date

formula field in salesforce

 Click next and Write formula

 Formula Area

 Set field Level security

 

After saving you can view the newly created field in the list

 salesforce object relationship

 Formula applied for Date Field

Create Text Formula Field

Follow the above steps and write the following formula

To find the state name based on initials

Create Number Formula Field
To check number must be even

 Now after this article, you must be pretty confident in your knowledge of Formula filed in Salesforce. Also, you must have understood the object relationship very well.

Tutorial Index

  1. Introduction to Cloud Computing (Salesforce.com and Force.com)
  2. Overview of Database Concepts (Salesforce.com)
  3. Introduction to Force.com
  4. Building Salesforce Custom App and Objects
  5. Object Relationships and Formula Field in Salesforce
  6. Salesforce Security Model and Overview
  7. Automation in Salesforce
  8. Approval Process in Salesforce
  9. Introduction to SOQL and SOSL
  10. Introduction to Apex
  11. Salesforce Data Management
  12. Visualforce MVC Architecture on Cloud
  13. Salesforce Reports and Dashboards
  14. Building a Visualforce (Custom) Page for the Salesforce App
  15. Salesforce Sandbox and Overview of Force.com capabilities
  16. Learning Apex and Deployment Tools

 

Add a Comment

Your email address will not be published. Required fields are marked *