You need to sign in to do that
Don't have an account?

output link url no longer exists
Greetings,
I am attempting something pretty simple. I have a list of accounts displayed and I want to make the account name clickable so that it goes to the corresponding record. I have the code implemented but when I click the account name, it goes to a page that says "ERROR URL NO LONGER EXISTS." Your help is greatly appreciated. My code is as follows:
***************************************VF Page******************************************************
<apex:page controller="NewController" >
<apex:form id="theForm">
<apex:pageBlock title="{!$User.FirstName}'s Accounts">
<apex:commandButton value="Save" action="{!save}" rerender="theForm,msg"/>
<apex:commandbutton value="Edit" action="{!edit}" rerender="theForm"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
<br></br><br></br><b>Note: Selecting "Recycle will auto-populate the DQ Reason ("No Longer Wish to Pursue").</b><p></p>
<apex:pageblocktable value="{!myaccounts}" var="acct">
<apex:column headervalue="Account">
<apex:outputlink value="/!{acct.id}">{!acct.Name}</apex:outputlink>
<apex:inputField value="{! acct.Name}" rendered="{!IsEditEnabled}"/>
</apex:column>
<apex:column headervalue="Recycle">
<apex:outputField value="{!acct.type}"/><br/>
<apex:inputfield value="{! acct.type}" rendered="{!IsEditEnabled}"/>
</apex:column>
<apex:column headervalue="DQ Reason">
<apex:outputField value="{!acct.DQ_Reason__c}" />
</apex:column>
</apex:pageblocktable>
<apex:pageMessages id="msg"/>
<p></p> <B> Note: Selecting "Recycle will auto-populate the DQ Reason ("No Longer Wish to Pursue").</B><br/><br/>
<apex:commandButton value="Save" action="{!save}" rerender="theForm,msg"/>
<apex:commandbutton value="Edit" action="{!edit}" rerender="theForm"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageblock>
</apex:form>
</apex:page>
***********************************************************Controller*********************************************************************
public class NewController {
public List<Account> myAccounts;
public Boolean isEditEnabled;
//Constructor called when page is accessed.
public NewController(){
myAccounts = new List<Account>();
isEditEnabled = false;
}
public List<Account> getMyAccounts(){
myAccounts = [select Id,name,type, dq_reason__c from Account WHERE type != 'Customer' and type != 'Disqualified' and (owner.id =: userinfo.getuserid()) order by name];
return myAccounts;
}
public PageReference edit() {
isEditEnabled = true;
return null;
}
public PageReference cancel() {
iseditenabled = false;
return null;
}
public PageReference save() {
for (account a: myaccounts){
if(a.type == 'Disqualified'){
apexpages.addmessage(new apexpages.message(ApexPages.severity.ERROR,'Invalid entry, "Disqualified" option not yet supported. Contact your administrator.'));
return null;
}
if(a.type == 'Recycle'){
a.dq_reason__c = 'No Longer Wish to Pursue';
}
else if(a.type != 'Recycle'){
a.dq_reason__c = '';
}
}
update myAccounts;
isEditEnabled = false;
return null;
}
public Boolean getIsEditEnabled(){
return isEditEnabled;
}
}
Hi josh.bergling,
The problem was the position of " ! " for the merge field.
It should be placed inside the { } for using merge fields in Visualforce pages.
<apex:outputlink value="/{!acct.id}">{!acct.Name}</apex:outputlink>
And avoid hardcoding the prefix url like "https://cs9.salesforce.com" for the links, as it might work fine in this particular org but not in other orgs in which this file is being deployed.
So, the right way is to provide relative URL as mentioned in the example above.
Thanks,
Neeraj
All Answers
I took another look and figured it out. The solution is as follows:
<apex:outputlink value="https://cs9.salesforce.com/{!acct.id}">{!acct.Name}</apex:outputlink>
Not sure if there is a best practice alternative to this?
Hi josh.bergling,
The problem was the position of " ! " for the merge field.
It should be placed inside the { } for using merge fields in Visualforce pages.
<apex:outputlink value="/{!acct.id}">{!acct.Name}</apex:outputlink>
And avoid hardcoding the prefix url like "https://cs9.salesforce.com" for the links, as it might work fine in this particular org but not in other orgs in which this file is being deployed.
So, the right way is to provide relative URL as mentioned in the example above.
Thanks,
Neeraj
Oh wow I can't believe I overlooked that. Thank you for your help.