Adding some points:
It is not possible to add a Visualforce page within a flow, e.g. there is no way to see it as an option in the Flow Builder. The only method to switch to visualforce is using a page as a wrapper for the flow and passing control to it by setting a variable value within the flow, which there is an example of
Add the following to the controller
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
// Specific flow name for flow type
public Flow.Interview.my_flow myflow { get; set; }
public String varCaseId;
public String varUpload;
public Boolean upload;
public Boolean uploaded = false;
public String fName{ get; set;}
public String displayName{get; set;}
// The Case Id value from the flow
public String getvarCaseId()
{
If(myFlow == null)
Return null;
Else
return myflow.varCaseId;
}
// The varUpload variable value from the flow
public String getvarUpload()
{
If(myFlow == null)
Return String.valueOf('0');
Else
Return myflow.varUpload;
}
Public Boolean getupload()
{
If(myFlow != null && myflow.varUpload != null && myflow.varUpload == '1' && uploaded!= null && uploaded == false)
Return true;
else
Return false;
}
// Save method, leading to next step in flow
public PageReference Save()
{
return upload(System.Boolean.valueOf(true));
}
// Save More method, leading to the attachment upload functionality again
public PageReference SaveMore()
{
return upload(System.Boolean.valueOf(false));
}
// Cancel method, leading to next step in flow
public PageReference Cancel()
{
This.uploaded = true;
attachment = null;
return null;
}
// Upload method for actual attachment upload, setting the upload variable appropriately to allow/ not allow another attachment upload
public PageReference upload(Boolean varUploaded)
{
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = getvarCaseId(); // the record the file is attached to
attachment.IsPrivate = false;
if( (!(attachment.name != null && attachment.name != '')) && (fName != null && fName != ''))
{
String afterExt = fName.substringAfter('.');
System.debug('afterExt :: ' + afterExt );
if(displayName != null && displayName != '')
{
attachment.name = displayName + '.' + afterExt;
}
else
attachment.name = fName;
}
try
{
if(!(attachment.body != null))
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please specify a file to be uploaded'));
}
else if (!(attachment.name != null && attachment.name != ''))
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Please specify a file name'));
}
insert attachment;
displayName = '';
fName = '';
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
}
finally
{
attachment = new Attachment();
}
This.uploaded = varUploaded;
// true for save and false for Save more
return null;
// End of upload
}
Visualforce page
<apex:outputPanel id="theAttachmentPanel" rendered="{!upload}">
<apex:sectionHeader title="Attachment Upload (Upto 10 MB)"/>
<apex:pageMessages />
<apex:pageBlock title="Upload an Attachment">
<apex:pageBlockButtons >
<apex:commandButton action="{!SaveMore}" value="Upload More"/>
<apex:commandButton action="{!Save}" value="Finish Uploading"/>
<apex:commandButton action="{!Cancel}" value="Submit with no Attachment"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Name" for=" filesName "/>
<apex:inputText value="{!displayName}" id="filesName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!attachment.body}" filename="{!fName}" id="file"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Description" for="description"/>
<apex:inputTextarea value="{!attachment.description}" id="description"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
Hope this will help you.
Thanks
-
This reply was modified 6 years, 3 months ago by Parul.