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
hiroji1020hiroji1020 

子オブジェクトの繰り返し表示

VFで繰り返し表示はapex:repeatを使うと思いますが、カスタムオブジェクトの子オブジェクトを繰り返し表示する際のコーディングで困っています。

知っている人は教えてもらえると助かります。

 

カスタムオブジェクト: A

子オブジェクト: B

 

上記で、

<apex:repeat value="{!A.B}" var="line">

とやるとエラーになります。やり方を教えてください。

Best Answer chosen by Admin (Salesforce Developers) 
AdrianCCAdrianCC

If you don't mind me asking, what is the purpose of your VF page? Are you sure you need the custom code? Maybe a configuration solution is possible

 

What is your level of apex knowledge? If you go with a custom VF page you'll need either to use a standardController or a custom one. If you use a standard one you can use <apex:relatedList> to show the oppty line item easily(http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_relatedList.htm). If you use a custom controller you will need to extract from the DB with a soql the related records. You can show them in the page with either <apex:repeat> or apex:dataTable>

<apex:repeat value="{!opptyLineItemsList}" var="lineitem" >
       <!-- show the fields that you are interested here -->
</apex:repeat>

 

Were are you stuck right now? 

 

Thanks,

Adrian

All Answers

AdrianCCAdrianCC

Hello Hiroji!

 

Well it depends on how many records you have and how exactly do you want to show them. From your description I'm not sure wheter there are multiple records A, each with many related children B, OR just one A with multiple B. 

 

In case you have many As with many Bs I suggest creating a wrapper class in your controller. Something like:

...
public class Wrapper {
	public Object_A__c a 			{get; set;}
	public List<Object_B__c> bList  {get; set;}

	public Wrapper(Object_A__c a, List<Object_B__c> bList) {
		this.a = a;
		this.bList = bList;
	}
}
...

 You'll need to build a list of Wrapper in your controller's constructor so you can use them.

public List<Wrapper> wrapperList 		{get; set;}

 And you'll use this in your page like:

<apex:repeat value="{!wrapperList}" var="wrapper" >
	<apex:outputField value="{!wrapper.a.Id}" />
	<apex:repeat value="{!wrapper.bList}" var="b" >
		 <apex:outputField value="{!b.Id}" />
	</apex:repeat>
</apex:repeat>

 

HappyMonday,

Adrian

 

hiroji1020hiroji1020

Thanks Adrian.  Actually my case is only one A with many Bs. In face, I build apps with CRM and was using opportunity and oppotunitylines. Then I would change this to custom object and A is opportunity and B is oppotunitylines.

 

I would much appreciate if you can suggest with this condition.

 

Thank you so much,

Best regards

Hiroji

AdrianCCAdrianCC

If you don't mind me asking, what is the purpose of your VF page? Are you sure you need the custom code? Maybe a configuration solution is possible

 

What is your level of apex knowledge? If you go with a custom VF page you'll need either to use a standardController or a custom one. If you use a standard one you can use <apex:relatedList> to show the oppty line item easily(http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_relatedList.htm). If you use a custom controller you will need to extract from the DB with a soql the related records. You can show them in the page with either <apex:repeat> or apex:dataTable>

<apex:repeat value="{!opptyLineItemsList}" var="lineitem" >
       <!-- show the fields that you are interested here -->
</apex:repeat>

 

Were are you stuck right now? 

 

Thanks,

Adrian

This was selected as the best answer
hiroji1020hiroji1020

Thanks Adrian for your prompt response and I really appreciated.

I hesitate to say but my Aepx skill level is "Jounior".

 

My purpose of VF page is showing "qoute" with PDF format. I was using opportunity and standard controller when I build apps ISVforce. Thus, opportunitylines worked.

However, I need to change the apps from ISVforce to OEM. AS you know, OEM doesn't allow to use opportunites and need to re-build it into custom objects. Then I am restructuring quote VF.

 

Now, I understood that this will need the custom controller. Let me try it.

 

Lastly, I really appreciate your support.

 

Best regards

Hiroji