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
Travis HendrixTravis Hendrix 

Query Validation Rules

I am trying to query validation rules in apex.  I was trying to do it with a callout but keep getting an error: No operation available for request.  Here is the code I am using.
HTTP h = new HTTP();
HTTPRequest req = new HTTPRequest();
req.setMethod('GET');
req.setHeader('Content-Type', 'text/xml');
req.setHeader('SOAPAction', 'ValidationRule');



String b = '';
b += '<?xml version="1.0" ?>';
b += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:metadata.tooling.soap.sforce.com">';
b += '<soapenv:Header>';
b += '<urn:SessionHeader>';
b += '<urn:sessionId>'+UserInfo.getSessionId()+'</urn:sessionId>';
b += '</urn:SessionHeader>';
b += '</soapenv:Header>';
b += '<soapenv:Body>';
b += '<urn:ValidationRule>';
b += '</urn:ValidationRule>';
b += '</soapenv:Body>';
b += '</soapenv:Envelope>';

req.setBody(b);
req.setCompressed(false);
req.setEndpoint('https://na34.salesforce.com/services/Soap/T/35.0');
HTTPResponse resp = h.send(req);
System.debug(resp.getBody());


 
scottbcovertscottbcovert
Hi Travis,

Andrew Fawcett from FinancialForce built an Apex wrapper around the Tooling API that utilizes SOAP; should be perfect for this use case:

https://github.com/afawcett/apex-toolingapi