0

I am using salesforce's tooling API to get metadata changes for CustomField objects where were modified after a certain date. I am using the following code which is written in JAVA.

Q.> How to write a greater than "LastModifiedDate" criteria ?

    private static final String created_date_compared = "2016-02-01T00:00:00.000+0000";
String restURL;
        restURL = "/tooling/query/?q=Select+Id,DeveloperName,NamespacePrefix+From+CustomField+Where+LastModifiedDate+>+="+ created_date_compared;

I am getting the following error. If I remove the > sign the query works fine.

Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 144: https://na9.salesforce.com/services/data/v36.0/tooling/query/?q=Select+Id,DeveloperName,NamespacePrefix+From+CustomField+Where+LastModifiedDate+>+=2016-02-01T00:00:00.000+0000

0

Your example query has few confusing (for API) places, e.g.

LastModifiedDate+>+=

API reads this as "LastModifiedDate > =", note the space between ">" and "="

2016-02-01T00:00:00.000+0000

API reads this as

2016-02-01T00:00:00.000 0000

again, note the space before last "0000"

The simplest way is to write you query as normal and then URL Encode it, for example using http://meyerweb.com/eric/tools/dencoder/

Original query

Select Id,DeveloperName,NamespacePrefix From CustomField Where LastModifiedDate >=2016-02-01T00:00:00.000+0000

after using URL encoder becomes this

Select%20Id%2CDeveloperName%2CNamespacePrefix%20From%20CustomField%20Where%20LastModifiedDate%20%3E%3D2016-02-01T00%3A00%3A00.000%2B0000

Since you mentioned java, your case may look something like this:

String query = java.net.URLEncoder.encode("Select Id,DeveloperName,NamespacePrefix From CustomField Where LastModifiedDate >="+ created_date_compared);

which produces the same result as online encoder above.

and then full API url becomes this:

String restURL = "/tooling/query/?q=" + query;

which results in this

/services/data/v36.0/tooling/query/?q=Select+Id%2CDeveloperName%2CNamespacePrefix+From+CustomField+Where+LastModifiedDate+%3E%3D2016-02-01T00%3A00%3A00.000%2B0000

2

Need to have html encoding for >, <.

Please try below and see whether it works with &gt; instead of >

  private static final String created_date_compared = "2016-02-01T00:00:00.000+0000";

   String restURL;

    restURL = "/tooling/query/?q=Select+Id,DeveloperName,NamespacePrefix+From+CustomField+Where+LastModifiedDate+&gt;+="+ created_date_compared;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.