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
OlbrestOlbrest 

Please Help. Apex class returns array the same objects.

Hello.

 

Class getPicanto returns array of equal objects.

 

Like:

xx 1

xx 1 

xx 1 

......

 

Need:

xy 1

xk 0

xw 1

.....

 

Please Help!

 

 

Code:

 

 

global class LaFormica {

public class Ispanola
{
public Wine__c Wine {get; set;}
public Integer Sd {get; set;}
}


public List<Ispanola> getPicanto() {
Wine__c[] Wns = [SELECT Gellato From Wine__c];
Ispanola[] Navs = new Ispanola[Wns.size()];

Integer k = 0;
Integer l = 0;
Ispanola Obj = new Ispanola();

for (Wine__c Wn : Wns){
Obj.Wine = Wn;
Obj.Sd = k;
Navs[l] = Obj;

k++;
l++;
if (k == 2){k = 0;}
}

return Navs;
}

 

 

<apex:page cache="true" showHeader="false" sidebar="false" controller="LaFormica">
<apex:repeat value="{!Picanto}" var="Wine">
Name = {!Wine.Wine.Gellato} <br>
Val = {!Wine.Sd}
</apex:repeat>
</apex:page>

 

 

Message Edited by Olbrest on 02-20-2009 06:19 PM
Best Answer chosen by Admin (Salesforce Developers) 
VisualForceVisualForce

Hi..

      Here is my sample code .. This code retrives all records from account object and display the Name..

I have changed ur code Wine__c into Account and Galetto into Name.. U change ur own field and Object..

And I have changed class name into innerclass... U change into urs...

       In ur code, u have to create Ispanola instance in for loop. Then only it creates new instance every time.

I hope following code will help u...

Page: <apex:page cache="true" showHeader="false" sidebar="false" controller="innerclass"> <apex:repeat value="{!Picanto}" var="Wine">Name = {!Wine.Wine.Name} <br/>Val = {!Wine.Sd}<br/> </apex:repeat> </apex:page> Controller: global class innerclass { public class Ispanola { public Account Wine {get; set;} public Integer Sd {get; set;} } public List<Ispanola> getPicanto() { Account[] Wns = [SELECT Name From Account]; Ispanola[] Navs = new Ispanola[Wns.size()]; Integer k = 1; Integer l = 0; for (Account wn: Wns ) { Ispanola Obj = new Ispanola(); Obj.Wine = Wn; Obj.Sd = k; Navs.add(Obj); k++; if (k == 2){k = 0;} } return Navs; } }

 

All Answers

aalbertaalbert

Not sure if this is your issue, but I think the SOQL query is invalid. The select statement selects a field named Gellato , which as a custom field, is named Gellato__c. 

 

So try [select gellato__c from Wine__c];

 

 

 

OlbrestOlbrest

 

This query jast for exaple. All fields is right.

aalbertaalbert

So what is the specific issue?

You can wrap multiple objects into a single class and access the data through an apex:repeat component in the page. But not sure that is what you are asking for clarification.

OlbrestOlbrest

I need to return to the apex::page array of specific sobject+integer.

 

aalbertaalbert

Ah, I see. I changed the "var" attribute and then slightly restructured the Name and Val properties. You need to use the .dot syntax to navigate from the outer class of "Ispanola", and then access the Wine object and/or SD integer. 

 

 

<apex:page cache="true" showHeader="false" sidebar="false" controller="LaFormica"> <apex:repeat value="{!Picanto}" var="pic"> Name = {!pic.Wine.Gellato} <br> Val = {!pic.Sd} </apex:repeat> </apex:page>

 

 

 

OlbrestOlbrest
In my souce code I have the same as you wrote ( I make an error when wrote the first message ) I fixed it now.
 
But instead of a list of different values, visualforce displaying the same thing.
VisualForceVisualForce

Hi..

      Here is my sample code .. This code retrives all records from account object and display the Name..

I have changed ur code Wine__c into Account and Galetto into Name.. U change ur own field and Object..

And I have changed class name into innerclass... U change into urs...

       In ur code, u have to create Ispanola instance in for loop. Then only it creates new instance every time.

I hope following code will help u...

Page: <apex:page cache="true" showHeader="false" sidebar="false" controller="innerclass"> <apex:repeat value="{!Picanto}" var="Wine">Name = {!Wine.Wine.Name} <br/>Val = {!Wine.Sd}<br/> </apex:repeat> </apex:page> Controller: global class innerclass { public class Ispanola { public Account Wine {get; set;} public Integer Sd {get; set;} } public List<Ispanola> getPicanto() { Account[] Wns = [SELECT Name From Account]; Ispanola[] Navs = new Ispanola[Wns.size()]; Integer k = 1; Integer l = 0; for (Account wn: Wns ) { Ispanola Obj = new Ispanola(); Obj.Wine = Wn; Obj.Sd = k; Navs.add(Obj); k++; if (k == 2){k = 0;} } return Navs; } }

 

This was selected as the best answer
OlbrestOlbrest

You genius !

 

Thank you very much.

 

Issue is solved now.