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
Amit_Amit_ 

Attach Image in Attachment

Hi,

I have simple requirement, I have a webservice class which accepts some parameters as,


global class someclass{

               

               list<apexclassImage> imageLst{get;set;}{imageLst = new list<apexclassImage>();}

along with other string parameter I am getting a list which has filename and fileBody as blob from java side this is my method signature.

webservice static string myMethod(string, string,string......, list<apexclassImage> imageLst){

I want to insert the list<apexclassImage> imageLst to Attachment. this list may contain sigle image or Multiple Image.
but I am not able to insert in the Body filed of attachment from the list.

I am able to insert value to other object from the passed value.

          for(interger i=0; i<= imageLst.size(); i++){


                   Attachment att = new Attachment();

         }

/* I have created a wrapper class in webservice class itself as and declared a list of wrapper in webservice */
global class apexclassImage{
          global string fileName{get;set;}
          global Blob fileBody{get;set;}
}

Please suggest me how to get the multiple elements from the list and attachment. Any suggeston is appriciated.

Thanks & Regards,

SarfarajSarfaraj

Hi Amit

 

Body of Attachment class is of type base64. You need to convert the Blob to base64. You have to use base64Encode(Blob) method of EncodingUtil class.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_attachment.htm

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_EncodingUtil_instance_methods.htm

 

Ashish_SFDCAshish_SFDC

Hi Amit,

 

See the links for more info,

The following data types are only supported when used as call ins, that is, when an external Web service calls an Apex Web service method. These data types are not supported as callouts, that is, when an Apex Web service method calls an external Web service.

  • blob

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex.htm

 

Vote for the idea:

 

Add Blob Response Support to HTTP Callouts

https://success.salesforce.com/ideaview?id=08730000000I9p2AAC

 

 

Add support for Base64 type to Apex Code for parsing Attachment Body

https://success.salesforce.com/ideaView?id=08730000000BrmoAAC

 

http://salesforce.stackexchange.com/questions/9995/handling-inline-images-in-inbound-email-handler

 

Regards,

Ashish