# MOD() Function in Salesforce | Calculate remainder in Salesforce

In this Salesforce tutorial, We will learn about the Salesforce MOD() function. In addition, we’ll learn the syntax and various real-world Salesforce usage examples for this function.

Recently, I got hired by a New York-based company that relies on the CRM software Salesforce to manage its work. I was given a job at work that required me to determine the overall amount of funds raised for the campaign.

As a solution, I discovered that Salesforce gives us the function named “MOD” which helps in determining the remainder when a number is divided by a given divisor. To understand how to use the MOD() function in Salesforce Lightning and Salesforce Classic, let’s go into further depth.

## Salesforce MOD Function

The MOD() function in Salesforce is the mathematical function available in Salesforce that is used to carry out mathematical calculations. In basic terms, the MOD() function returns a remainder after dividing a number by a specified divisor.

Additionally, only numerical data types like Integers, Decimals, and Currency are supported by the MOD() function. However, if you attempt to utilize a text, date, or other non-numeric data type, an error will result.

The Salesforce MOD() function syntax is as follows:

``MOD(dividend, divisor)``

Here, the divisor is the number by which the dividend is divided and the dividend is the number that is being divided. The value of the parameter divided and divisor can be a field, a constant number, or a complex formula.

For a better understanding of how the MOD function works, let’s look at an example.

As I mentioned above, I need to figure out how much money was raised overall for the campaign. I will therefore utilize Salesforce MOD() method for this. The formula is as follows:

``MOD(Total_Contribution__c, Total_Amount__c)``

With this, we learned the syntax of the MOD() function as well as an example. We’ll now look at how to use the MOD() function in Salesforce Lightning.

## How to use MOD Function in Salesforce Lightning

The steps to use the MOD() function in Salesforce Lightning are as follows:

Step 1: Log in to Lightning mode in Salesforce, then click the “Gear Icon” in the top right corner of the page. To proceed, click “Setup” from the dropdown menu.

Step 2: The setup page is opened after selecting the Setup option. The “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.

Step 3: The object manager page is opened after you click it. There are numerous items seen here. Use the search field to look for the item you want to use the MOD() function on. In this instance, I look for the “Campaign” object because I need to determine how many votes we needed in the elections on the bases of engagement in the campaign to reach the desired level.

Step 4: Now click the “Campaign” object to move to the campaign object page.

Step 5: Under this campaign object page, on the left side of the page, the “Field & Relationship” option is found in the details section. Select “Field & Relationship” from the menu

Step 6: The field and relationships page is opened after selecting the field and relationship option. Click the “New” button at the top of the field and relationship page.

Step 7: The data type page is opened after clicking the new button. The page contains a wide variety of data types. In this case, I choose the “Formula” data type field, as I want to use the MOD function in the advanced formula.

Step 8: Click the “Next” button to move on to the following step.

Step 9: The choose output type screen appears after hitting the next button. Enter the information now by filling out the “Field Label” and the “Field Name”, is automatically filled in when you click on the field. I typed “Votes Needed” into the field label in this instance.

Step 10: Choose the “Output Data Type” for the field in which we want to store the result. In this case, I check the radio button in front of the “Number” data type to receive the formula return type as a number, and I also set the “Decimal Place” to 2.

Step 11: Move to the next, click on the “Next” button.

Step 12: Go to the advanced formula editor and type the MOD() function formula there. In this instance, I want to use the MOD function to determine how many votes we needed to reach the desired level. The formula is as follows:

``MOD(Total_Voter__c, Candidate_Support__c)``
• This formula is used to determine the remainder after dividing the total number of voters “Total_Voter__c” by candidate support “Candidate_Support__c”, to get how many more votes we need to win with a majority.

Step 13: To validate the formula and make sure there are no mistakes, click the “Check Syntax” option.

Step 14: Optionally, we may define the “Description” and “Help text” as well as “Handle the empty field” if we like.

Step 15: Press the “Next” button to go to the security stage for the formula field.

Step 16: In this step, establish “Field-Level Security”.Now choose the profiles to which we wish to grant field-level security edit access to this field. If field-level security is not added, the field will be hidden from all profiles.

Because I want it to be visible to all profiles, I have chosen “Visible” in this instance. After that, click the “Next” button located at the top.

Step 17: Add the custom field to the “Page Layout” after setting up the field-level security. Pick the page layout that has this field in it. If we do not select a layout, the field will not appear on any pages.

Step 18: To save the formula field, click the “Save” button.

We can use the formula field once weâ€™ve created it. Letâ€™s look at an example:

• Open the Campaign Tab and create a new campaign with the fields Total Voters and Candidate Support.
• The Estimated Votes field, which displays the output of the MOD() function, then appears when you click on the Details Section.

As a result, we now understand how to use Salesforce Lightning MOD() Function. Now, weâ€™ll look at how to use the MOD() Function in Salesforce Classic.

## How to use MOD Function in Salesforce Classic

The steps to use the MOD() Function in Salesforce Classic are as follows:

Step-1: Log in to your Salesforce account first; after you’re logged in, the Salesforce Lightning Edition should already be open. Click “Profile Picture” once you are in Salesforce Classic. The drop-down menu for the profile photo is available. There is a “Switch To Salesforce Classic” option below this selection of profile pictures. Just click it.

Step 2: Next, select “Setup” from the menu.

Step 3: The setup page is opened after selecting the setup option. Go down to the “Build” section now. Select the object for whose field we want to use the MOD() function under “Customize” after that. In this instance, I choose the “Orders” object since I need to track the order.

Step 4: Select “Orders” from the drop-down menu. The drop-down list is available, and underneath it is a field option. Select “Fields” from the menu.

Step 5: The order custom field page is opened after selecting the fields option. There is a section titled “Order a custom field and a relationship” at the bottom of the page. Simply click the “New” button to add a new field.

Step 6: The data type page is opened after clicking the new button. The page contains a wide variety of data types. In this case, we’re choosing the “Formula” data type field.

Step 7: Click the “Next” button to move on to the following step.

Step 8: The “Choose Output Type” window appears after selecting the next button. Fill out the “Field Label” and “Field Name” (which are pre-filled when you click on the field) to enter the information. In this case, I entered “Track Order” into the field label.

Step 9: Choose the “Output Data Type” for the field in which we want to store the result. In this case, I check the radio button in front of the “Number” data type to receive the formula return type as a number, and I also set the “Decimal Place” to 0.

Step 10: Click the “Next” button to move on to another step.

Step 11: Next, enter the MOD() function formula in the advanced formula editor. In this case, I wish to utilize the MOD function, to calculate the number of days needed to deliver the order. The formula reads as follows:

``MOD(Total_Package__c, Delivered_Pacakges__c)``
• This formula divides the total number of packages “Total_Packages__c” by the number of packages “Delivered_Pacakages__c” that have been delivered to determine the remainder to get the number of packages still remaining to be delivered.

Step 12: Click “Check Syntax” to validate the formula and ensure there are no errors.

Step 13: Define the “Description” and “Help text” as well as “Handle the empty field” if you’d like.

Step 14: To access the security page for the formula field, click the “Next” button.

Step 15: Establish “Field-Level Security”. Select the profiles to whom you want to grant field-level security editing access. The field will be hidden from all profiles if field-level security is not set.

I’ve selected “Visible” in this case because I want it to be visible to all profiles. In order to continue, click the “Next” button at the top.

Step 16: After configuring the field-level security, add the custom field to the “Page Layout”. Choose the page layout that includes this field. The field won’t show up on any pages if we choose not to select a layout.

Step 17: To save the formula field, click the “Save” button.

Once we’ve established the formula field, we may use it. Let’s examine an illustration:

• Create a new order with the fields Total Packages and Delivered Packages by opening the Orders Tab.
• Click on the Details section after that, and the Track Order field will display the MOD() function output.

We now understand how to use the MOD() Function in Salesforce Classic.

## Conclusion

As a result, we can conclude that the Salesforce MOD() Function is an excellent and effective method to obtain the remainder after a number has been divided by a defined divisor. Additionally, we concentrated on the MOD() Function syntax and a number of real-world business scenarios.

The steps for using the MOD() Function in Salesforce Lightning and Salesforce Classic were also covered in detail.