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 

special character using sforce.connection.query in visualforce page

We have a custom field "check" of type Picklist.
If we execute query using ajax and using sforce.connection.query in the VF page using special character like

var query = Select Id, LastName, FirstName From Contact where Contact.check__c like 'sdds!&*()_+{}|:<>?/.;][%';
var result = sforce.connection.query(query);

it give an error faultstring (give an error due to parentheses, curly braces, and square braces) other wise it is working fine
In controller it is also working fine with any special character
if we use any other field in place of "check__c" (or we can say other then picklist) then it is working fine for all the special character
can any one tell me how to execute this query properly for picklist type field(or how to handel parentheses, curly braces, and square braces for sforce.connection.query in the VF page)

Cloud CredenceCloud Credence

Hi,

 

Please try with the below statement.(Copy Paste)

 

var query = "Select Id, LastName, FirstName From Contact where Contact.check__c like 'sdds!&*()_+{}|:<>?/.;][%'";

 

Thanks

Deep067Deep067

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 it working fine(without special character)
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

Deep067Deep067

Thanks for reply bt that nt working I give u the complete code can u please check it