function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ratheven SivarajahRatheven Sivarajah 

How do you create a button when clicked will send you to that link

Hey So I have created a button where I want the !res.Detail_Link__c to be displayed in the button and I want it to go to the link when click on !res.Detail_Link__c and if there is no link the button should not be visible.

<apex:page controller="TechnologyProduct" lightningStylesheets="true">
    <apex:form>
    <apex:pageBlock>
    <apex:pageBlockSection title="Vitality Check Attributes">
            <apex:repeat value="{!TechnologyProduct}" var="res">
<apex:outputText value="{!res.Detail_Link__c}" /><br/>
       <apex:commandButton  value="{res.Detailed_Product_Name__c}"/>
            </apex:repeat>
    </apex:pageBlockSection>
         </apex:pageBlock>
        </apex:form>
</apex:page>
Best Answer chosen by Ratheven Sivarajah
Shri RajShri Raj
You can modify the apex:commandButton as follows:
<apex:commandButton value="{!res.Detailed_Product_Name__c}" onclick="window.location.href='{!res.Detail_Link__c}'" rendered="{!res.Detail_Link__c != null}" />

All Answers

Ratheven SivarajahRatheven Sivarajah
I have the condition part working need help with when you click on the button it should go to the value of !res.Detail_Link__c which has a URL

<apex:page controller="TechnologyProduct" lightningStylesheets="true">
    <apex:form>
    <apex:pageBlock>
    <apex:pageBlockSection title="Vitality Check Attributes">
            <apex:repeat value="{!TechnologyProduct}" var="res">
                  <apex:outputText value="{!res.Detailed_Product_Name__c}" /><br/>
                    <apex:outputPanel rendered="{!res.Detail_Link__c != null}" layout='none'>
                    <apex:commandButton value="{!res.Detailed_Product_Name__c}">
                        <apex:outputLink value="{!res.Detail_Link__c}" />
                    </apex:commandButton >
                </apex:outputPanel>
            </apex:repeat>
    </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>
Shri RajShri Raj
You can modify the apex:commandButton as follows:
<apex:commandButton value="{!res.Detailed_Product_Name__c}" onclick="window.location.href='{!res.Detail_Link__c}'" rendered="{!res.Detail_Link__c != null}" />
This was selected as the best answer
Ratheven SivarajahRatheven Sivarajah
Shri Raj you have been very helpful thank you!