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
ramesh_tankalaramesh_tankala 

Upload Excel File

 

Hi all,

 

  i have developed an application using sales force api recently.Now i have a problem when i am uploading the file physically to salesforce from my applicaton.can u give the solution for this. 


 

JasonGablerJasonGabler

What exactly is the problem?

 

jason

Ankit AroraAnkit Arora

Please explain your problem and use case.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

ramesh_tankalaramesh_tankala

I have developing application using Apex, My application generate Excel Sheet for each Opportunity.My Problem is i need to upload that Excel sheet  for that opportunity in sales force using APEX. 

 

 

irlrobinsirlrobins

Do you mean you want the excel file attached to each opportunity? Or stored as a Document in Salesforce?

 

How is the excel file generated?

ramesh_tankalaramesh_tankala

Hi

  

 Yes ,i want attached excel sheet for each opportunity from my application, i have generated excel sheet  from Goggle Analytics based on opportunity.

 

with regards

 

ramesh

irlrobinsirlrobins

Well the normal way to create an attachment in apex is as follows:

 

Attachment myAttachment  = new Attachment();  
myAttachment.Body = fileBody;  
myAttachment.Name = fileName;
myAttachment.ParentId = myOpportunity.Id;
insert myAttachment;

 where fileBody is a Blob and fileName a string.

 

I think it would be useful to see the apex code where you're generating the excel file.

ramesh_tankalaramesh_tankala

Hi

 

  i am trying your code still i am not able to handle "insert myAttachment;" , i need more details on   that.

 

with regards

 

ramesh

irlrobinsirlrobins

This blog has an example of attaching a pdf to an object. It might make things clearer.

JasonGablerJasonGabler

What are the details related to "I am still not able to handle..."?   If you want us to be able to help you do what you need to, you're going to have to be more forthcoming with details of what is not working for you.     What happens when you try the code you were given?  Have you been using the System Log to do any debuggin?

 

jason

ramesh_tankalaramesh_tankala

 

Hi

 

Please observe my code and give me the suggestions.

 

 qr = binding.query("select Account.Id,Account.Name,Id,Name,Web_Services_Report_URL__c from opportunity where Web_Services_End_Date__c > TODAY and Web_Services_Start_Date__c <= TODAY and name like '%_IWeb_%' and Name='Yale University_School of Management_IWeb_2010'");

 

records = qr.records;

 

apex.Opportunity opt = (apex.Opportunity)records[0];

 

apex.Attachment attch = new apex.Attachment();               

 

attch.Body = blob1;

 

attch.Name="D:\fileserver\5-2011\PetersonsWebServicesReport-06-20-2011-chesneyr@wpunj.edu-3.xls";

 

attch.ParentId=opt.Id;

 

insert attch; //How to handle this statement

 

 

and also i need to upload this file name(attch.Name ) to custom field  "Web_Services_Report_URL__c "

 

 

with regards

 

Ramesh