1

I have the following code referencing a URL field on the object. As long as the address in the field is typed with the leading address info like "http:www.cnn.com" the code works just fine however if I just type in "cnn.com" I get an error message from Salesforce when I click the outputlink. I can go to the record page and click the link without issue so I am guessing that Salesforce is reformatting the field on the fly. Is there a way to do the same in outputlinks?

                <apex:column style="text-align:left;">
                    <apex:facet name="header">S.O.P.</apex:facet>
                    <apex:outputlink target="_blank" 
                                     disabled="{!IF(ISBLANK(acc.Account_Servicing_Task__r.Standard_Operating_Procedures_SOP__c),true,false)}" 
                                     value="{!acc.Account_Servicing_Task__r.Standard_Operating_Procedures_SOP__c}">
                        SOP
                    </apex:outputlink>
                </apex:column>
2
  • 1
    Is there a reason that you dont want to just save the entire url in the field? May 3, 2018 at 17:22
  • No, I want the full URL in the field but this is a user updated field and as the system will accept a URL that is close it causes me a little wrinkle in how the VF page works.
    – Matt M
    May 4, 2018 at 18:14

1 Answer 1

1

If you observe carefully whenever you add a link without the protocol (HTTP or HTTPS) in a URL field, Salesforce automatically append HTTP and display it in Standard pages.

You can achieve this in two ways either you use <apex:outputField which will do the HTTP append for you or write your own logic through formula as below.

<apex:outputLink value="{!IF(BEGINS(LOWER(item.URL__c), 'http'), item.URL__c, 'http://'+item.URL__c)}">{!item.URL__c}</apex:outputLink>

Example VF Page:

<apex:page standardController="Book__c" recordSetVar="Books" >
    <apex:pageBlock>
        <apex:pageBlockSection>
            <apex:pageBlockTable value="{!Books}" var="item">
                <apex:column>
                    <apex:facet name="header">S.O.P.</apex:facet>
                    <apex:outputField value="{!item.URL__c}"/>
                </apex:column>
                <apex:column>
                    <apex:facet name="header">S.O.P.</apex:facet>
                    <apex:outputLink value="{!IF(BEGINS(LOWER(item.URL__c), 'http'), item.URL__c, 'http://'+item.URL__c)}">{!item.URL__c}</apex:outputLink>
                </apex:column>                
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

You must log in to answer this question.

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