Redirect standard salesforce view of child object to skuid page of parent

  • 1
  • Question
  • Updated 3 years ago
  • Answered
Related_Person__c is a child object of Patient__c.

When a user visits the detail page of a Related Person (i.e. /{{Id}}), I'd like to send them to the same squid page that the Patient detail redirects too, and also add #related_person to the url.

Patient__c detail redirects to something like this:
/apex/UI?id={{Id}}&sfdc.override=1&objectType=Patient__c&actionType=View

Would it be possible to Related_Person__c detail to redirect to something like this:
/apex/UI?id={{Patient_Name__c}}&sfdc.override=1&objectType=Related_Person__c&actionType=View#related_person

Where Patient_Name__c is the reference field from Related Person to Patient.

How would I set that up?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Any ideas on this one, friends?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
^^
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Interesting challenge.  

I think you can do this in your object / action override code, if you use the Skuid Redirect method and don't run the page through Page Assignments. 

I think your VF Page code for View under Related_Person__c would look something like this: 

<apex:page action="{!redirect}&page=PatientDetailPage&Id="{!PatientId}"#tab_two" extensions="skuid.Redirects" standardController="Related_Person__c">
</apex:page>
                                        
You could also do this as a direct link in your skuid pages (rather than using the redirect infrastructure) 

Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Thanks, Rob. I'll try it out. I would use the direct link idea, but the search component doesn't allow different actions for different objects.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Hmm, I'm not quite getting the syntax right.

When I do this...
<apex:page standardController="Related_Person__c" action="{!redirect}&page=PatientChart&id={!Patient_Name__c}#related_person" extensions="skuid.Redirects"
 showHeader="false" sidebar="false" readonly="true" docType="html-5.0">
</apex:page>
 I get the error:
Error: Unknown property 'Related_Person__cStandardController.Patient_Name__c'

If I put quotes around {!Patient_Name__c} as your example suggests...
<apex:page standardController="Related_Person__c" action="{!redirect}&page=PatientChart&id="{!Patient_Name__c}"#related_person" extensions="skuid.Redirects"
 showHeader="false" sidebar="false" readonly="true" docType="html-5.0">
</apex:page>
I get the error: 
Error: <apex:page> is required and must be the outermost tag in the markup at line 1 column 1
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
Maybe # is not a valid character to use in the action parameter...

dirty workarround: Javascript

<apex:page standardController="Related_Person__c" showHeader="false" sidebar="false" readonly="true" docType="html-5.0">
<html>
<head>
<script>
function goToPatientPage(){
document.location='/apex/skuid__ui?page=PatientChart&id={!Patient_Name__c}#related_person';
}
</script>
</head>
<body onload="gotoPatientPage();">
<img src="loading.gif"> Redirecting    <----- this is completely optional
</body>
</html>
</apex:page>
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Pablo,

Thanks for the answer. I'm still getting this error code:

Error: Unknown property 'Related_Person__cStandardController.Patient_Name__c'

I really don't know much about apex at all... Skuid has largely shielded me from it (yay, skuid!). Is there something wrong in my syntax? Should {!Patient_Name__c} return the value of the Patient_Name__c field in the Related_Person__c object?

Why am I seeing 'Related_Person__cStandardController' in the error message... as one word?

I tried to look up some apex syntax on the SFDC help, but the help seems to be broken at the moment...
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
Can you try instead of {!Patient_Name__c} put  {!Related_Person__c.Patient_Name__c}
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
That worked! I was able to go back to the direct approach Rob suggested, but using {!Related_Person__c.Patient_Name__c}
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Hmm, I spoke too soon. I was finally allowed to save the VF page... but when I implemented it as the view action this is what I get:

SObject row was retrieved via SOQL without querying the requested field: Related_Person__c.Patient_Name__c

Should I go back the the javascript method?

Or is there a way to tell apex to query that field?
(Edited)
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
The dirty workaround works! :)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Sorry for the dirty workaround.  Thanks for your persistence.  Glad it works.