+ Start a Discussion
1111_forcecom1111_forcecom 

The page don't show the results

Hello every body, I don't know why can't display the results in my visualforce page. The page don't show error only is empty

Please help me, I try to display the contacts in a family with their benefits

 

This is my visualforce page

 

<apex:page StandardController="Sayana__c" extensions="familiaExtension">
  <apex:pageBlock title="Beneficios">
  <apex:pageBlockTable value="{!BeneficiosTodos}" var="beneficio" cellPadding="3" border="1" columnsWidth="50px,110px,60px,60px,230px" rules="all">
     <apex:column value="{!beneficio.Contacto__c}"/>
     <apex:column value="{!beneficio.fecha_entrega__c}"/>
  </apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

 

and this is the apex class

 

public class familiaExtension {

    private final Sayana__c sayana;
    private string idSayana;
    private final Contact contacto;    
    private final Beneficio__c[] beneficios;

    public familiaExtension(ApexPages.StandardController sayanaController) {
       this.sayana = (Sayana__c)sayanaController.getRecord();
       idSayana = sayana.id;
    }

    public List<Beneficio__c> getBeneficiosTodos()
    {
       for(Contact contact : [SELECT  id, Name from Contact where Sayana__c = :idSayana]){
           Beneficio__c[] beneficios  = contact.Beneficios__r;
       }       
       return beneficios;
    }
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
amilawamilaw

do you have only 1 contact for a given Sayana__c?

if not your logic is wrong.

any way 

 

use following

for(Contact contact : [SELECT  id, Name,(select Name FROM Beneficios__r) from Contact where Sayana__c = :idSayana])

 

All Answers

MehrialMehrial

Try this:

 

<apex:pageBlockTable value="{!beneficiosTodos}" var="beneficio" cellPadding="3" border="1" columnsWidth="50px,110px,60px,60px,230px" rules="all">

 

Also, try adding  a debug line.

nickwick76nickwick76

Hi, 

You are declaring a list 'benficios' as a final member variable.

Then in the for loop in method 'getBeneficiosTodos()' you are declaring a local variable with the same name. Since the declaration is in the foor loop and the for loop contains code that might not execute, I am not sure you are returning the value you want. I think you are returning the final variable which hasn't been set to a value. And in fact since this is a final variable it cannot be set anywhere else than in the declaration, the constructor or in an initialization code block.

 

Try this

public List<Beneficio__c> getBeneficiosTodos()
    {
		Beneficio__c[] beneficios;
		for(Contact contact : [SELECT  id, Name from Contact where Sayana__c = :idSayana]){
			beneficios  = contact.Beneficios__r;
       }       
       return beneficios;
    }

 Or remove the final keyword from the global variable and skip the declaration in the method.

Worth a try, but if this is not the case you should check that the SQOL query returns something.

 

HTH / Niklas

amilawamilaw

do you have only 1 contact for a given Sayana__c?

if not your logic is wrong.

any way 

 

use following

for(Contact contact : [SELECT  id, Name,(select Name FROM Beneficios__r) from Contact where Sayana__c = :idSayana])

 

This was selected as the best answer
1111_forcecom1111_forcecom
Thanks Amilaw, I tried the code and this is OK, my new question is how can I access in the visualforce page, the atributtes for Beneficios__r.

Please help me, this is new for me and i try to get used.

For the last, if you can say me how can I see the names for relations the custom objects.

Regards,
amilawamilaw

according to you visualforce 

 <apex:column value="{!beneficio.Contacto__c}"/>
     <apex:column value="{!beneficio.fecha_entrega__c}"/>

 

you have used Contacto__c and fecha_entrega__c of the Beneficio__c object. so you have to add

for(Contact contact : [SELECT  id, Name,(select Name,Contacto__c,fecha_entrega__c FROM Beneficios__r) from Contact where Sayana__c = :idSayana])

to the query.

 

what do you see when you open the page

1111_forcecom1111_forcecom
Really I'm sorry question again. I'm not use the FOR structure control, my code is:

The apex class

public class familiaExtension {

private final Sayana__c sayana;
private string idSayana;
private final Contact contacto;
private final Contact contactos;
private final Beneficio__c[] beneficios;

public familiaExtension(ApexPages.StandardController sayanaController) {
this.sayana = (Sayana__c)sayanaController.getRecord();
idSayana = sayana.id;
}

public List<Contact> getBeneficiosTodos()
{
//Beneficio__c[] beneficios = contact.Beneficios__r;
Contact[] contactos = [SELECT contact.Name, (SELECT Name,Contacto__c,fecha_entrega__c, Catalogo_Beneficio__c FROM Beneficios__r) FROM contact where Sayana__c = :idSayana ];
return contactos;
}
}

The visualforce page

<apex:page StandardController="Sayana__c" extensions="familiaExtension">
<apex:pageBlock title="Hello {!Sayana__c.Name}!">
You are viewing the {!Sayana__c.Name} Familia.
</apex:pageBlock>

<apex:pageBlock title="Contactos">
<apex:pageBlockTable value="{!BeneficiosTodos}" var="beneficio" cellPadding="3" border="1" columnsWidth="50px,110px,60px,60px,230px" rules="all">
<apex:column value="{!beneficio.name}"/>
<apex:column value="{!beneficio.Contact__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Please, help me.

Regards,