Relate an Activity to Multiple Whats

Ever wanted a simple way to add more than one RelatedTo record to an Event? Keep reading.
Relate an Activity to Multiple Whats

Relate an Activity to Multiple Whats

Relate an activity (task/event) to multiple 'Related To' records.  A client of mine recently approached me with this issue.  Not only did she need to be able to relate several contacts to an event in Salesforce, but also multiple records from a custom object.  If your organization has enabled Shared Activities, you can relate as many as 50 contacts to non-recurring and non-group tasks, and non-recurring events, but relating to multiple records of other objects is not available or supported by Salesforce.  

 

This Is Not a New Idea

Here's the latest revival of this idea in the success community.  Here’s another iteration of the same thing, and here's the original idea which was posted 10 years ago, then merged (mistakenly, in the opinion of most) into another idea that was similar but not the same concept.  Needless to say, the idea has been around and continues to be an issue for some Salesforce Users.  

 

An Unreasonable Solution

 It’s likely to occur to many that a combination of custom objects could be used to achieve this functionality from a data model standpoint, but without extensive automation or a fair amount of custom code, including a Visualforce page, the data model will be difficult to maintain.  Such a lengthy addition to the data model for such a small amount of additional functionality also just seemed a bit silly, and after a quick sandbox demo of how this might look, my client required a cleaner, simpler solution.  

The Pseudo Related List (I made that up)

The solution that I came up with doesn’t create a relationship between objects via a lookup field.  It simply captures a name from a lookup and appends it to a long text field on the event object. At the same time, a task is created on the related record referring back to the event. To finish off the process, the lookup field value that was selected is removed in order to allow the addition of further records.  

Now roll up your sleeves. Here’s what you’ll need to replicate the process.

We’ll need to create some custom fields to help us accomplish this, see detail below:

 

Custom Fields

  • Activities   ( In Classic: Setup → Customize → Activities → Activity Custom Fields )

 

Field Name

Field Type

Add to layout

Add New Opportunity

Lookup to Opportunity

Event Layout

Related Opportunities

Text Area

Event Layout

Event/Meeting Link

URL

Task Layout

Event URL

Fomula → text

Non/Hidden

 


 

 

Custom Label

  • This will be used to allow the text area to appear as a list.  It’s actually a workaround for a known issue with line breaks in Process builder formulas.  More info here.
  • Setup → Create → Custom Labels
  • NewLine
  • Value should equal dashes “ - “ on two separate lines

 

Process builder

  • Setup → Create → Workflow & Approvals → Process Builder

 

  • Start the process when an Event record is created or edited

 

 

 

  • Next we’ll create some criteria for appending an Opportunity name to our list.  
  • The AddNewOpportunity__c field should be changed or new and not be null.  We’ll use 3 criteria to set this.   

 

 

 

Field

Operator

Type

Value

[Event].AddNewOpportunity__c

Is Changed

Boolean

True

[Event].CreatedDate

Equals

Reference

[Event].LastModifiedDate

[Event].AddNewOpportunity__c

Does not equal

Global Constant

$GlobalConstant.Null



 

 

 

If these criteria are met, the following actions should occur:

  • Append the opportunity name to the Related Opportunities field by adding an action to update a record.
  • Update the ‘Related Opportunities’ field on the Event that started your process
  • Use the following formula to put each appended name on a new line.

 

[Event].AddNewOpportunity__c.Name &  

SUBSTITUTE($Label.NewLine,"-","")&

PRIORVALUE([Event].Related_Opportunities__c)

 

 

 

 

 

  • Create a Task on the related Opportunity that links back to the Event
  • Add an action to Create a Record of type Task

 

 

 

The last step will be to remove the value from our ‘Add New Opportunity field’  

 

 

  • If ‘Add New Opportunity’ field is not null

 

 

 

  • Make the field null

 

 

Next, make sure to update the process to ‘Evaluate the Next Criteria’ instead of stopping

 

 

 

Be sure to Activate your process.

 

 

Next time you create an event and save it, you can add Opportunities to the “related list” by selecting opportunities in the ‘Add New Opportunity’ field lookup and saving the record.

 

 

Each time you do this, it should add the opportunity name to your ‘Related Opportunities’ field and  leave the ‘Add New Opportunity’ field blank.  

 

 

 

Each of the opportunities you add will also have a task related to them with the subject as the event.

 

 

 

The activity will display in the Activity History of the Opportunity as well.  

 

 

 

 

Other Considerations

 

  • Removing an opportunity name from the list will not remove the related task from the Opportunity. This will need to be done manually.  Automating this would require a fairly complex Apex trigger that would completely defeat the simplicity of this project.
  • Modifying an event date or start time will not propagate through to the created tasks.  Although the link back to the event will still be correct.  Tasks will continue to have original date until updated manually.  
  • Activities reporting should function as expected, given that each Opportunity will have its own activity assigned to it.
  • The use of Opportunities was only for the purpose of this demo.  This process could easily be updated to accommodate any custom or standard object available via lookup.
  • Rich text fields are not available on Activities records.  If the list was to be implemented on an object that allowed this, the names could be inserted as hyperlinks connecting to the related record directly.  
  • Using a lookup field as a point of data entry for an adjacent text field may be confusing, as this is definitely a non-standard way to use Salesforce.  

 

It was my client’s suggestion that I share this as a possible solution for a fairly common problem.  With a little imagination, the concept of a pseudo related list has lots of potential use cases beyond events.

 

Do you have any uses for a pseudo related list like the one I outlined above? If so, tell me all about it. Share them with me on the Arkus Facebook page, in the comments below, in the Success Community, or to me directly via Twitter at @jpbujold

 


Filed under: , , ,
blog comments powered by Disqus