[SalesForce] Filter lookup on Task

Normally in Salesforce we can insert filter logic for lookup fields values by clicking on Edit near to chosen lookup field. Why cannot we do this in case of standard field RelatedTo on Task? This lookup looks like below:

Lookup(Contract,Order,Campaign,Account,Opportunity,Product,Asset,Case,Solution,Quote,Live
Chat Transcript,Live Agent Session,Coaching,Goal,Metric,Asset
Relationship,Channel Program,Channel Program Level,Partner Fund
Allocation,Partner Fund Claim,Partner Fund Request,Partner Marketing
Budget,Waypoint)

How can we filter suggestions shown to user in this lookup? We want to restrict values only to Cases and Leads. Validation rule is not an option, because user still will see suggestions for all objects and he won't see the error until he cliks Save. Any ideas how to resolve this issue? Thanks in advance

Best Answer

The Related To field on Task (which is called WhatId under the hood) is one of a small number of polymorphic lookup fields in Salesforce, which can point to many different objects. Whether or not an object is available there actually isn't controlled by the Task itself, but by the settings chosen when each object was created:

Custom Object creation screen

Above shot is from the Custom Object creation wizard. If "Activities" are turned on, the object automatically becomes available as a target of the Related To field on Task.

Since you cannot apply lookup filters to this standard field, your options are really limited to workarounds, which might deprive you of some standard Salesforce functionality.

  • Building a custom Visualforce or Lightning interface to add Tasks and using a custom UI to populate Related To.
  • Using Quick Actions or custom buttons to create Tasks with the Related To field prepopulated from a record page.
  • Applying a validation rule.
  • Adding separate lookups to Case and Lead, and using automation to copy any populated value to Related To. (Note that you cannot create new polymorphic lookups, so you'd have to have one per object).

There's not a lot of customization available for this functionality. It's a core part of Salesforce.

Related Topic