Apex Class: public class ContactUsController { public List attachments { get; set; } public String handleFileContent { get; set; } public void FillAttachment() { if(this.handleFileContent != null && this.handleFileContent.length() > 0) { Attachment toAttach = new Attachment(body = Blob.valueOf(this.handleFileContent)); this.attachments.add(toAttach); } } } The problem of this approach is that in this way, i got „Regex too complicated“ error. So, I tried to check heap size ( ), but it is no problem. I also tryied to use Transcient method, but it does not work ( ). Finnaly I tried to use future method, but it is static, so it is not possible for me to use it ( ). I suggest that problem is that I exceed limit of view stat ( ) Can you help me? To Sum Up. Is there any way, how to send file from visualforce page using javascript and actionfunction to apex class? I can not use apex:imputFile because I have to use more rerender scopes on that page. I hope that there will be some workaround. (I thinking about iframe page using apex:imputFile embedded to my page which handle uploading attachments and then via timpestamp-identifiers map it to relevant Case. But I think that it is \"weird\" way to upload files.) Thank you for your answer. Martin", "answerCount": 4, "upvoteCount": 0, "datePublished": "2016-06-30T11:49:45.000Z", "author": { "@type": "Person", "name": "Martin Prokop", "url": "https://trailblazers.salesforce.com/profileView?u=0053000000BmhEdAAJ", "affiliation": { "@type": "Organization", "name": "--" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Try this.. http://salesforce.stackexchange.com/questions/88933/upload-attachment-in-visualforce-without-reloading-the-whole-page", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4Y5WSAV", "datePublished": "2016-06-30T12:02:01.000Z", "author": { "@type": "Person", "name": "Raj Kumar", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000CLyDmQAL", "affiliation": { "@type": "Organization", "name": "Deloitte Consulting" } } } ] } } Skip to main content
Hello,

Could you help me please? I want to implement attaching files to Cases in SalesForce.

 

There is recomanded way which using apex:inputFile element, but I can’t use it, because on page I have to use more rerendering scopes.

 

So I decided to implement it via standard html input and action function with parameters (where content of file is passed in parameter to apex class).

 

Visualforce:

<apex:form id="techForm" enctype="multipart/form-data">

<apex:actionFunction name="fillAttachment" action="{!formController.FillAttachment}" reRender="attachmentsBlock">

<apex:param assignTo="{!formController.handleFileContent}" name="handleFileContent" value="" />

</apex:actionFunction>

<script type="text/javascript">

function check_extension(filename) {

var files = document.getElementById('attachment').files;

var file = files[0];

fillAttachment(file);

}

</script>

<input type="file" accept=".gif, .jpg, .jpeg, .tif, .tiff, .png, .pdf" onChange="check_extension(this.value)" class="hidden" value="" filename="attachment" id="attachment" />

</form>

Apex Class:

public class ContactUsController {

public List<Attachment> attachments { get; set; }

public String handleFileContent { get; set; }

public void FillAttachment() {

if(this.handleFileContent != null && this.handleFileContent.length() > 0) {

Attachment toAttach = new Attachment(body = Blob.valueOf(this.handleFileContent));

this.attachments.add(toAttach);

}

}

}

The problem of this approach is that in this way, i got „Regex too complicated“ error.

 

I suggest that problem is that I exceed limit of view stat (https://developer.salesforce.com/forums/?id=906F0000000AsUHIA0)

 

Can you help me?

 

To Sum Up. Is there any way, how to send file from visualforce page using javascript and actionfunction to apex class? I can not use apex:imputFile because I have to use more rerender scopes on that page. I hope that there will be some workaround.

 

(I thinking about iframe page using apex:imputFile embedded to my page which handle uploading attachments and then via timpestamp-identifiers map it to relevant Case. But I think that it is "weird" way to upload files.)

 

Thank you for your answer.

Martin
4 个回答
0/9000