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
asadimasadim 

Office Toolkit: SOQL query acting retard-like

Hi,

 

Can somebody explain why these work:

SELECT Id FROM object__c WHERE Id = 'asdf'

 

and

 

SELECT Id FROM object__c WHERE myField__c LIKE '%asdf%'

 

but this doesn't:

 

SELECT Id FROM object__c WHERE Id = 'asdf' OR myField__c LIKE '%asdf%'

Best Answer chosen by Admin (Salesforce Developers) 
foghornfoghorn

I ran a test with a query like yours (before the edit to protect the innocent), no thrown errors and the ret val was as expected.

 

var qr=sfApi.Query("select id from event where id = 'a valid id' OR subject LIKE '%bar%'" ,false)

 

I tried with v3 and got the same results.

 

Maybe try the above query in a different env? 

Copy this into a local html file and open with  IE.

 

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>

<script>
function testQuery()
{
    var msg = '';

    try
    {
        var sfApi = new ActiveXObject("SForceOfficeToolkit4.SForceSession4")
    
        sfApi.Login(<un>,<pw>);
        
        var qr=sfApi.Query("select id from event where id = '<valid id>' OR subject LIKE '%bar%'" ,false)        
        
        var e = new Enumerator(qr)
        
        while (!e.atEnd())
        {
            msg += e.item().Item("id").value
            e.moveNext()
        }
    }
    catch(exp)
    {
        alert(exp.message);
        alert(sfApi.ErrorMessage);
    }

    alert(msg)
}

</script>

</head>
<body>

<input type="button" value="Run Test" onclick="testQuery()" ID="Button1" NAME="Button1">


</body>
</html>

 

 

All Answers

foghornfoghorn
What error do you get on the fail case?
asadimasadim

So my query looks like this:

 

try
{
QueryResultSet4 qrs = _sfapi.Query(failingQuery, false);
}
catch (Exception) {}

 When I look at _sfapi it says NO_SF_ERROR in the Error field. The Exception however shows HRESULT E_FAIL but that's all. There's no other info on the error.

 

Message Edited by asadim on 03-11-2010 01:32 PM
foghornfoghorn

I ran a test with a query like yours (before the edit to protect the innocent), no thrown errors and the ret val was as expected.

 

var qr=sfApi.Query("select id from event where id = 'a valid id' OR subject LIKE '%bar%'" ,false)

 

I tried with v3 and got the same results.

 

Maybe try the above query in a different env? 

Copy this into a local html file and open with  IE.

 

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>

<script>
function testQuery()
{
    var msg = '';

    try
    {
        var sfApi = new ActiveXObject("SForceOfficeToolkit4.SForceSession4")
    
        sfApi.Login(<un>,<pw>);
        
        var qr=sfApi.Query("select id from event where id = '<valid id>' OR subject LIKE '%bar%'" ,false)        
        
        var e = new Enumerator(qr)
        
        while (!e.atEnd())
        {
            msg += e.item().Item("id").value
            e.moveNext()
        }
    }
    catch(exp)
    {
        alert(exp.message);
        alert(sfApi.ErrorMessage);
    }

    alert(msg)
}

</script>

</head>
<body>

<input type="button" value="Run Test" onclick="testQuery()" ID="Button1" NAME="Button1">


</body>
</html>

 

 

This was selected as the best answer
asadimasadim

Sweet deal! I didn't know that the JS version shows the error messages. Now I now what it was: cannot use non-Id value for comparing Id's. If you read my first post you see that I was comparing the Id field to some garbage text.

 

Thanks!!