You need to sign in to do that
Don't have an account?

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>
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
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];
This query jast for exaple. All fields is right.
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.
I need to return to the apex::page array of specific sobject+integer.
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>
But instead of a list of different values, visualforce displaying the same thing.
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; } }
You genius !
Thank you very much.
Issue is solved now.