MOD() Function in Salesforce | Syntax, Examples, & Use Cases

Recently, I was hired by a New York-based company that uses Salesforce CRM to manage its operations. 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.

In this tutorial, we will learn about the MOD() function in Salesforce. In addition, we’ll learn the syntax and real-world Salesforce use cases for this function.

What is the MOD Function in Salesforce

The MOD() function in Salesforce is a mathematical function used to perform calculations. In basic terms, the MOD() function returns the remainder when a number is divided by a specified divisor.

Additionally, only numerical data types—Integers, Decimals, and Currency — are supported by the MOD() function. However, if you attempt to utilise 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 by the divisor can be a field, a constant number, or a complex formula.

To better understand how the MOD function works, let’s look at an example.

As I mentioned above, I need to figure out how much money the campaign raised overall. I will therefore utilise the 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.

MOD() Function in Salesforce: Calculate Remainder in Salesforce

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

  1. Log in to Salesforce org, then click the “Gear Icon” in the top right corner of the page. To proceed, click Setup from the dropdown menu.
MOD Function in Salesforce
  1. The “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.
MOD Function in Salesforce Example
  1. The object manager page opens when you click it. Now, click the “Campaign” object to move to the campaign object page.
MOD Function in Salesforce Lightning
  1. On the campaign object page, select Field & Relationship from the menu.
    • 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.
MOD Function in Salesforce Lightning Example
  1. The data type page opens when you click the new button. The page contains a wide variety of data types. In this case, I chose the “Formula” data type field, as I want to use the MOD function in the advanced formula.
    • Click the “Next” button to move on to the following step.
Calculate remainder in Salesforce
  1. Enter the information now by filling out the “Field Label” and the “Field Name”, which is automatically filled in when you click on the field. I typed “Votes Needed” into the field label in this instance.
    • Choose the Output Data Type for the field in which we want to store the result. In this case, I check the radio button next to the “Number” data type to return the formula result as a number, and I also set the “Decimal Place” to 2.
    • Move to the next step by clicking the “Next” button.
Calculate remainder in Salesforce Example
  1. 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 the candidate’s support “Candidate_Support__c”, to determine how many more votes we need to win a majority.
  • To validate the formula and make sure there are no mistakes, click the “Check Syntax” option.
  • Optionally, we may define the “Description,” “Help text,” and “Handle the empty field” if we like.
  • Press the “Next” button to go to the security stage for the formula field.
MOD() Function in Salesforce
  1. 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.
Calculate remainder in Salesforce Lightning Example
  1. 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.
    • To save the formula field, click the “Save” button.
How to Calculate remainder in Salesforce Lightning
  1. 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.
How to Calculate remainder in Salesforce Lightning Example

As a result, we now understand how to use Salesforce Lightning MOD() Function.

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 focused on the MOD() Function syntax and several real-world business scenarios.

You may like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.