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
professoreprofessore 

Adding an attachment to an opportunity using SOAP message

Hi,

 

I am trying to add an attachment to an opportunity using a SOAP message.  Below is the soap message :

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>00DA0000000aBVb!AREAQBukBuFfuoatmzmtcp4lg8rPIobjbXbosShxu._d7g_eRrrZVh3fmaXH.CAesIQmGyvUPjF5oTMnYXGwoODbSz7Fbrvs</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
  <urn:Name>zxcxzcxzc.doc</urn:Name>
 <urn:Body> BASE 64 stuff in here ... </urn:Body>
         <urn:sObjects urn:type="Attachment">
            <urn1:fieldsToNull>true</urn1:fieldsToNull>
    <urn1:ParentId>006A0000006dGDkIAM</urn1:ParentId>
    <urn1:OwnerId>005A0000000KRJv</urn1:OwnerId>
    <urn1:ContentType>doc</urn1:ContentType>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>

 

 

I get the following response :

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <soapenv:Body>

      <soapenv:Fault>

         <faultcode>sf:INVALID_TYPE</faultcode>

         <faultstring>INVALID_TYPE: Must send a concrete entity type.</faultstring>

         <detail>

            <sf:InvalidSObjectFault xsi:type="sf:InvalidSObjectFault">

               <sf:exceptionCode>INVALID_TYPE</sf:exceptionCode>

               <sf:exceptionMessage>Must send a concrete entity type.</sf:exceptionMessage>

               <sf:row>-1</sf:row>

               <sf:column>-1</sf:column>

            </sf:InvalidSObjectFault>

         </detail>

      </soapenv:Fault>

   </soapenv:Body>

</soapenv:Envelope>

 

 

The doc is an MS Word doc.  Any ideas what I am doing wrong ? I am able to run queries no problem.

 

Thanks,

 

Prof

 

 

Best Answer chosen by Admin (Salesforce Developers) 
professoreprofessore

Thanks Simon,

 

That did the trick .... for the record the correct syntax is ...

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>Session ID Here</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
         <urn:sObjects xsi:type="Attachment">
    <Name>zxcxzcxzc.doc</Name>
    <Body> Base 64 stuff here</Body>
    <ParentId> Parent ID here</ParentId>
    <ContentType>doc</ContentType>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>

 

All Answers

joshbirkjoshbirk

I believe "Name" and "Body" need to within the sObject definition, and you may need type as an attribute.   See the sample SOAP create message:

 

http://wiki.developerforce.com/index.php/PartnerCreate

professoreprofessore

Hi

 

I put Name and Body in but still get the same message. Where do i add Type as an attribute, and what should it be ?

 

Thanks

 

prof

professoreprofessore

Oops, sorry, just saw where type should go.

professoreprofessore

 

Didn't work unfortunately.  Here's what I have now :
Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId> Session stuff here </urn:sesssionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
         <urn:sObjects>
    <urn1:type><b>Attachment</b></urn1:type>
    <urn:Name>zxcxzcxzc.doc</urn:Name>
    <urn:Body> Base64 stuff here <urn:Body>            <urn1:fieldsToNull>true</urn1:fieldsToNull>
    <urn1:ParentId>006A0000006dGDkIAM</urn1:ParentId>
    <urn1:OwnerId>005A0000000KRJv</urn1:OwnerId>
    <urn1:ContentType>doc</urn1:ContentType>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>
Response :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>sf:INVALID_TYPE</faultcode>
         <faultstring>INVALID_TYPE: Must send a concrete entity type.</faultstring>
         <detail>
            <sf:InvalidSObjectFault xsi:type="sf:InvalidSObjectFault">
               <sf:exceptionCode>INVALID_TYPE</sf:exceptionCode>
               <sf:exceptionMessage>Must send a concrete entity type.</sf:exceptionMessage>
               <sf:row>-1</sf:row>
               <sf:column>-1</sf:column>
            </sf:InvalidSObjectFault>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

 

joshbirkjoshbirk

Was the B tag in your SOAP type tag or was that just a message board format? 

 

It's also possible the SOAP API is being nitpicky about the namespacing. 

professoreprofessore

Nope, was in there because it was in the exapmple you referred me to.  I took it out and still doesn't work, and gives the same error :(

joshbirkjoshbirk

Huh, so it was :)  Pretty certain we don't need the bold tags in there, think that's a formatting error on the example...

 

So I'd check the namespacing ... but let me see if I can hunt down a specific attachment example.  Know it's possible, but I don't have the code that I worked with laying around before.

 

What language are you using?

professoreprofessore

I am using Visual C++ 6 and have put together some classes to talk to Salesforce.

joshbirkjoshbirk

And is this partner or enterprise?

professoreprofessore

Enterprise

joshbirkjoshbirk

Ah, then I may have pointed you in the wrong direction.  I think Enterprise uses the type attribute like you had before:

 

http://www.salesforce.com/us/developer/resources/soap/sforce60/sforce_API_messages_update.html

 

So perhaps the right combination is using the type attribute with the Name and Body included in the sObjects element?

 

I'll continue to poke around and see if I can find a specific attachment example.   

professoreprofessore

 

Thanks, I will pick this up again tomorrow

 

jhurstjhurst

You can find a list of SOAP calls at http://wiki.developerforce.com/index.php/Sample_SOAP_Messages

 

To create an attachment, you would use something like:

 

 

<?xml version="1.0" encoding="utf-8"?>  
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
     <urn:SessionHeader>
        <urn:sessionId><b>QwWsHJyTPW.1pd0_jXlNKOSU</b></urn:sessionId>
     </urn:SessionHeader>
  </soapenv:Header>
  <soapenv:Body>
     <urn:create>
        <urn:sObjects xsi:type="Attachment"> 
           <Name>Attachment.doc</Name>
           <Body>Base64 Data</Body>
           <ParentId>006A0000006dGDkIAM</ParentId>
           <OwnerId>005A0000000KRJv</OwnerId>
           <ContentType>doc</ContentType>
        </urn:sObjects>
     </urn:create>
  </soapenv:Body>
</soapenv:Envelope>

 

 

professoreprofessore

 

I must say I am still stumped.
With this request :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId> Session ID Here </urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
         <urn:sObjects xsi:type="Attachment">
    <Name>zxcxzcxzc.doc</Name>
    <Body> Base 64 encoding here </Body>
    <ParentId> Parent ID here</ParentId>
    <ContentType>doc</ContentType>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>

 

I get :

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <soapenv:Body>

      <soapenv:Fault>

         <faultcode>soapenv:Client</faultcode>

         <faultstring>The prefix "xsi" for attribute "xsi:type" associated with an element type "urn:sObjects" is not bound.</faultstring>

      </soapenv:Fault>

   </soapenv:Body>

</soapenv:Envelope>

 

 

If I remove the xsi: from the sObjects attribute I get the same error as before, i.e.:

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <soapenv:Body>

      <soapenv:Fault>

         <faultcode>sf:INVALID_TYPE</faultcode>

         <faultstring>INVALID_TYPE: Must send a concrete entity type.</faultstring>

         <detail>

            <sf:InvalidSObjectFault xsi:type="sf:InvalidSObjectFault">

               <sf:exceptionCode>INVALID_TYPE</sf:exceptionCode>

               <sf:exceptionMessage>Must send a concrete entity type.</sf:exceptionMessage>

               <sf:row>-1</sf:row>

               <sf:column>-1</sf:column>

            </sf:InvalidSObjectFault>

         </detail>

      </soapenv:Fault>

   </soapenv:Body>

</soapenv:Envelope>

 

 

 

 

SuperfellSuperfell

For the enterprise API, you need to send the xsi:type attribute, and that will require you to declare the namespace binding for the xsi prefix (this is the first error message you got) e.g. add an  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attribute to your Envelope element. (see the response xml for an example)

professoreprofessore

Thanks Simon,

 

That did the trick .... for the record the correct syntax is ...

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>Session ID Here</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
         <urn:sObjects xsi:type="Attachment">
    <Name>zxcxzcxzc.doc</Name>
    <Body> Base 64 stuff here</Body>
    <ParentId> Parent ID here</ParentId>
    <ContentType>doc</ContentType>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>

 

This was selected as the best answer
Lee Anne GLee Anne G
Thank you SO much for these two helpful tips! Bookmarking this page! :-)