1

I seem to have the same problem for 'update' call like in this post. I have created Http version of the update method. I am having trouble in adding fields to the update call. Any Idea, How can I add elements to List anyElement?

0

I used the following against the Apex classes generated by v3.12.19175.1 of the FuseIT SFDC Explorer. The Update web method was generated to support both the direct SOAP call and the HTTP version.

Note that the direct SOAP version that uses WebServiceCallout.invoke fails with a GACK:

System.UnexpectedException: Got an unexpected error in callout : Unsupported type: dom.XmlNode. Contact support with error ID: 1752241713-78721 (1305052954)

partnerSoapSforceCom.Soap partnerObj = new partnerSoapSforceCom.Soap();
partnerObj.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();
partnerObj.SessionHeader.sessionId = UserInfo.getSessionId();
partnerObj.endpoint_x = URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/u/46.0';

sobjectPartnerSoapSforceCom.sObject_x toUpdate = new sobjectPartnerSoapSforceCom.sObject_x();
toUpdate.type_x = 'Account';
toUpdate.fieldsToNull = null;
toUpdate.Id = '0017000001HW4RjAAL';
toUpdate.anyElement = new List<DOM.XmlNode>();

string namespace = null;
DOM.Document doc = new DOM.Document();
dom.XmlNode mockRoot = doc.createRootElement('root', namespace, null);

DOM.XmlNode descriptionFieldUpdate = mockRoot.addChildElement('Description', namespace, null);
descriptionFieldUpdate.addTextNode('This is the new Account Description');

toUpdate.anyElement.add(descriptionFieldUpdate);

sobjectPartnerSoapSforceCom.sObject_x[] sObjects = new sobjectPartnerSoapSforceCom.sObject_x[] {toUpdate};
//System.UnexpectedException: Got an unexpected error in callout : Unsupported type: dom.XmlNode. Contact support with error ID: 1752241713-78721 (1305052954)
//partnerSoapSforceCom.SaveResult[] saveResults = partnerObj.update_x(sObjects);
partnerSoapSforceCom.SaveResult[] saveResults = partnerObj.update_x_Http(sObjects);
System.debug(saveResults);

I've created a DOM.XmlNode to hold the new description field value. To create this record I first needed to create a mock document and root element that are then discarded.

Also, because of how the namespace is handled on the any element I needed to manually modify the populateXmlNode method for sobjectPartnerSoapSforceCom.sObject_x as follows:

    public void populateXmlNode(Dom.XmlNode outerNode){
        Dom.XmlNode type_xNode = outerNode.addChildElement('type', 'urn:sobject.partner.soap.sforce.com', '');
        if(this.type_x != null){
            type_xNode.addTextNode(this.type_x);
        }
        if(this.fieldsToNull != null){
            for(String element: this.fieldsToNull){
                Dom.XmlNode fieldsToNullNode = outerNode.addChildElement('fieldsToNull', 'urn:sobject.partner.soap.sforce.com', '');
                fieldsToNullNode.addTextNode(String.valueOf(element));
            }
        }                               
        Dom.XmlNode IdNode = outerNode.addChildElement('Id', 'urn:sobject.partner.soap.sforce.com', '');
        if(this.Id != null){
            IdNode.addTextNode(this.Id);
        }

        List<DOM.XmlNode> anyElementObj = this.anyElement;
        for(DOM.XmlNode anyNode: this.anyElement){
            Dom.XmlNode anyElementNode = outerNode.addChildElement(anyNode.getName(), anyNode.getNamespace(), null); 
            anyElementNode.addTextNode(anyNode.getText());
        }
    }

Note how the outerNode prefix is set to null rather than the empty string and the inner text is copied over to the new anyElementNode.

1
  • 1
    Thanks Daniel. It worked with small change to namespace from your code. I have changed the namespace to 'string namespace = 'urn:partner.soap.sforce.com'' – Uday Jul 1 '19 at 11:29

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.