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
wesnoltewesnolte 

CommandButton params are null but commandlinks are not

Hello

 

I'm having a strange issue, let me start with my code:

 

VisualForce:

 

<apex:commandButton action="{!sendEmail}" value="Send Email" id="emailButton"> <apex:param name="frmParam" assignTo="{!frm}" value="{!$User.Email}"></apex:param> <apex:param name="toParam" assignTo="{!to}" value="{!Application__c.Email__c}"></apex:param> <apex:param name="subjParam" assignTo="{!subject}" value="Your application for position no. {!Application__c.Job_Requisition__r.name}"></apex:param> </apex:commandButton>

 Controller:

 

public class emailApplicant { private Application__c app; private String jobRef = null; public string frm; public string to; public string subject; public string emailBody; public string getFrm(){ return frm; } public string getTo(){ return to; } public string getSubject(){ return subject; } public string getEmailBody(){ return emailBody; } public void setFrm(string value){ frm = value; } public void setTo(string value){ to = value; } public void setSubject(string value){ subject= value; } public void setEmailBody(string value){ emailBody=value; } public emailApplicant(ApexPages.StandardController controller){ app = (Application__c)controller.getSubject(); //Id id = System.currentPageReference().getParameters().get('id'); jobRef = [SELECT name FROM job_req__c WHERE id = :app.job_requisition__c].name; } public Application__c getAppInfo(){ return app; } public String getJobRef(){ return jobRef; } public PageReference sendEmail(){ PageReference p = new PageReference('https://na6.salesforce.com/'+app.job_requisition__c); p.setRedirect(true); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String [] toAddresses = new String[]{to}; mail.setToAddresses(toAddresses); mail.setReplyTo(frm); mail.setSenderDisplayName(frm); mail.setSubject(subject+to+frm); mail.setPlainTextBody(emailBody); Messaging.sendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail}); for ( Messaging.sendEmailResult result : results ) { if ( !result.isSuccess () ) { System.debug ( result ); return p; } } return p; } }

 

The issue is that if I use a commandbutton in the VisualForce page I get the following error:

 

 

System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : null

 

This value is not null, and I can attest to this because if I simply change the commandButton into a commandLink, the result is positive. Could someone tell me if there is a bug, or if I am using the component incorrectly.

 

Thanks,

Wes

 

 

jwetzlerjwetzler
Actually there's a known bug with command button where param values don't come through unless you're doing a partial page update.  Currently the only way around it is to use either commandLink or to make it a partial page update, which probably isn't an option for you.
RedPointRedPoint
I remember seeing a post that said this "should" be fixed in Spring '09 release but it doesn't seem to be fixed.  Maybe by the summer we can get rid of the ugly links and replace them with pretty buttons....
SteveBowerSteveBower

 

I mean **bleep**... really.  I've banged my head against this for an hour before looking through a bunch of posts on the board to see if anybody else had problems with this.

 

This is a waste of my time.  It's not a known issue if you don't tell anybody about it, it's just a bug.

 

Vote for this:   http://ideas.salesforce.com/article/show/10094288/#skin=adn

 

-S

 

 

Ron WildRon Wild

Jill,

 

Can you give us an update?  Will this be fixed in the Summer '09 release?

 

Thanks,

Mike F.Mike F.

I just spent a half a day beating on this issue too, and found out that if I switch from a button to a link, the parameters pass just fine.

 

STILL an issue.