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
Achilles21Achilles21 

LookUp + VF Page + Related List

Hi All,

 

I am stuck at a requirement which I am desperate to get out from. Here is what I need:

 

There is a custom object Note__c that has a look up relation with Account. A VF Page is having lookup field on it that will let the user select the Account. Now whichever Account is selected, the relatedlist NOTES should be displayed on the same VF Page. I have used a button as of now that would be required to display the notes.

 

The code is : 

<apex:page standardController="Account" extensions="AccNoteExtension">

    <apex:form >
       Please Select an Account: <apex:inputField value="{!No.Account__c}"/>
       <br/>
       <apex:commandButton action="{!DisplayNotes}" value="Display Notes" reRender="myPanel"/>
    </apex:form>
    <apex:outputPanel id="myPanel">
    <apex:relatedList subject="{!ac}" list="Notes__r" rendered="{!$ObjectType.Note__c.accessible"/>
    </apex:outputPanel>
 
 
</apex:page>
            

 

public class AccNoteExtension{ 

     public AccNoteExtension(ApexPages.StandardController controller) 
     {
       
         
     }
     public Note__c No{get;set;}
        
    
     String s,str;
     Id myId;
     List <Account> ac;
      
     public List<Account> getAC()
     {
       
     return ac;
     }
    public PageReference DisplayNotes()
     {
       ac = [select id from Account where Name = 'Kevin Test Account'];
       system.debug('AC==========='+ac);
       return null;
     }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
ManjunathManjunath

Hi ,

 

Try the below code.

 

<apex:page standardController="Account" extensions="AccNoteExtension">
   <apex:form >
       Please Select an Account: <apex:inputField value="{!No.Accountid}" />
       <br/>
       <apex:commandButton action="{!DisplayNotes}" value="Display Notes" reRender="myPanel"/>
    </apex:form>
    <apex:outputPanel id="myPanel">
    <apex:relatedList subject="{!ac.id}" list="Notes__r" />
    </apex:outputPanel>
 </apex:page>

 

public class AccNoteExtension{ 
	public Note__c No{get; set;}
	Account ac;
	
	public AccNoteExtension(ApexPages.StandardController controller) 
	{
		No= new Note__c();
	}
	
	public Account getAC()
	{
		return ac;
	}
	
	public PageReference DisplayNotes()
	{
		ac = [select id from Account where id=:No.accountid];
		system.debug('AC==========='+ac);
		return null;
	}
	
}

 

I tried with contact object instead of Note__c object, It worked.

Make sure list attribute in the apex:releatedList has correct value.

 

Regards,