1

I'm trying to figure out how to call Tooling API in the APEX class and get the data, Here is what I have done:

In Remote Site URL provide your salesforce instance.

Getting the following error:

USER_DEBUG [77]|DEBUG|response

Bad Message 400

reason:
Unknown Version

static String restGet(String endPoint, String method, String sid) {
    Http h = new Http();
    HttpRequest hr = new HttpRequest();
    hr.setHeader('Authorization', 'Bearer ' + sid);
    hr.setTimeout(60000);
    hr.setEndpoint(endPoint);
    hr.setMethod(method);
    HttpResponse r = h.send(hr);
    return r.getBody();
}

String baseURL = URL.getSalesforceBaseUrl().toExternalForm();

String body = restGet( baseURL +
'/services/data/v47.0/tooling/query?'+
'q=SELECT Id, MasterLabel, Metadata FROM Flow WHERE MasterLabel = EncodingUtil.urlEncode(\'TEST FLOW\', \'UTF-8\') AND Status = EncodingUtil.urlEncode(\'Active\', \'UTF-8\') ORDER BY versionnumber',
'GET', UserInfo.getSessionId() );

System.debug(LoggingLevel.ERROR, '@@@ v: ' + body );
String metadata = body.substringBetween('"Metadata":{"', '}}]}');
System.debug(LoggingLevel.ERROR, '@@@ v: ' + metadata );
4

You are sending the literal string EncodingUtil.urlEncode() instead of calling the method to build a string. You want:

String body = restGet( baseURL +
'/services/data/v47.0/tooling/query?'+
'q=SELECT Id, MasterLabel, Metadata FROM Flow WHERE MasterLabel = ' + EncodingUtil.urlEncode('TEST FLOW', 'UTF-8') + ' AND Status = ' + EncodingUtil.urlEncode('Active', 'UTF-8') + ' ORDER BY versionnumber',
'GET', UserInfo.getSessionId() );
| improve this answer | |

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.