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
hoomelhoomel 

Invoke a class variable in a VisualForce page

Hi,

 

i am currently trying to get some insight into developing for SalesForce with VisualForce and Apex.

 

I have built a VisualForce calendar which is still very static at the moment.

What i would like to do:

The calendar consists of 8 columns, one of those is a column for custom text, the others are the columns for the days.

Every day now has a static number of rows, which should represent special products.

I want to write a <apex:repeat> for that, so that there is a row for every product.

There is the first problem:  How do i invoke the result of a SOQL Query i wrote in a method of the controller? I created a variable in which the number products are stored.

 

I tried the following (with no success):

 

<apex:repeat value="{!count}" var="anzahl" id="foreachanz">

 

 

In this case, "count" is the name of the variable with the number of products.

The method which counts the entries is the following:

 

  	public Integer Anzahl() {
		Integer anz = [select count() from Leihanlage__c];
		return anz;
	}

 

How do i reference the variable in the apex:repeat?

Best Answer chosen by Admin (Salesforce Developers) 
JeeedeeeJeeedeee

I would suggest you to look into the apex:dataTable and apex:column tags for this purpose. Here an short example, in this case just to display a list of contacts.

 

 

public List<Contact> getContacts() { 
return [SELECT Id, Name, Account.Name, Phone, Email From Contact 
	    ORDER BY LastModifiedDate DESC LIMIT 10];
}


<apex:pageBlock title="Contacts Details">
	<apex:dataTable value="{!contacts}" var="c" cellpadding="2" headerClass="customHeader">
	    <apex:column>
	    	<apex:facet name="header">Name</apex:facet>{!c.name}	 
		<apex:param name="cid" value="{!c.id}"/>{!c.id}
	     </apex:column>
	   <apex:column >
		<apex:facet name="header">Account Name</apex:facet>
		{!c.account.name}
	    </apex:column>
	</apex:dataTable>
</apex:pageBlock>

 

 

All Answers

JeeedeeeJeeedeee

I would suggest you to look into the apex:dataTable and apex:column tags for this purpose. Here an short example, in this case just to display a list of contacts.

 

 

public List<Contact> getContacts() { 
return [SELECT Id, Name, Account.Name, Phone, Email From Contact 
	    ORDER BY LastModifiedDate DESC LIMIT 10];
}


<apex:pageBlock title="Contacts Details">
	<apex:dataTable value="{!contacts}" var="c" cellpadding="2" headerClass="customHeader">
	    <apex:column>
	    	<apex:facet name="header">Name</apex:facet>{!c.name}	 
		<apex:param name="cid" value="{!c.id}"/>{!c.id}
	     </apex:column>
	   <apex:column >
		<apex:facet name="header">Account Name</apex:facet>
		{!c.account.name}
	    </apex:column>
	</apex:dataTable>
</apex:pageBlock>

 

 

This was selected as the best answer
hoomelhoomel

That was exactly the hint that i needed.

Thanks!