You need to sign in to do that
Don't have an account?
Jonas Myhre
If statement help
Hi guys, this will be quite hard to explain, but i will try my best:
I have created a custom object called "Drift status" (currently a draft in the sandbox). This is created so we have an easy way to show our current issues to both our customers and internal users. I have then created an Apex class which gets this information and i use that as a visual force area home page component. It works fine if i have 1 active record (defined by a checkbox called "Visible"), if i have more or less it gives an error message. Im not fairly experienced in programming, so i need some help here. Ill post my code below:
Apex class:
global with sharing class driftsStatus{
public Drift_Status__c status{get;set;}
public driftsStatus() {
status= [select Comment__c,ETA_Fix__c,Service__c from Drift_Status__c where Visible__c = true];
}
}
So i need some guides on how to handle it if Visible__C count is less or more than 1. I would like to show all the records if there are more than 1, and a message if its 0 visible. Thanks alot
I have created a custom object called "Drift status" (currently a draft in the sandbox). This is created so we have an easy way to show our current issues to both our customers and internal users. I have then created an Apex class which gets this information and i use that as a visual force area home page component. It works fine if i have 1 active record (defined by a checkbox called "Visible"), if i have more or less it gives an error message. Im not fairly experienced in programming, so i need some help here. Ill post my code below:
Apex class:
global with sharing class driftsStatus{
public Drift_Status__c status{get;set;}
public driftsStatus() {
status= [select Comment__c,ETA_Fix__c,Service__c from Drift_Status__c where Visible__c = true];
}
}
So i need some guides on how to handle it if Visible__C count is less or more than 1. I would like to show all the records if there are more than 1, and a message if its 0 visible. Thanks alot
try with this code, it will work.
All Answers
Refer the below updated code:
"Drift_Status__c status" will contains only one record but if convert it into List<Drift_Status__c> than it will handle one or more records.
Now you can use this list in your Visualforce page and iterate it using pageBlockTable.
you can refer this link for PageBlockTable:
http://nanostuffs.com/Blog/?p=751
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
"Unknown property 'VisualforceArrayList.Service__c'
Error is in expression '{!status.Service__c}' in component <apex:pageBlockTable> in page newdriftstatus"
This is the visualforce component (iknow its horrible, please dont shoot me):
<apex:page controller="driftsStatus" showHeader="true">
<div align="left" width="550px">
<apex:pageblock title="Drift Status">
<apex:pageblocktable value="{!status.Service__c}" var="status">
<apex:column value="{!status.Service__c}"/>
<apex:column value="{!status.Comment__c}"/>
<apex:column value="{!status.ETA_Fix__c}"/>
<b>
<br> <apex:outputText value="Service: {!status.Service__c}"/></br>
<br> <apex:outputText value="Comment: {!status.Comment__c}"/> </br>
<br> <apex:outputText value="ETA Fix is: {!status.ETA_Fix__c}"/> </br>
</b>
</apex:pageblocktable>
</apex:pageblock>
</div>
</apex:page>
with
Error Error: Unknown property 'VisualforceArrayList.Service__c'
<apex:column value="{!status.Comment__c}"/>
<apex:column value="{!status.Service__c}"/>
<apex:column value="{!status.ETA_Fix__c}"/>
i put ETA_Fix__c on the top and the error message is: Error Error: Unknown property 'VisualforceArrayList.ETA_Fix__c'
global with sharing class driftsStatus{
public Drift_Status__c status{get;set;}
public driftsStatus() {
status= [select Comment__c,ETA_Fix__c,Service__c from Drift_Status__c where Visible__c = true];
}
}
VF page:
<apex:page controller="driftsStatus" showHeader="true">
<div align="left" width="550px">
<apex:pageblock title="Drift Status">
<apex:pageblocktable value="{!Status}" var="Status">
<apex:column value="{!status.ETA_Fix__c}"/>
<apex:column value="{!status.Comment__c}"/>
<apex:column value="{!status.Service__c}"/>
<b>
<br> <apex:outputText value="Service: {!status.Service__c}"/></br>
<br> <apex:outputText value="Comment: {!status.Comment__c}"/> </br>
<br> <apex:outputText value="ETA Fix is: {!status.ETA_Fix__c}"/> </br>
</b>
</apex:pageblocktable>
</apex:pageblock>
</div>
</apex:page>
I get this error message: Error: Unknown property 'VisualforceArrayList.Service__c'
try with this code, it will work.
Thanks alot for your time and patience, ill buy you a beer if we ever meet! Cheers!