11

is it even possible to save attachment with remote objects to salesforce?

I tried this:

  1. construct remote object model

<apex:remoteObjects jsNamespace="MyModel"> <apex:remoteObjectModel name="Attachment" fields="Name,Id,ParentId,Body" > </apex:remoteObjectModel> </apex:remoteObjects>

  1. create attachment

var blob='test body'; var ctDetails = {Name:'test',parentid:'some_id',Body:blob}; var ct = new MyModel.Attachment(); ct.create(ctDetails);

I get response:

Body: value not of required type...

I thought problem has to be with body encoding and I tried to convert to base64 (btoa('test body')), use Blob class in javascript. Nothing works, response is the same everytime.

What is wrong here?

  • Could you include the controller class as well so that we can see what the remote action is defined to accept? – TC Sutton Jan 25 '15 at 18:29
  • There is no controller class, because it is just visual force page. Remote objects are intended just for Vf. See: salesforce.com/us/developer/docs/pages/… – Simon Jan 25 '15 at 21:56
  • The body needs to be a BLOB not a text string – Eric Feb 27 '15 at 7:06
  • 1
    Can you retrieve a known Attachment via remote objects and then examine the encoding of the body? This may indicate how you should encode the body, assuming symmetric treatment for retrieval and creation. – Daniel Ballinger Mar 2 '15 at 0:39
  • 1
    I've tried that and get the following error when trying to retrieve body field of attachment: Visualforce Remoting Exception: No serializer found for class common.udd.object.EncryptableFfxBlobField$DeferredEncryptableFfxBlobValueImpl If I try to retrieve attachment without body field, it works normally. – Simon Mar 2 '15 at 9:18
8
+50

Based on the error message you get when you attempt to retrieve the body of an attachment:

Visualforce Remoting Exception: No serializer found for class common.udd.object.EncryptableFfxBlobField$DeferredEncryptableFfxBlobValueImpl

It would appear that you can't work with blob fields in Visualforce Remote Objects.

I'll see if I can find an official reference for the supported field types...

  • Visual Force Remoting

    VF Remoting [does not] support Blob data type. See VF Remoting docs for supported types.

  • 2
    This makes sense, which is why we're unable to retrieve or create. But had the error message said Attachment Object not supported for remoteObject then that would have been the end of it. But the Error message says 'Body : not of required type' which only makes the developer think that there could be a data type that can be used. Salesforce should update their documentation on the supported objects for Remote Objects – Sam Mar 3 '15 at 10:44
  • I agree, it is confusing. I've tried pinging @SalesforceDocs to see if they can elaborate. – Daniel Ballinger Mar 3 '15 at 20:10
  • Got a confirmation from Salesforce that this is a bug in the system and will be worked upon in the coming release. – Sam Mar 25 '15 at 4:04
  • They have created a knowledge article on the same help.salesforce.com/apex/… – Sam Mar 26 '15 at 14:53
0

If you are using javascript remoting to upload document to salesforce, you will be limited by the 6MB heap limit of apex. But actually salesforce supports uploading attachments of size upto 25MB. I had come across such scenario previously to upload document to salesforce record from javascript. I used AJAX API to solve the problem.

Try using HTML5 file reader API in combination with AJAX API call to upload attachment. HTML5 file reader will help in showing preview of files(images) and checking whether file size is exceeding 25MB and AJAX API will help in uploading upto 25MB through nothing more than 200 lines of javascript.

  • I have already implemented it using REST API and its working beautifully. But I wanted to be able to create it using RemoteObjects which I am unable to. – Sam Mar 2 '15 at 1:27

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.