i created a visualforce page in which actionfunction definition is

<apex:actionFunction name="setAttachment" action="{!setAttachment}" >
<apex:param name="attachmentBody" value=""/>

and in my javascript code at end i am calling


and setAttachment method in apex controller is

public void setAttachment()
{System.debug('coming here');
    String attachmentBody = ApexPages.currentPage().getParameters().get('attachmentBody');
    System.debug('attachment body is'+attachmentBody);
if(attachment == null)
System.debug('coming here');
attachment.Body = EncodingUtil.base64decode(attachmentBody);


in logs its giving attachment body is null.but i am passing a big string in javascript code function.can anyone please tell why instead of passing string its passing null as parameter in apex controller ??


When we need to send parameter with action function then we have to use rerender attribute in otherwise we always get null value in controller.

   <apex:actionFunction name="setAttachment" action="{!setAttachment}" rerender="none" >
    <apex:param name="attachmentBody" value=""/>
| improve this answer | |
  • You'd think SF would have fixed this by now - I just got caught again by this... – Caspar Harmer Feb 25 '16 at 23:09
  • I just got caught by this again... 2 years later. Sigh. Maybe it's me. – Caspar Harmer Oct 18 '18 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.