Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityDefinition field missing on ValidationRule #41

Open
sierra82 opened this issue Apr 4, 2016 · 4 comments
Open

EntityDefinition field missing on ValidationRule #41

sierra82 opened this issue Apr 4, 2016 · 4 comments
Labels

Comments

@sierra82
Copy link

sierra82 commented Apr 4, 2016

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=

@afawcett afawcett added the bug label Apr 13, 2016
@afawcett
Copy link
Owner

Can you share a snippet of Apex code that reproduces this please, i'll take a look. Thanks.

@sierra82
Copy link
Author

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');

@sierra82 sierra82 reopened this Apr 14, 2016
@afawcett
Copy link
Owner

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>

@afawcett
Copy link
Owner

cc @dancinllama thoughts on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants