I have an outputlink in visualforce page that uses a custom field as a display name of link instead of Name
field. Link successfully displays when Name
is used. However, I tried using other custom field named Field1__c
, but link does not appear. Why is that?
By the way, Field1__c
is a formula text field concatenating the Name
standard field and a custom number field. Also, Field1__c
has a value when viewed in record detail page.
Visualforce:
<!--portion-->
<apex:pageBlockTable value="{!customList}" var="c" rendered="{!customList != null}">
<apex:column headerValue="Custom Record">
<apex:outputLink value="/{!c.Id}">{!c.Field1__c}</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
Controller
public class CustomController{
public List<Contact> contactList{get;set;}
public List<Custom__c> customList{get;set;}
public Account accRecord;
public CustomController(ApexPages.StandardController controller){
this.accRecord = (Account)controller.getRecord();
accRecord = [SELECT New_Field__c FROM Account WHERE Id=: accRecord.Id];
customList = new List<Custom__c>();
contactList = new List<Contact>();
if(accRecord.New_Field__c != null){
contactList = [SELECT Id,Name,Custom__c,Custom__r.Field1__c FROM Contact WHERE New_Field__c =: accRecord.New_Field__c];
if(contactList.size()==0){
contactList = null;
}else{
for(Contact c : contactList){
customList.add(new Custom__c(Id=c.Custom__c, Name = c.Custom__r.Custom_Name__c));
}
if(customList.size() == 0){
customList = null;
}
}
}
}
}
Modified Apex Class:
public class CustomController{
public List<Contact> contactList{get;set;}
public List<CustomWrapper> customList {get;set;}
public Account accRecord;
public CustomController(ApexPages.StandardController controller){
this.accRecord = (Account)controller.getRecord();
accRecord = [SELECT New_Field__c FROM Account WHERE Id=: accRecord.Id];
customList = new List<CustomWrapper>();
contactList = new List<Contact>();
if(accRecord.New_Field__c != null){
contactList = [SELECT Id,Name,Custom__c,Custom__r.Field1__c, Custom__r.Custom_Name__c FROM Contact WHERE New_Field__c =: accRecord.New_Field__c];
if(contactList.size()==0){
contactList = null;
}else{
Map<Id, CustomWrapper> customMap = new Map<Id, CustomWrapper>();
for(Contact c : contactList){
Custom__c customObj = new Custom__c(Id=c.Custom__c, Name = c.Custom__r.Custom_Name__c);
CustomWrapper wrapper = new CustomWrapper(customObj, c.Custom__r.Field1__c);
customMap.put(customObj.Id, wrapper);
}
customList = customMap.values();
if(customList.size() == 0){
customList = null;
}
}
}
}
public class CustomWrapper {
public Custom__c customObj {get; set;}
public String fieldValue {get; set;}
public CustomWrapper(Custom__c customObj, String fieldValue) {
this.customObj = customObj;
this.fieldValue = fieldValue;
}
}
}
{!c.Field__c}
and you want value fromField1__c
. Please update your post if that's not what your actual code looks like.Field1__c
visible in Field-Level Security to the user viewing the page?