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
SelvaSelva 

unable to set the field value which contains quote!

Hi,
 
I am trying to set the email value which contains single quote into Contact object's email field, but couldn't. Weblogic server thrown the following error. Is there any way to escape the single quote.
 
Code:
<xml-fragment xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><faultcode>sf:MALFORMED_QUERY</faultcode><faultstring>MALFORMED_QUERY: 
'dean.rose@gmail.com','brenden.o'connor@gmail.com','karen.davenport@gmail.com'
                                          ^ ERROR at Row:1:Column:963 expecting a right parentheses, found 'connor'</faultstring><detail><sf:fault xsi:type="sf:MalformedQueryFault" xmlns:sf="urn:fault.enterprise.soap.sforce.com"><sf:exceptionCode xmlns:sf="urn:fault.enterprise.soap.sforce.com">MALFORMED_QUERY</sf:exceptionCode><sf:exceptionMessage xmlns:sf="urn:fault.enterprise.soap.sforce.com">
'dean.rose@gmail.com','brenden.o'connor@gmail.com','karen.davenport@gmail.com'
                                          ^ ERROR at Row:1:Column:963 expecting a right parentheses, found 'connor'</sf:exceptionMessage><sf:row xmlns:sf="urn:fault.enterprise.soap.sforce.com">1</sf:row><sf:column xmlns:sf="urn:fault.enterprise.soap.sforce.com">963</sf:column></sf:fault></detail></xml-fragment>

 
I am using the following logic in JPD file to set the email value.
Code:
    private String getUserId(QueryResult qr, String emailId) throws Exception
    {
        String userId = "";
        
        for(int i=0; i < qr.getRecordsArray().length; i++)   
        {
            User usr = User.Factory.parse(qr.getRecordsArray(i).xmlText());
            
            if(usr.getEmail().equals(emailId))
            {
                userId = usr.getId();
                break;   
            }
        }
        return userId;
    } 
..................     
String usrId = getUserId(qrTeam,accountData[i].TEAM_EMAIL);
            
            if(!usrId.equalsIgnoreCase(""))
            {
                account.setOwnerId(usrId);
            }
.....................

 
Thanks.

 
SuperfellSuperfell
you have to esacpe ' in SOQL literal values, see the SOQL section of the API docs.
SelvaSelva
Code:
        String ownerQry = "Select Id, email from User where email in('0000'";
        for(int i=0; i<accountData.length; i++)
        {
            ownerQry += ",'" + accountData[i].TEAM_EMAIL+"'";
        }
       ownerQry += ")";
                
       QueryResult qrTeam = sfdcCtrl.query(ownerQry);

 
I am passing the email values via oracle DB table. accountData[i].TEAM_EMAIL contains the array of email values. how do i escape this single quote on this.
SuperfellSuperfell
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#replace(java.lang.CharSequence,%20java.lang.CharSequence)
SelvaSelva
Simon,
 
is there any method which can be passed as part of SOQL to escape the single quote? please guide me, as i couldn't find anything from java doc String to meet oor SFDC SOQL query
 
 
SuperfellSuperfell
ownerQry += ",'" + accountData[i].TEAM_EMAIL.Replace("'", "\'") +"'";
SelvaSelva

Thanks Simon for the hint. :-)

The following code worked out.

            ownerQry += ",'" + accountData[i].TEAM_EMAIL.replaceAll("'", "\\\\'") +"'";