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
salesForceUsersalesForceUser 

Creating an Attachment objcet opportunity

Hi,

i am trying to create an attachment to an opportunity and seem to get this error in my SaveOptions.

Required fields are missing: [Body]

The code snippet is below and I am setting the Body. Any ideas, what i am doing wrong, please let me know.

 

         Attachment att = new Attachment();
          att.setBody(docStream);
          att.setParentId(oppKey.getPublicId());
          att.setName(sforceDocName);
          att.setBodyLength(docInfo.getSize());
          SObject[] sObjects = new SObject[1];
          sObjects[0] = att;
          SaveResult[] saveResults = sforceBinding.create(sObjects, sh , new SaveOptions());
          if (saveResults[0].getSuccess())
          {
           // No errors, so we will retrieve the id created for this index
           System.out.println("Attachment with id " + saveResults[0].getId());
          }
        else
          {
            System.out.println("Error during creation of attachment " + saveResults[0].getErrors());
          }

DevAngelDevAngel

Hi salesForceUser,

I'm not sure what a docstream is, but you should be sending a base64 encoded string as the value of the body.  There are several decent base64 libraries for java out there, you just need to find one and use it.

Cheers

salesForceUsersalesForceUser

Hi Dave,

thanks for the response, but I believe Weblogic is handling that for me since the only method I have available on the Attachment class generated by Weblogic soap engine is 

Attachment.setBody(byte[])

When I do the exact same thing from Axis it works fine.

Also the error says

Error during creation of attachment Error{ statusCode=<REQUIRED_FIELD_MISSING> m
essage=<Required fields are missing: [Body]> fields=<null> }

Would it not give me "it is not base64 ......" kind of error if that were the case?

 

Thanks Dave

salesForceUsersalesForceUser

Hi Dave,

Actually, I have now verified that all the read operations go fine in weblogic, but the creation of objects fails. I tried a simple "Account" object. That too fails with a similar error (Missing Required fields) and no missing field is specified. I am wondering if there is something drastically different in the creates when done from weblogic.  And that is not being passed in the code.......

Has the webservice through weblogic been tested previously?

 

Any help on this will be great!

thanks.

salesForceUsersalesForceUser

Hi

More on this, I was able to create a simple Accoutn object  throught weblogic using this rather than the simple one which passed through Axis,. But the Attachment, which is the real object I want to create keeps throwing the one of these errors:

If I specify bodylength to be a valid size:

Error during creation of attachment Error{ statusCode=<INVALID_FIELD_FOR_INSERT_
UPDATE> message=<bad field names on insert/update call: BodyLength> fields=<null> }

If i do not specify it:

It says

Error during creation of attachment Error{ statusCode=<REQUIRED_FIELD_MISSING> message=........... for the BODY

Unfortunately I have to use weblogic because of other issues and I am stuck. Is there a way to see why the sforce server is really throwing the error? I suspect there is some other expectation on sforce side which weblogic is not fulfilling.

WEBLOGIC- ACCOUNT

    /*Account att =  new Account(null,
      null,
      "AC",
      "1"
      ,   "activec"
      ,     0
      ,     "abcd"
      ,     "which country"
      ,     "94538"
      ,     "A"
        ,     "A"
      ,     null
      ,     null
        ,     "A"
        ,     "A"
        ,     "A"
        ,     "A"   ,
null      ,     null
      , "name"
      ,     0
      ,    2
      ,     null
      ,     "mine"
      ,     null
      ,     "0"
      ,     "rating"
      ,     Calendar.getInstance()
      ,     "p_sLASerialNumberC"
      ,     "p_sLAC"
      ,     "p_shippingCity"
      ,     "p_shippingCountry"
      ,     "p_shippingPostalCode"
      ,     "p_shippingState"
      ,     "p_shippingStreet"
      ,     "p_sic"
      ,     "p_site"
      ,     null
      ,     "p_tickerSymbol"
      ,     "p_type"
      ,     "p_upsellOpportunityC"
      ,     null);*/

 

AXIS -ACCOUNT works with:

/*Account att = new Account();
        att.setDescription("desc");
        att.setName("Account23");
        att.setAC("AC");
        att.setAccountNumber("what is this");
        att.setAnnualRevenue(0);
        att.setOwnerId(SforceLoginHelper.lr.getUserId());   */

salesForceUsersalesForceUser

Hi,

here are the changes that I had to make to the WSDL for weblogic(follows the JAX-RPC/WSDL specification) to work correctly:

1. soap:fault, according to the specification needs "name" parameter. This needed to be added to 26 places in the WSDL.

2. If you have to work with 15 or 18 char Ids,  remove the length check on the Id which is set to 18 in the WSDL.

3. For objects like attachments, the bodylength is defined to be an int, Axis develops a class in which the setBodyLength(Integer a) whereas Weblogic (follows the JAX-RPC) created setBodyLength(int a)If the WSDL does not specify that the bodyLength can be nillable, the soap packet generated has this element set to 0 in Weblogic and the server side does not accept this. However the server side accepts the Bodylength to be null (which is what Axis does) and is able to create attachments. So the WSDl needs to be changed to allow nillable

I have not tried with other objects, where there might be similar constraints.

 

Hope this will help someone who is trying with Weblogic.