• Skip to main content
Client Portal
(888) 391-4493
  • Salesforce Services
    Salesforce Managed Services

    Maximize your ROI and say goodbye to costly in-house Salesforce staffing with StarrData Team as a Service.

    Salesforce Administration

    Stop worrying about the day to day details of Salesforce and outsource to a 5-star certified Salesforce team.

    Salesforce Implementation

    We'll help you get up and running quickly - from simple implementations to fully customized instances.

    Salesforce Optimization

    Get the most out of your Salesforce investment by fine tuning your instance specifically for your needs.

  • Salesforce Clouds
    Salesforce Revenue Cloud
    Salesforce CPQ

    Deliver fast & accurate proposals that empowers your sales team and maximizes company revenue.

    Salesforce Products
    Sales Cloud

    Empower your sales team by leveraging best practices throughout the company.

    Experience Cloud

    Connect your customers, employees & partners with the power of Salesforce.

  • Who We Serve
  • Success Stories
  • Blog
  • About
    Guaranteed Customer Satisfaction

    A commitment to customer satisfaction doesn’t go far without a process for ensuring it. Learn how the StarrData Action Loop works to guarantee customer satisfaction, eliminating misunderstandings and scope creep.

    5-Star Certified Salesforce Partner

    Since 2009, StarrData has helped hundreds of companies leverage the power of Salesforce. We are a 5-star certified partner with an experienced team of consultants, solution architects, engineers, and administrators.

    Success Stories & Testimonials

    Read first-hand accounts of how StarrData solutions, customizations and ongoing support helped clients in multiple industries get more out of their Salesforce investment, enhancing productivity and customer satisfaction.

    Commitment to Equality

    At StarrData we believe that all humans are equal, and diversity is a strength. We are committed to providing equal employment opportunities and world-class service to anyone, regardless of sex, color, gender, religion, or sexual orientation.

  • Talk to an Expert

Create your own Line Item Numbers in Salesforce

By Darren Starr
Linkedin
X (Twitter)
starrdata-logo

Today we will teach you how to create your own Line Item Numbers in Salesforce.

We recently had a need to add Line Item Numbers to the Salesforce Campaign Members related to a Campaign. At first thought, one would think to use an “Auto Number” field on the Campaign Member object but this field assigns numbers sequentially across all records in an object, so the numbers for each record would just keep increasing across all Campaign Members.

What we actually want is for the numbers to start over for each Campaign, so as Campaign Members are added, the numbers increase for that Campaign. Then, to add more complexity, we needed the numbers to recalculate as records are removed, so we do not have gaps in the sequence.

This functionality is quite easy to create using standard Salesforce automation, including Process Builder and Visual Flows, with a little help from a Roll-Up Summary field. We built this on the Campaign/Campaign Member relationship but it can also be used for Quotes and Quote Line Items, Accounts and Opportunities, or anywhere else where a Roll-Up Summary field is available (objects with a Master-Detail relationship). For Lookup relationships, like Accounts and Contacts, the free DLRS application will give you the ability to count all related records (and more) from the parent record.

The first thing you need to do is create a couple of fields. On the Campaign object, create a Roll-Up Summary field called “Total Members” that counts all related Campaign Members. This field gets updated each time a Campaign member record is added or removed, which allows us to fire a Process Builder process off of it. Then, on the Campaign Member object, create a new “Member Line Item Number” number field with zero decimal places. You may want to make this field read-only or remove it from page layouts so it cannot be edited by a user.

Now for the fun part; creating the Visual Flow. Each time a Campaign Member is added to a Campaign, we need to look at all associated members and assign sequential numbers, based on the order that they were added. Below is a picture of the Flow as a whole. This needs to be saved as an Auto-Launched Flow to work properly.

Before creating any steps, you will want to create a few Variables. Below are the ones referenced in this Flow:

  • Variables:
    • VarCampaignId holds the Campaign Id from the record that starts the Flow
      • Resource Type = Variable
      • Name = VarCampaignID
      • Data Type = Text
      • No Default Value
      • Check Available for input
  • VarOne holds the new Campaign Member Line Item Number
    • Resource Type = Variable
    • Name = VaOne
    • Data Type = Number
    • Decimal Places = 0
    • Default Value = 1
  • SObject Collection Variable:
    • Resource Type = Variable
    • Name = CollUpdatedMembers
    • Data Type = Record
      • Check Allow multiple values (collection)
    • Object = Campaign Member
    • Check Available for output

Now that the resources are created, the actions can be created.

Get Campaign Members action

The first action is to get all the Campaign Members for a specified Campaign. This will be the first action of the Flow, connected from the Start element. It needs to look up all the Campaign Member records where the Salesforce Campaign ID equals the value in the “VarCampaignID” variable. We want the Line Item number applied by when the member was added so this step is sorting by the Created Date in Ascending order.

Loop action

Now we want to loop through the collection of Campaign Members, one record at a time, and update their line number. Drag a Loop element onto the canvas, and configure it to loop through the Get_Campaign_Members collection variable just created. Be sure to accept the default Direction of First item to Last item.

First Assignment action

Now we need to edit each record in the Loop. Drag an Assignment element onto the canvas. For Variable, first, select “Current Item from Loop Loop_Campaign_Members. In the list of Campaign Member fields, select “Member Line Item Number” (or whatever you named your field to hold the line item number).

Set the Operator to Equals, and for Value, select VarOne. On the first record processed in the loop, Line Number is set to VarOne’s default value of 1.  Your Assignment action should look as follows.

Second Assignment action

This action could have been part of the first action, but keeping it separate provides better clarity on the actions. The first action set the first Campaign Member’s line number to “1”, the default in the VarOne variable. This action adds 1 to the VarOne variable before the next record is processed.

It also adds the record in the loop to CollUpdatedMembers for the update action.  For value, select “Current Item from Loop” as shown.

Update Records action

After the loop has processed all of the Campaign Member records in the Get_Campaign_Members collection, the flow is ready to mass update the records that have been added to CollUpdatedMembers. Drag the Update Records element onto the canvas, and select the CollUpdatedMembers collection for update.

Your flow is ready!  Save the flow with a logical name such as “Set Line Numbers on Campaign Members”, and Activate the flow.

Call the Flow from a Process

The final step is to create a Process Builder process which calls the flow when the Roll-Up Summary field on a Campaign record changes.  We called the field “Total Members” above.

Create a new Process to act on the Campaign object, whenever a record is created or edited.  Set the action Criteria to Total Members (or your field name) Is changed equals True.

The criteria’s Immediate Action is to call the flow you just created.  So select Immediate Action Type of Flows, give it an Action Name, and select your Flow. If your new flow isn’t listed, it probably hasn’t been Activated.

Finally, set the Flow Variable.  Select VarCampaignId from the flow, set Type as Field Reference, and for Value select Campaign Id.

Save your new Process and Activate.  It’s now operational.  Here is an example of the end result.

Posted in Salesforce Administration
StarrData Logo

StarrData

3527 Mt. Diablo Blvd. #392
Lafayette, CA 94549

(888) 391-4493 x101

info@starrdata.com

Popular Links

  • Salesforce Implementation
  • Salesforce Managed Services
  • Salesforce Optimization
  • Salesforce Administration
  • Salesforce CPQ

Follow Us

Copyright© 2024 | Privacy Policy

Our Spring Sale Has Started

You can see how this popup was set up in our step-by-step guide: https://wppopupmaker.com/guides/auto-opening-announcement-popups/

Our Spring Sale Has Started

You can see how this popup was set up in our step-by-step guide: https://wppopupmaker.com/guides/auto-opening-announcement-popups/

Contact Us Today

To speak with someone right away, give us a call at (510) 984-3648.

  • This field is for validation purposes and should be left unchanged.