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
LA_193LA_193 

how to upload files for multiple fields.... it's very urgent

Hi

 

Generally   we upload  file  for one record in salesforce .But our requirement is we have to upload  files

to  multiple fields for one record  in a Visualpage

 

for example 

 

Field1   Browse button1 

 

Field2   Browse button2

 

Field3   Browse button3

 

Please suggent ....

 

Thanks

Lakshmi

 

Best Answer chosen by Admin (Salesforce Developers) 
APathakAPathak

Hi,

If you mean attaching 4 files to records then this template code will get you started :-

 

/*Page*/
<apex:page controller = "Ctrl">
	<apex:form>
		<apex:inputFile value="{!contentFile1}"/>
		<apex:inputFile value="{!contentFile2}"/>
		<apex:inputFile value="{!contentFile3}"/>
		<apex:inputFile value="{!contentFile4}"/>
		<apex:commandButton action = "{!saveAttachements}" value = "Save Attachments"/>
	</apex:form>
</apex:page>


/*Controller*/
public class ctrl
{
	public Blob contentFile1{get;set;}
	public Blob contentFile2{get;set;}
	public Blob contentFile3{get;set;}
	public Blob contentFile4{get;set;}
	pulic String recordId;
	private account account;
	public ctrl()
	{
		//Constructor
		//recordId = '';//Initialize the record Id under whom attachments are inserted
	}
	
	public pagereference saveAttachements()
	{
		Attachment attachement1 = new attachement();
		Attachment attachement2 = new attachement();
		Attachment attachement3 = new attachement();
		Attachment attachement4 = new attachement();

		attachement1.Body = contentFile1;
		attachement1.ParentId = recordId;
		attachement2.Body = contentFile2;
		attachement2.ParentId = recordId;
		attachement3.Body = contentFile3;
		attachement3.ParentId = recordId;
		attachement4.Body = contentFile4;
		attachement4.ParentId = recordId;

		insert attachement1;
		insert attachement2;
		insert attachement3;
		insert attachement4;
		
	}
};

 

All Answers

Santosh KumbarSantosh Kumbar

What you mean by multiple files?? Are you trying to attach multiple files at one click to a record or three separate fields that hold s these n files??

 

 

regards

San

LA_193LA_193

need to upload files to fields on vf page....

LA_193LA_193

three separate fields on vf page

bob_buzzardbob_buzzard

I wrote up a blog post on uploading multiple attachments from a single page - that should give you a starting point:

 

http://bobbuzzard.blogspot.co.uk/2011/01/uploading-multiple-attachments-via.html

 

 

LA_193LA_193

thanks alot  for sharing this link .

But i have 4 separate page blocks in that have separate fields that holds these  n  no.  of uploadfiles

and  all these attachments should save to content .

 

Please suggest....

APathakAPathak

Hi,

If you mean attaching 4 files to records then this template code will get you started :-

 

/*Page*/
<apex:page controller = "Ctrl">
	<apex:form>
		<apex:inputFile value="{!contentFile1}"/>
		<apex:inputFile value="{!contentFile2}"/>
		<apex:inputFile value="{!contentFile3}"/>
		<apex:inputFile value="{!contentFile4}"/>
		<apex:commandButton action = "{!saveAttachements}" value = "Save Attachments"/>
	</apex:form>
</apex:page>


/*Controller*/
public class ctrl
{
	public Blob contentFile1{get;set;}
	public Blob contentFile2{get;set;}
	public Blob contentFile3{get;set;}
	public Blob contentFile4{get;set;}
	pulic String recordId;
	private account account;
	public ctrl()
	{
		//Constructor
		//recordId = '';//Initialize the record Id under whom attachments are inserted
	}
	
	public pagereference saveAttachements()
	{
		Attachment attachement1 = new attachement();
		Attachment attachement2 = new attachement();
		Attachment attachement3 = new attachement();
		Attachment attachement4 = new attachement();

		attachement1.Body = contentFile1;
		attachement1.ParentId = recordId;
		attachement2.Body = contentFile2;
		attachement2.ParentId = recordId;
		attachement3.Body = contentFile3;
		attachement3.ParentId = recordId;
		attachement4.Body = contentFile4;
		attachement4.ParentId = recordId;

		insert attachement1;
		insert attachement2;
		insert attachement3;
		insert attachement4;
		
	}
};

 

This was selected as the best answer
LA_193LA_193

Hi

 

Thanks for sharing ...

 

LA_193LA_193

Hi

 

Thanks a lot.

I have done same process in content  .

 

I got it.