1

I have a custom object call Account_Addresses__c that has a master-detail relationship to the Account record. I am trying to create a Visualforce page that will be embedded in the Account Detail to show the related list's records and eventually allow users to inline edit them. I have the controller and Visualforce below. Both render without error, but nothing shows on the Account even though there are records in the related list. What am I missing?

Visualforce:

<apex:page standardController="Account" extensions="AcctAddresses" tabStyle="Account" >
    <apex:pageMessages />
    
<apex:form >                 
TESTING
        <apex:pageblock id="AddressList"> 

          <div style="margin-left: 30%;"><apex:commandLink value="New Address" action="{!newAddress}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;"/></div> 

            <br/> 

            <apex:pageBlockTable value="{!addresses}" var="addr" rendered="{!NOT(ISNULL(addresses))}">                 

                <apex:column HeaderValue="Action" width="60"> 

                    <apex:commandLink value="Edit" style="color:#015ba7;" action="{!editAddress}" target="_parent" ><apex:param value="{!addr.id}" name="AddrId"/> 

                    </apex:commandLink> 

                    &nbsp;|&nbsp; 

                    <apex:commandLink value="Del" onclick="return confirm('Are you sure you want to delet this address?')" style="color:#015ba7;" action="{!deleteAddress}" target="_parent"><apex:param value="{!addr.id}" name="AddrId"/> 

                    </apex:commandLink> 

                </apex:column> 

                <apex:column value="{!addr.Primary__c}"/> 
                <apex:column value="{!addr.Street__c}"/> 
                <apex:column value="{!addr.City__c}"/> 
                <apex:column value="{!addr.State__c}"/> 
                <apex:column value="{!addr.Zip_Postal_Code__c}"/>
                <apex:column value="{!addr.Country__c}"/> 

            </apex:pageBlockTable>            

            <apex:outputLabel value="No records to display" rendered="{!(ISNULL(addresses))}" styleClass="noRowsHeader"></apex:outputLabel> 

        </apex:pageblock> 

    </apex:form>     
    
</apex:page>

Controller:

public class AcctAddresses {     

    public List<Account_Addresses__c> addresses{get;set;} 

    public Account accounts {get;set;} 

    public Account acct {get;set;} 

     

    //Constructor 

    public AcctAddresses(ApexPages.StandardController controller) { 

        acct = (account)controller.getRecord();      

        accounts = [SELECT Id
                    FROM account
                    WHERE id=: acct.id LIMIT 1]; 

        addresses = [SELECT Id, Primary__c, Street__c, City__c, State__c, Zip_Postal_Code__c, Country__c, Account__c
                    FROM Account_Addresses__c
                    WHERE Account__r.Id = :accounts.id ORDER BY Primary__c, State__c];     

} 

    //This method is to create a new address while clicking on the Add Address button 

    public pageReference newAddress(){  

        pageReference pageRef = new pageReference(URL.getSalesforceBaseUrl().toExternalForm() + '/003/e?&retURL=' + accounts.id);  

        return pageRef; 

    } 

    //This method is to edit the existing contact record while clicking the Edit link 

    public pageReference editAddress(){  

        String contactId = Apexpages.currentpage().getParameters().get('Account_Addresses__c.Id');  

        pageReference pageRef = new pageReference(URL.getSalesforceBaseUrl().toExternalForm() + '/' + Account_Addresses__c.Id + '/e?retURL=' + accounts.id);  

        return pageRef;  

    }    


 //This method is to delete the contact record while clicking the Del link 

    public pageReference deleteAddress(){  

        String AcctAddId = Apexpages.currentpage().getParameters().get('Account_addresses__c.Id');  

        Account_addresses__c AddressList = [SELECT Id FROM Account_addresses__c WHERE id = : AcctAddId LIMIT 1]; 

        delete AddressList; 

        String baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); 

        PageReference redirectPage = new PageReference(baseUrl+'/'+accounts.id); 

        return redirectPage;  

    }   

}

3 Answers 3

2

If you are you trying to view the VF page on the Account page layout in Lightning Experience, you'll need to edit the VF page under setup and check the "Available for Lightning Experience, Lightning Communities, and the mobile app" checkbox:

https://help.salesforce.com/articleView?id=community_builder_use_visualforce.htm

1
  • Thanks. I do have that checked, but I am trying to view in Classic right now.
    – J. Neilan
    Aug 31, 2020 at 1:22
2

Apparently, this is an issue related to the browser cookies. It does not work for me in Safari, but the page does appear in Chrome. Thanks for the answers.

1

This could be because if the rendered tag you have in the pageblock table code!

Change the rendered tag to below

rendered="{! IF(addresses.size > 0, true, false)}">

Also debug the below query to see if records are returned

I will use Account__c instead of relationship Account__r but should not impact the results though

addresses = [SELECT Id, Primary__c, Street__c, City__c, State__c, Zip_Postal_Code__c, Country__c, Account__c FROM Account_Addresses__c WHERE Account__c = :accounts.id ORDER BY Primary__c, State__c]
4
  • Thanks. I made that change, but it did not do anything.
    – J. Neilan
    Aug 31, 2020 at 0:56
  • Can you check if the queries are running fine using system.debug in your controller methods Aug 31, 2020 at 1:04
  • Yes, I ran System.Debug and the queries are returning data as expected. It seems the page is just not loading as I even entered straight text and nothing appeared.
    – J. Neilan
    Aug 31, 2020 at 1:21
  • Any errors on browser console? Aug 31, 2020 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.