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
irlrobinsirlrobins 

Apex:Datatable, not reading checkbox field correctly

Having an issue with correctly displaying the value of a checkbox field (on Case object) in a datatable.

 

Here is the table code in my VF Page:

<apex:dataTable value="{!CurrentInProgressCaseList}" var="c" width="100%">
	<apex:column >
		<apex:facet name="header">Request ID</apex:facet> 
		{!c.CaseNumber} 
	</apex:column>
	.
	.
	.
	<apex:column >
		<apex:facet name="header">Escalated</apex:facet>
		<c:CP_M2MEscalationComponent escalation="{!c.isEscalated}" />
	</apex:column>
	<apex:column >
		<apex:facet name="header">Raised By</apex:facet>
		{!c.CreatedBy.Name}
	</apex:column>
</apex:dataTable>

 Here is the apex code for the method that pulls in the data for the datatable:

public List<Case> getCurrentInProgressCaseList() {
	if (myInProgressCaseList ==null) {
		myInProgressCaseList = [Select CaseNumber, Customer_Status__c, isEscalated, CreatedDate, CreatedBy.Name from Case where (Customer_Status__c =:'Submitted' or Customer_Status__c =:'In Progress') and AccountId =: this.accountId ORDER BY CreatedDate desc];
	}
	for(Case c:myInProgressCaseList){
		System.debug(c.CaseNumber+': '+c.isEscalated);
	}
	return myInProgressCaseList;
}

 Now if I look in the debug logs for the System.debug statement above, I can clearly see my test case showing with the correct case number and isEscalated set to true.

 

But further down in my debug log I can clearly see the isEscalated value being passed to the component is set to false!

 

13:02:28.597 (597299000)|CODE_UNIT_STARTED|[EXTERNAL]|CP_M2MEscalationComponentController set(escalation,false)
13:02:28.597 (597316000)|SYSTEM_MODE_ENTER|true
13:02:28.597 (597343000)|CODE_UNIT_STARTED|[EXTERNAL]|CP_M2MEscalationComponentController set(escalation,false)
13:02:28.597 (597371000)|CODE_UNIT_FINISHED|CP_M2MEscalationComponentController set(escalation,false)
13:02:28.597 (597383000)|CODE_UNIT_FINISHED|CP_M2MEscalationComponentController set(escalation,false)

 And this is my issue. A case that clearly has its isEscalated field checked/set to true is being passed as false to my component.

 

My question is how/why??

Best Answer chosen by Admin (Salesforce Developers) 
irlrobinsirlrobins

It's always something simple.... Embarassingly enough, the issue was that the isEsclated field for several profiles was not set to Read. Once the profile access was corrected, the datatable displayed correctly.

 

Bit of a Doh! moment. Thanks all for your help anyway.

All Answers

Shashikant SharmaShashikant Sharma

Could you please check with using a boolean property with instad of boolean field. And use boolean property to assign values to object field.

irlrobinsirlrobins

Not quite sure what you mean?

1graham1graham

hi,

I'm having a similar problem.

Has anybody any idea how to get around this problem?

 

 

irlrobinsirlrobins

Bumping this as I'm still no further in getting this resolved.

 

Thanks!

R

SteveBowerSteveBower

I think I'd need to see the component controller code and vf to offer any help.  Best, Steve.

irlrobinsirlrobins

Component code:

 

<apex:component controller="CP_M2MEscalationComponentController" access="global">
    <apex:attribute name="escalation" description="escalation status" type="Boolean" assignTo="{!escalation}"/>
    <apex:outputText value="{!escalationString}" escape="false" />
</apex:component>

 

Corresponding Controller code: 

 

public class CP_M2MEscalationComponentController {
	
	public CP_M2MEscalationComponentController() {
		
	}
	
	public Boolean escalation {get;set;}

	
	public String getEscalationString(){
    	Boolean currentEscalation = this.escalation;
    	if(currentEscalation==true) {
    		return 'Yes';
    	}
        else if (currentEscalation==false){
        	return 'No';
        }
        else
        	return '';
	}

 

SteveBowerSteveBower


Offhand things look fairly correct to me.   

 

As near as I can see (regardless of other things in the code), you're retrieving the cases and isEscalated is part of that query.  You're passing that value into the component as an attribute.

 

The Component is declared as Access="global", and I'm not sure if the declaration of the Attribute should also be "global".  It seems to me like it should even if it's not required, so you might want to see if that makes a difference.   I'm not sure why you need this to be global in the first place, but that's a different issue.  You might be better served by removing the access tag from the component declaration unless you really are dealing with different namespaces, etc.

 

In the component you're assigning it to "escalated" which is of type Boolean, and the property looks right as well.

 

In your component controller, everything after this line:  public Boolean escalation {get;set;}   isn't needed because in your Component you can do:  

<apex:outputText value="{!if(escalation,'Yes', 'No')}" escape="false" />    I don't think that's a proble, but it's unnecessary.

 

 

So, I'm sorry, but I'm not sure why you've having a problem and I think it's time for more debugging if you're still having the issue.   

 

Best, Steve.

 

irlrobinsirlrobins

Thanks for your input Steve. Unfortunately, your code improvement has the same result.

 

I accept that our code is optimal, but we had tried your approach first and when that failed attempted the code pasted previously.

 

I'm starting to wonder if this is a SFDC bug....

irlrobinsirlrobins

It's always something simple.... Embarassingly enough, the issue was that the isEsclated field for several profiles was not set to Read. Once the profile access was corrected, the datatable displayed correctly.

 

Bit of a Doh! moment. Thanks all for your help anyway.

This was selected as the best answer