Coder Social home page Coder Social logo

Comments (4)

afawcett avatar afawcett commented on August 23, 2024

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

from apex-toolingapi.

sierra82 avatar sierra82 commented on August 23, 2024

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

from apex-toolingapi.

afawcett avatar afawcett commented on August 23, 2024

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>

from apex-toolingapi.

afawcett avatar afawcett commented on August 23, 2024

cc @dancinllama thoughts on this one?

from apex-toolingapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.