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
shiva pendemshiva pendem 

How to decode attachement body from base64 while using Async process Salesforce to .Net

HI All,

I am getting some issue my integration process, My senario is We are fetching the attachments from Salesforce with the help of Asynchronous process (Rest) api and adding all the files to .Dll file. But its Showing Error for Body fied Like 'Base64 format not supported'. How can we decode this Body content and how to add to dll file .
Please help Us.
Thanks 
NagaNaga (Salesforce Developers) 
Hi Shiva,

The API sends and receives the binary file attachment data encoded as a base64Binary data type. Prior to creating a record, client applications must encode the binary attachment data as base64. Upon receiving a response, client applications must decode the base64 data to binary (this conversion is usually handled for you by the SOAP client).



The difficult part is uploading an attachment to match Salesforce's specific multipart/form-data template. Without going into the exhausing details, the only I found to do this was to manually build the HTTP request body, and put the entire body in an ArrayBuffer, which the browser will not UTF-8 encode. Can you please try the below link and it should help you

http://salesforce.stackexchange.com/questions/56899/salesforce-isnt-handling-base64-encoded-attachments-uploaded-via-rest-api

Best Regards
Naga Kiran


 
shiva pendemshiva pendem
HI Naga,

Here we are not Uploading the attachments into salesforce . the req is fetching all the attachments and adding it to .Dll Using Async process (Rest). In Dotnet Environment.

Can u plz give your Suggetions. plese See the code and Guide me.
public partial class Attachments
    {

        private byte[] bodyField;
        public string name { get; set; }
        public string ContentType { get; set; }
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(DataType = "base64Binary", IsNullable = true, Order = 0)]
        public byte[] Body    // here the error is coming. 
        {
            get
            {
                return this.bodyField;
            }
            set
            {
                this.bodyField = value;

            }
        }
    }
    public static class OpportunityServices
    {

        private static async Task<IEnumerable<Opportunities>> GenerateDealFromSalesforce()
        {
            var auth = new AuthenticationClient();

            try
            {
                await auth.UsernamePasswordAsync("consumerkey","consumersecret","Username","Password", "https://test.salesforce.com/services/oauth2/token");
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);

            string attachments = "SELECT Name, Body, ContentType FROM Attachment WHERE ParentId = 'ParentRecID'";
            var att = await client.QueryAsync<Attachments>(attachments);

            return null;
        }
    }