0

What are design options for the following requirements?

  1. End user specifies the text of a Modal window to be something like: Hello [User Full Name], Because you chose [Case.FieldA] goto this <a href="hyperlink.html">hyperlink</a>.
  2. A Visualforce page gets this text from either a Custom Metadata or email template or something declaratively accessible.
  3. The Modal renders the text in pretty HTML.
  4. The Modal will capture the onclick event of the hyperlink and create a custom object (CaseInfo__c) record with the HTML link, in the text, set in the CaseInfo__c.Link__c field. Would prefer to not use JS if possible.

My design (which I don't like):

  • split the text message into the HTML portion and the dynamic portion (which contains the User Name and Case field info.)
  • Create a Visualforce Form component which contains OutputPanels. The "Save" button in the first, initially visible OutputPanel, will rerender a second, initially hidden OutputPanel (Modal).
  • Here's a portion of the code:

    <apex:outputPanel layout="block" styleClass="modalMessageText">
        Hello {!$User.FirstName},<p/>
        Because you chose, "{!Case.FieldA__c}",&nbsp;
      <apex:dynamicComponent componentValue="{!restOfMessage}"/>
    </apex:outputPanel>
    <apex:commandButton value="OK" title="Close the modal" action="{!closeModal}" rerender="modalWin"/>
    

The dynamicConmponent in the above page is supported by the associated page controller, which pulls the HTML portion of the message from the Custom Metadata record. This example has a simple link but the design should allow for a more complex (i.e. multiple links, multiple paragraphs, etc..) type of message. My current design doesn't address the forth bullet... besides being a hack.

Any helpful direction or insights would be most appreciated.

2 Answers 2

0

Without JS, if you want to capture the click and pass the parameter and take necessary actions in Controller then better to use apex:commandLink.

Use apex:param to pass the value of {!Case.FieldA__c} to Controller and assign that to caseFieldId through assignTo attribute.

Visualforce

<apex:outputPanel layout="block" styleClass="modalMessageText">
    Hello {!$User.FirstName},<p/>
    Because you chose, "{!Case.FieldA__c}" ,&nbsp; goto this 
        <apex:commandLink id="FieldA" value="{!yourLink}" id="theCommandLink" action="{!CreateCaseInfo}"> {!yourLink}
            <apex:param name="caseFieldId"
                value="{!Case.FieldA__c}"
                assignTo="{!caseFieldId}"/>
        </apex:commandLink>

  <apex:dynamicComponent componentValue="{!restOfMessage}"/>
</apex:outputPanel>
<apex:commandButton value="OK" title="Close the modal" action="{!closeModal}" rerender="modalWin"/>

Controller

public class MyController
{
    public String yourLink {get;set;}
    public String caseFieldId {get;set;}

    public void CreateCaseInfo()
    {
        //here you will have caseFieldId which is getting passed from CommandLink
        System.debug('caseFieldId: '+caseFieldId);
        //create Case Field Info record and take other actions.
    }

}
3
  • Thanks for the reply Santanu. The big issue I have is the business user defines the message (including the link.) I need to be able to give them a simple (nothing more complex than HTML) method to communicate their message to the page. Writing the commanLink code is beyond their skill and it needs to be dynamically situated on the page, so it may not be right after the goto this... I did implement the recommendation and it's not rendering on the modal outputpanel... I'm not sure why... I 'll run a debug.
    – jangiz
    Jun 28, 2017 at 18:02
  • is that helps to find a solution? Jun 28, 2017 at 18:04
  • Not yet. The modal is now not showing any text.
    – jangiz
    Jun 28, 2017 at 18:39
0

So, if you're an ISV, I can't tell you what the certification team would say about this (although they might be OK for the same reasons I am, as below; I just haven't specifically talked with them about this), but if you're an enterprise developer:

If you concatenate the static and dynamic parts in your Apex controller, you can use escape=false on your apex:outputText and the HTML bits will render as HTML.

Normally, this would be something to be really careful of--because if the dynamic part contained malicious Javascript, bad stuff could happen. But the fact that Admins are providing a gateway between the end user and the metadata means that as long as the admins check for that sort of thing before they enter it, I think the security risk here is pretty minimal.

3
  • Hello avrom, First off, love the Metadata feature. Well the admins will take the formatted text from the business user and enter it in the Metadata text field. The Apex is being executed in system context, so the Metadata will be accessible. I'll defer to you in terms of appropriateness of the design. I'll look into a custom object instead. I was hoping to take advantage of the free SOQL queries I can make to the custom metadata :)
    – jangiz
    Jun 30, 2017 at 19:06
  • Ah, OK, I hadn't understood that from your response to the answer below. Fixing my response. Jun 30, 2017 at 20:21
  • Hopefully this version's better. Jul 1, 2017 at 0:30

You must log in to answer this question.

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