Thank you for responding. I have taken your advice as best as possible. As of now, I am not receiving any errors, but the fields are not populating when I create a new task that fits the criteria for the Flow to fire. Would you happen to see what I am missing, or offer any further advice?

I have Opportunity -> Appointment__c -> Task

I am creating a link from Task to Opportunity, the 'Text' of the Link will be the Opportunity Name.

Opportunity_Link__ on Task Object is a Lookup field to Opportunity.

Also, when creating the hyperlink am I accessing the Object, or ObjectId. Process BUilder is on Appointment__c

FLow is on Task

Thank you

enter image description here

enter image description here

enter image description here

Original Post -- I didn't know if I should remove

DISREGARD BELOW********* Objects: Opportunity -> Appointment -> Task

I am creating a Hyperlink field on the Task that leads back to the Opportunity. The Text of the link will be the Opportunity Name. On the Task Object the Appointment is linked through the WhatId field. I cannot figure out the correct syntax for the Link or Opportunity Name. I am receiving broken link messages when I test, meaning I don't have the link syntax correct.

Also, because the WhatId field can be any of a number of objects I was wondering, how would I show this field conditionally.

If WhatId is not an Opportunity, do not show field?

  "/WhatId" , 
  "This will be the Opportunity name",

enter image description here

enter image description here

Thank you

2 Answers 2


First of all, I would start, by challenging this requirement because there if a Task is related to an Opportunity, then the 'Related To' field on the Task will already be a hyperlink to the Opportunity using the Opportunity Name. Why do you need to have a separate field when the end users can just click on the 'Related To' link?.

Oftentimes, additional fields like this cause clutter and when you can fallback on an Out of the Box (OOTB) feature, that should always be preferred. If this is about users not knowing if this is an Opportunity or not then they should be trained. They can simply hover over the hyperlink and it will show the Object type and Icon.

For the sake of your post, I will still answer your question. Perhaps it will be useful to others who are attempting a similar implementation for other use cases:

I know polymorphic lookup fields are tricky to work with sometimes so I would suggest breaking this into smaller parts and test at each step.

  1. We need to identify if the Task is related to an Opportunity.

Lookup fields store the Salesforce Id of the 'parent' record. Each Object can be identified by the first 3 digits of the Salesforce Id. While custom Objects may be different between Sandboxes and Production, Standard Objects always have these prefixes.

Perhaps you can create a formula (Checkbox) field (let's call it is_for_ Opportunity__c) on the Activity object that will be true if the Id stored in the lookup field corresponds to an Opportunity:

Use something like this for the formula:


Test on a task to make sure it is checked (true) when the whatId is populated with an Opportunity and false when it is blank or populated with another object.

  1. Now we need a formula field on the Activity that shows a hyperlink.

    Lets build a hyperlink formula and nest that in an IF Statement that will show the hyperlink if the Task is for an Opportunity and will be blank if it is not.

     HYPERLINK('/' + WhatId, 'Open Opportunity', '_self' ),
  2. I believe as of the SP'21, we can now dynamically show fields on a lightning record page.

so you can optionally use this feature to only display the field if the task is for an Opportunity (i.e, Is_For_Opportunity__c = true).

Hope that helps. I think this way is clear, but if you need, you can always simply use a single formula field instead of two and incorporate the LEFT() function in the Hyperlink condition.

You can also potentially use the Is_For_Opportunity__C field differently such as using a Text Formula field and returning the name of the object in WhatId.


 IF(LEFT(WhatId,3)=='006', Opportunity,    
  IF(LEFT(WhatId,3)=='001', Account, 

This way you don't need multiple formula fields 'Is_For_Opportunity__c, Is_For_Account, ...) and can rely on a single one for multiple uses.

  • OP asked to show the Opportunity.Name field
    – cropredy
    Commented Jul 6, 2021 at 18:13
  • THank you for all the good information and ways to look a this. The '/WhatId' is sending me to the Apporintment not the Opportunity though.
    – tsmith
    Commented Jul 14, 2021 at 11:27

Adding a relevant answer since you refined your question.

Since you can't access parent fields of a polymorphic relationship using a formula field or a process builder, you would need to build automation. Use an Apex Trigger or a Salesforce [record triggered] flow launched after After a task is created (and updated?)

  1. Create a lookup field to Opportunity on the Activity (Task)

In flow:

  1. Check that the whatId is an Appointment
  2. Query the Appointment
  3. update a custom lookup field with the Opportunity from the Appointment
  4. Use Salesforce Dynamic Forms to show the field when it is populated or when WhatId is Appointment.

If you use a trigger, you will need to ensure your code is bulkified as well to support multiple tasks that are created in a single transaction. I believe flows are bulkified automatically.

Benefits of Apex / SOQL is that you can use the 'TYPEOF' expression In your SOQL query to return parent fields based on the object type.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .