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
Deep067Deep067 

Query on picklist give exception using Special character

We have a custom field "Priority" of type Picklist in contact object.
If we execute query using Ajax  using sforce.connection.query in the VF page using special character then it gives an error in the case of picklist field

I give an example
Paste the following code in your org
For that first create a custom fild name Priority  of type Picklist Type in your Contact object having value "one", "two" ,"Folder~`!@#$%^$-&*()_+{}|":<>?/.,;'\][fsdsvghchx"
now create a contact in which Priority field having value "Folder~`!@#$%^$-&*()_+{}|":<>?/.,;'\][fsdsvghchx"
Page
-------
<apex:page standardController="contact" extensions="testclass" id="pg">
    <script src="/soap/ajax/16.0/connection.js" type="text/javascript"></script>
    <script src="/soap/ajax/16.0/apex.js" type="text/javascript"></script>    
    <apex:form id="frm">
        <p><b>text1</b></p><input type="text"  id="box"/>
        <input type="button" value="ClickMe" id="box12" onclick="callfun()"  />
        <apex:outputPanel id="inputhiddenfld2">
                <p><b>text2</b></p>
                <apex:inputText value="{!passdata}" id="hid2" />
        </apex:outputPanel>
        <script>
            sforce.connection.sessionId  = "{!$Api.Session_ID}";
            var check = '';
            function callfun()
            {
                try
                {
                    check = document.getElementById('box').value;
                    callname(check);
                }
                catch(err)
                {
                    alert(err);
                }
            }
            
            function calloncom()
            {
                try{       
                        var check1 = document.getElementById('pg:frm:hid2').value;
                        var query = "Select Id, LastName, FirstName From Contact where Contact.Priority__c like \'" +check1+"%\'";  //query2
                        var forerror = sforce.connection.query(query);
                        alert('forerror     '+forerror);
                    }
                catch(err)
                    {
                        alert('err   '+err);
                    }
            }
        </script>
        <apex:actionFunction name="callname" action="{!cont}" reRender="inputhiddenfld2,hid2" oncomplete="calloncom()">
            <apex:param name="passvalue" value="" assignTo="{!passvaluecont}"/>
        </apex:actionFunction>
    </apex:form>  
</apex:page>



class
-------

public with sharing class testclass
{
    public string passvaluecont{get; set;}
    public string passdata{get; set;}
    public testclass(ApexPages.StandardController controller)
    {
    }
    public void cont()
    {
        system.debug('-----------passvaluecont------------------'+passvaluecont);
        passdata = String.escapeSingleQuotes(passvaluecont.trim());
    }
}

Now Enter value "Folder~`!@#$%^$-&*()_+{}|":<>?/.,;'\][fsdsvghchx" in the text box named as "text1" and then click on button "ClickME"
it give an error, in normal case(without special character) it working fine
I just want to know how we handel the special character so that this query execute properly using Picklist having like operator
if any thing is not clear then please contact me on
Email- abhishek0674@gmail.com

AravindBabu512AravindBabu512

I guess this is not the breaking case for all the picklist values with any special characters, the problem I guess is with the single quote character. Based on the no of quotes you have the query is closed and left with few more characters after being closed. 

 

Thanks,

Aravind

Deep067Deep067

Hi