Open sierra82 opened 8 years ago
Can you share a snippet of Apex code that reproduces this please, i'll take a look. Thanks.
Here is the snippet of code that gives me the error:
ToolingApi toolingApi = new ToolingApi();
ToolingAPIWSDL.QueryResult qr = toolingApi.query('SELECT Fullname, metadata, entitydefinition FROM ValidationRule WHERE EntityDefinition.QualifiedApiName=\'Account\'','ToolingAPIWSDL.ValidationRule');
I've spent some time trying to get this working... ValidationRules need to be queried via a sub-select query while querying EntityDefinition. So the following query does return the response needed....
ToolingApi toolingApi = new ToolingApi();
ToolingAPIWSDL.QueryResult entityQueryResult =
toolingApi.query('SELECT Id, (Select Id from ValidationRules) FROM EntityDefinition Where QualifiedApiName=\'Test__c\'', 'ToolingAPIWSDL.EntityDefinition');
Problem with Apex Wrapper However the logic in the Apex wrapper here does not support deserialising ValidationRules it appears. So a new exception is thrown when the wrapper attempts to deserialise the response. I need to take a longer look at the architecture of this wrapper to see if this is just a missing configuration or if this type of structure is a wider issue.
Workaround via Apex HTTP Callout In the meantime you can using the Apex HTTP callout API and build the XML request as follows and parse via Apex XML API the response manually. The following is the XML request and response i captured.
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header>
<SessionHeader xmlns="urn:tooling.soap.sforce.com">
<sessionId>[yoursessionidhere]</sessionId>
</SessionHeader>
</env:Header>
<env:Body>
<query xmlns="urn:tooling.soap.sforce.com">
<queryString>SELECT Id, (Select Id, Metadata from ValidationRules) FROM EntityDefinition Where QualifiedApiName='Test__c'</queryString>
</query>
</env:Body>
</env:Envelope>
Example XML response...
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:tooling.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mns="urn:metadata.tooling.soap.sforce.com">
<soapenv:Body>
<queryResponse>
<result>
<done>true</done>
<entityTypeName>EntityDefinition</entityTypeName>
<queryLocator xsi:nil="true"/>
<records xsi:type="EntityDefinition">
<Id>000000000000000AAA</Id>
<ValidationRules>
<done>true</done>
<entityTypeName>ValidationRule</entityTypeName>
<queryLocator xsi:nil="true"/>
<records xsi:type="ValidationRule">
<Id>03d58000000KbpgAAC</Id>
<Metadata>
<mns:active>true</mns:active>
<mns:errorConditionFormula>TRUE</mns:errorConditionFormula>
<mns:errorMessage>Test</mns:errorMessage>
</Metadata>
</records>
<size>1</size>
<totalSize>1</totalSize>
</ValidationRules>
</records>
<size>1</size>
<totalSize>1</totalSize>
</result>
</queryResponse>
</soapenv:Body>
</soapenv:Envelope>
cc @dancinllama thoughts on this one?
SELECT Fullname, metadata, entitydefinition FROM ValidationRule WHERE EntityDefinition.QualifiedApiName='Account'
For example gives me:
Web service callout failed: WebService returned a SOAP Fault: INVALID_FIELD: Select Fullname, metadata, EntityDefinition From ValidationRule ^ ERROR at Row:1:Column:28 No such column 'EntityDefinition' on entity 'ValidationRule'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. faultcode=sf:INVALID_FIELD faultactor=