+ Start a Discussion
Jezza83Jezza83 

Conversion Error setting value 'x' for '#{y}'.

I am relatively new to APEX and Visualforce and I am developing a VF page so users can search for records of a custom object and modify records either individually or en masse. I have created the VF page and Controller Extension and everything is working correctly except one part; I am trying to allow users to select multiple values to search a single field but I am receiving an error;

Error:

Conversion Error setting value 'NSW VIC' for '#{RelationshipManagerState}'

 

Any help with this problem would be greatly appreciated.

 

The section of the Controller Extension dealing with the dynamic SOQL is below with the sections I believe are giving me trouble highlighted in red;

 

 

/* Get Search Criteria Values */

public String getRelationshipRoleType() {
return null;
}

public String getRelationshipManagerID() {
return null;
}

public String getRelationshipManagerState() {
return null;
}


public String getAccountType() {
return null;
}

public String getAccountState() {
return null;
}

public String getLicenseeName() {
return null;
}

public String getServiceType() {
return null;
}

/* Set Results List */

public List<Panel_Relationship__c> result = new List<Panel_Relationship__c>();
private String RelationshipRoleType;
private String RelationshipManagerID;
private String RelationshipManagerState;
private String AccountType;
private String AccountState;
private String LicenseeName;
private String ServiceType;
public PanelMaintanenceExtension(){
}

public List<Panel_Relationship__c> getResult() {
return result;
}

/* Set Search Criteria Values */

public void setRelationshipRoleType(String RelationshipRoleType) {
this.RelationshipRoleType = RelationshipRoleType;
}

public void setRelationshipManagerID(String RelationshipManagerID) {
this.RelationshipManagerID = RelationshipManagerID;
}


public void setRelationshipManagerState(String RelationshipManagerState) {
this.RelationshipManagerState = RelationshipManagerState;
}

public void setAccountType(String AccountType) {
this.AccountType = AccountType;
}

public void setAccountState(String AccountState) {
this.AccountState = AccountState;
}

public void setLicenseeName(String LicenseeName) {
this.LicenseeName = LicenseeName;
}

public void setServiceType(String ServiceType) {
this.ServiceType = ServiceType;
}

/* Apply Search Criteria Values to Query and Run Query */

public void search() {
String queryRelationshipRoleType = RelationshipRoleType + '%';
String queryRelationshipManagerID = RelationshipManagerID + '%' ;
String queryRelationshipManagerState = RelationshipManagerState + '%';
String queryAccountType = AccountType;
String queryAccountState = AccountState = '%';
String queryLicenseeName = LicenseeName + '%';
String queryServiceType = ServiceType = '%';
result = [
SELECT Name, Role_Type__c, Relationship_Manager_ID__c, Manager_State__c,
Relationship_Manager_Name__c, Account_ID__c, Account_Name__c, Account_State__c,
Service_Type__c, Commencement_Date__c, LastModifiedDate, LastModifiedByID
FROM Panel_Relationship__c
WHERE Role_Type__c like :queryRelationshipRoleType
AND Relationship_Manager_ID__c like :queryRelationshipManagerID
AND Relationship_Manager_State__c like :queryRelationshipManagerState
AND Account_Type__c = :queryAccountType
AND Account_State__c like :queryAccountState
AND Licensee_Name__c like :queryLicenseeName
AND Service_Type__c like :queryServiceType ];

}

 

and the Visualforce Page is;

 

<apex:page standardController="Panel_Relationship__c" extensions="PanelMaintanenceExtension" id="page" cache="true" recordSetVar="unused" tabStyle="Panel_Maintenance__tab" showHeader="True" sidebar="True" title="Panel Maintenance">

<apex:form id="MassPanelUpdate">

<!-- Javascript Allows All Search Results to be Selected when Master Checkbox Checked or Deselect All Search Results when Master Checkbox Unchecked -->

<script type="text/javascript">
function customSelectChecked(form, element_name, value)
{
var i = 0;
for (i = 0; i < form.elements.length; i++) {
if (form.elements[i].name.search('selected') > 0 && form.elements[i].disabled == false) {
form.elements[i].checked = value;
}
}
}
function customSelectAllOrNoneByCheckbox(form, element_name, control)
{ customSelectChecked(form, element_name, control.checked); }
</script>

<apex:SectionHeader title="Panel Maintenance" subtitle="Search Page" />

<!-- Holds Search Criteria -->

<apex:pageBlock title="Search Criteria">

<apex:pageBlockSection title="Relationship Manager" columns="2" >

<apex:pageBlockSectionItem >Relationship Role Type
<apex:selectList value="{!RelationshipRoleType}" multiselect="false" size="1">
<apex:selectOption itemValue="BDM" />
<apex:selectOption itemValue="BDC" />
<apex:selectOption itemValue="PDM" />
<apex:selectOption itemValue="PDC" />
<apex:selectOption itemValue="NAM" />
</apex:selectList>

</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >Relationship Manager ID
<apex:inputText value="{!RelationshipManagerID}" />
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >Relationship Manager State

<apex:selectCheckboxes value="{!RelationshipManagerState}" >
<apex:selectOption itemValue="NSW" itemLabel="NSW" />
<apex:selectOption itemValue="VIC" itemLabel="VIC" />
<apex:selectOption itemValue="ACT" itemLabel="ACT" />
<apex:selectOption itemValue="QLD" itemLabel="QLD" />
<apex:selectOption itemValue="SA" itemLabel="SA" />
<apex:selectOption itemValue="WA" itemLabel="WA" />
<apex:selectOption itemValue="TAS" itemLabel="TAS" />
<apex:selectOption itemValue="NT" itemLabel="NT" />
</apex:selectCheckboxes>

</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Relationship Manager Name
<apex:inputField value="{!Panel_Relationship__c.Relationship_Manager_Name__c}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockSection title="Account Details" columns="2">
<apex:pageBlockSectionItem >Account Type *
<apex:selectList value="{!AccountType}" multiselect="false" size="1" required="True">
<apex:selectOption itemValue="Adviser" />
<apex:selectOption itemValue="Practice" />
<apex:selectOption itemValue="Licensee" />
</apex:selectList>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >Account Name
<apex:inputField value="{!Panel_Relationship__c.Account_Name__c}" />
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >Account State
<apex:selectCheckboxes value="{!AccountState}" >
<apex:selectOption itemValue="NSW" itemLabel="NSW" />
<apex:selectOption itemValue="QLD" itemLabel="QLD" />
<apex:selectOption itemValue="VIC" itemLabel="VIC" />
<apex:selectOption itemValue="ACT" itemLabel="ACT" />
<apex:selectOption itemValue="SA" itemLabel="SA" />
<apex:selectOption itemValue="WA" itemLabel="WA" />
<apex:selectOption itemValue="TAS" itemLabel="TAS" />
<apex:selectOption itemValue="NT" itemLabel="NT" />
</apex:selectCheckboxes>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockSection title="Licensee Details" columns="2">
<apex:pageBlockSectionItem >Licensee Name
<apex:inputText value="{!LicenseeName}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockSection title="Relationship Details" columns="2">
<apex:pageBlockSectionItem >Service Type
<apex:selectList value="{!ServiceType}" multiselect="false" size="1">
<apex:selectOption itemValue="Primary" />
<apex:selectOption itemValue="Secondary" />
</apex:selectList>
</apex:pageBlockSectionItem><br/>
</apex:pageBlockSection>

<apex:pageBlockButtons >
<apex:commandButton action="{!search}" value="Search" id="searchBtn"/>
</apex:pageBlockButtons>

</apex:pageBlock>

<!-- Display any Page Success or Error Messages -->

<apex:pageMessages ></apex:pageMessages>

<!-- Display Search Results -->

<apex:pageBlock title="Search Results" id="Results">

<apex:dataTable value="{!result}" var="Panel_Relationship__c" id="data" cellPadding="4" border="0" rowClasses="odd,even"
onrowmouseout="if (window.hiOff){hiOff(this);}" onrowmouseover="if (window.hiOn){hiOn(this);}">
<apex:facet name="caption"></apex:facet>
<apex:facet name="header"></apex:facet>
<apex:column >

<apex:facet name="header">

<!-- Allow All Search Results to be Selected when Checked or Deselect All Search Results when Unchecked -->

<apex:inputCheckbox id="selectall" onclick="javascript&colon;customSelectAllOrNoneByCheckbox(document.forms['Page:MassPanelUpdate'],'Page:MassPanelUpdate:Results:data:', this);"/></apex:facet>

<!-- Show Selected Search Results and Allow to Select or Deselect any Results Individually -->

<apex:inputCheckbox id="selected" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Account Name</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.Account_Name__c}" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Account ID</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.Account_ID__c}" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Account State</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.Account_State__c}" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Role Type</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.Role_Type__c}" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Manager Name</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.Relationship_Manager_Name__c}" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Manager State</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.Manager_State__c}" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Service Type</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.Service_Type__c}" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Commencement Date</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.Commencement_Date__c}"/>
</apex:column>

<apex:column >
<apex:facet name="header"><u>Last Modified Date</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.LastModifiedDate}" />
</apex:column>

<apex:column >
<apex:facet name="header"><u>Last Modified By</u></apex:facet>
<apex:outputField value="{!Panel_Relationship__c.LastModifiedByID}" />
</apex:column>

</apex:dataTable>

<apex:pageBlockButtons >
<apex:commandButton action="{!Remove}" styleClass="Button" value="Remove"/>
<apex:commandButton action="{!Add}" styleClass="Button" value="Add"/>
<apex:commandButton action="{!Change}" styleClass="Button" value="Change"/>
</apex:pageBlockButtons>

</apex:pageBlock>

</apex:form>

</apex:page>

 

Thanks in advance for any help with this and please feel free to comment on how I have structured my code as I have seen the getters and setters strucutred very differently in some code examples I have seen :)

 

 

 

Message Edited by JDog on 01-03-2010 06:34 PM
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

A few too many  quotes in there - I was assuming state would be a variable rather than literals.

 

So you'd need something like:

 

 

AND Relationship_Manager_State__c IN (\'NSW\', \'QLD\', '\VIC\')';

 

 my code was an attempt to create this string programatically from an array of strings.  Hopefully you get the picture.

 

All Answers

bob_buzzardbob_buzzard
Have you narrowed down where the error is coming from?  My guess would be that the dynamic SOQL doesn't like the binding for RelationshipManagerState - what type of field is this on the sObject?  
Jezza83Jezza83

Thanks Bob the dynamic SOQL didn't like the binding I was using. I found another post with a similar problem and I corrected the binding (below);

 

 

public with sharing class PanelMaintanenceExtension {

    public PanelMaintanenceExtension(ApexPages.StandardSetController controller) {
    
    }
    
    public PanelMaintanenceExtension(ApexPages.StandardController controller) {
    
    }
    
    /* Page References */
    
    public PageReference Remove() {
    return Page.Remove_Panel_Page;
    }
    
    public PageReference Add() {
    return Page.Add_Panel_Page;
    }
    
    public PageReference Change() {
    return Page.Change_Panel_Page;
    }
    
    /* Get and Set Manager States Search Criteria Values */

    public String [] m_lstVals = new String[]{};
    
    public void setManagerState (String [] lstVals){
    m_lstVals = lstVals;
    }

    public String [] getManagerState (){
    return m_lstVals;
    }
   
    public List<SelectOption> getManagerStates(){
    List<selectoption> lstManagerState = new List<SelectOption>();
    lstManagerState.add(new SelectOption ('NSW', 'NSW'));
    lstManagerState.add(new SelectOption ('ACT', 'ACT'));
    lstManagerState.add(new SelectOption ('VIC', 'VIC'));
    lstManagerState.add(new SelectOption ('QLD', 'QLD'));
    lstManagerState.add(new SelectOption ('WA', 'WA'));
    lstManagerState.add(new SelectOption ('SA', 'SA'));
    lstManagerState.add(new SelectOption ('TAS', 'TAS'));
    lstManagerState.add(new SelectOption ('NT', 'NT'));
    return lstManagerState;
    }

    
    /* Get and Set Acount States Search Criteria Values */
    
    public String [] a_lstVals = new String[]{};
    
    public void setAccountState (String [] lstVals){
    a_lstVals = lstVals;
    }

    public String [] getAccountState (){
    return a_lstVals;
    }
   
    public List<SelectOption> getAccountStates(){
    List<selectoption> lstAccountState = new List<SelectOption>();
    lstAccountState.add(new SelectOption ('NSW', 'NSW'));
    lstAccountState.add(new SelectOption ('ACT', 'ACT'));
    lstAccountState.add(new SelectOption ('VIC', 'VIC'));
    lstAccountState.add(new SelectOption ('QLD', 'QLD'));
    lstAccountState.add(new SelectOption ('WA', 'WA'));
    lstAccountState.add(new SelectOption ('SA', 'SA'));
    lstAccountState.add(new SelectOption ('TAS', 'TAS'));
    lstAccountState.add(new SelectOption ('NT', 'NT'));
    return lstAccountState;
    }
    
    /* Get All Other Search Criteria Values */

    public String getRelationshipRoleType() {             
    return null;
    }
    
    public String getRelationshipManagerID() {             
    return null;
    }
    
    public String getAccountType() {             
    return null;
    }
    
    public String getLicenseeName() {             
    return null;
    }
    
    public String getAFSLNumber() {             
    return null;
    }
    
    public String getServiceType() {             
    return null;
    }

    /* Set Results List */
          
    public List<Panel_Relationship__c> result = new List<Panel_Relationship__c>();   
    private String RelationshipRoleType;
    private String RelationshipManagerID;
    private String AccountType;
    private String AccountStates;
    private String LicenseeName;
    private String AFSLNumber;
    private String ServiceType;
    private String ManagerStates;
    public PanelMaintanenceExtension(){   
    }
   
    public List<Panel_Relationship__c> getResult() {
    return result;
    }
   
    /* Set All Other Search Criteria Values */
   
    public void setRelationshipRoleType(String RelationshipRoleType) { 
    this.RelationshipRoleType = RelationshipRoleType; 
    }
    
    public void setRelationshipManagerID(String RelationshipManagerID) { 
    this.RelationshipManagerID = RelationshipManagerID;
    }
    
    public void setAccountType(String AccountType) { 
    this.AccountType = AccountType; 
    }
    
    public void setLicenseeName(String LicenseeName) { 
    this.LicenseeName = LicenseeName; 
    }
    
    public void setAFSLNumber(String AFSLNumber) { 
    this.AFSLNumber = AFSLNumber; 
    }
    
    public void setServiceType(String ServiceType) { 
    this.ServiceType = ServiceType; 
    }
    
    /* Apply Search Criteria Values to Query and Run Query */    
    
    public void search() {   
    String queryRelationshipRoleType = RelationshipRoleType + '%';
    String queryRelationshipManagerID = RelationshipManagerID + '%' ;
    String queryManagerStates = ManagerStates = '%';
    String queryAccountType = AccountType;
    String queryAccountStates = AccountStates = '%';
    String queryLicenseeName = LicenseeName + '%';
    String queryAFSLNumber = AFSLNumber + '%';
    String queryServiceType = ServiceType + '%';
    
    result = [
    SELECT Name, Role_Type__c, Relationship_Manager_ID__c, Relationship_Manager_State__c, 
    Relationship_Manager_Name__c, Account_Name__c, Account_State__c, AFSL_Number__c,
    Service_Type__c, Commencement_Date__c, LastModifiedDate, LastModifiedByID 
    FROM Panel_Relationship__c 
    WHERE Role_Type__c like :queryRelationshipRoleType
    AND Relationship_Manager_ID__c like :queryRelationshipManagerID 
    AND Relationship_Manager_State__c like :queryManagerStates 
    AND Account_Type__c = :queryAccountType 
    AND Account_State__c like :queryAccountStates
    AND Licensee_Name__c like :queryLicenseeName
    AND AFSL_Number__c like :queryAFSLNumber
    AND Service_Type__c like :queryServiceType ];
    
    }

 

 and changed the vf to reflect this change;

 

<apex:pageBlockSectionItem >Manager State

<apex:selectCheckboxes value="{!ManagerState}" >
<apex:selectOptions value="{!ManagerStates}"/>
</apex:selectCheckboxes>

</apex:pageBlockSectionItem>

and I no longer am receiving the error however I am now faced with another problem that the result is ignoring whatever is selected on the vf page and not passing the values into my SOQL query. I tried changingmy SOQL query to below;

 

String queryManagerStates = ManagerStates = '%';

to

String queryManagerStates = ManagerStates + '%';

 

but then the SOQL query returns no results.

 

The field type on the sObject is a cross object formula which is dragging the Account.Billing_State through onto the Panel_Relationships__c record - is this a problem ? Should I be querying the Account.Billing_State directly instead of the formula field directly ?

 

Thanks in advance for your reply - Jeremy.

 

 

 

 

Message Edited by JDog on 04-01-2010 11:05 PM
bob_buzzardbob_buzzard

Looking at the latest code, I can't see anything that ties the selected items to the ManagerStates variable.

 

Using the following:

 

 

String queryManagerStates = ManagerStates = '%';

 

 assigns '%' to ManagerStates and queryManagerStates at the same time.  However, this has nothing to do with your selected checkboxes, which are stored in a string array.

That said, I'm not sure what you are attempting will work anyway.  If the user can select more than one checkbox, you will end up with a bound variable that is 'NSW VIC%' - which means the query will match on all records where the formula field starts with 'NSW VIC'.  I'm guessing that you won't have any of these, and what you actually want to do is find all those records where the formula field contains 'NSW' or 'VIC'.  Or have I misunderstood what you are trying to do.

 

 

Jezza83Jezza83

Thanks for that and yes you have understood correctly what I am trying to do e.g. search for all records with Manager States = to VIC OR NSW(the value of Manager State would be one or the other - never both) - I have obviously misunderstood the SOQL syntax as I thought that the :like attribute meant "contains" not "starts with" and that my code would separate the individual values that someone selected so that the query read; Manager State contains NSW or VIC

bob_buzzardbob_buzzard

You'll want to use the IN operator - this checks if the value from the record matches any one of a set.  I think you'll have to build the clause manually rather than binding it though.

 

 

Something like:

 

 

String inPart=''; for (String state : states) { inPart+=', \'' + state + '\''; } Then, in the select statement, replace your existing equality operator and binding with: IN (' + inPart.substring(1) + ')';

 

 

 

  where states is your array of selected strings.

 

Jezza83Jezza83
Thanks for that - will give it a go and get back to you.
Jezza83Jezza83

Hi Bob - hope you've been keeping well. Have just got back from a well deserved break :)

 

I have tried what you suggested however I am getting an error "line breaks not allowed in strings", however I may have misinterpreted your reply. Thanks again for your assistance with this.

 

 

String inPart=''; { for (String state : states) { inPart+=', \'' + NSW + QLD + VIC + WA + SA + ACT + TAS + NT + '\''; } } and in my SELECT I am using; AND Relationship_Manager_State__c IN (' + inPart.substring(1) + ')';

 

 

 

bob_buzzardbob_buzzard

A few too many  quotes in there - I was assuming state would be a variable rather than literals.

 

So you'd need something like:

 

 

AND Relationship_Manager_State__c IN (\'NSW\', \'QLD\', '\VIC\')';

 

 my code was an attempt to create this string programatically from an array of strings.  Hopefully you get the picture.

 

This was selected as the best answer
Jezza83Jezza83
Cheers thanks or that worked a treat