You need to sign in to do that
Don't have an account?
birdofprey
Button cannot be involve.
I want to have a send email message in a function that gets executed whenever the button is press in VF. But nothing happens, I even put in a few system debug, but it doesn't seem to be called when I look into the developer console. Any Ideas?
... public EasySendEmail(ApexPages.StandardController controller){ this.con=(Contact)controller.getRecord(); } public PageReference SendEmail(){ Contact recipient = [SELECT id, firstname FROM Contact Where Id = '003f00000039EQcAAM']; system.debug('debug--->' + UserInfo.getUserId()); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTargetObjectId(recipient.Id); mail.setTemplateId('00Xf0000000DZTt'); system.debug('mail--->' + mail); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); return new PageReference('/' + con.id); } ...
public List<SelectOption> getContactItems(){ List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('CANADA','Canada')); options.add(new SelectOption('MEXICO','Mexico')); return options; } public String[] getContactInfo() { return contact; } public void setContactInfo(String[] contact) { this.contact = contact; }
<apex:page standardcontroller="Contact" extensions="EasySendEmail"> <apex:form > <apex:selectList value="{!ContactInfo}" size="1"> <apex:selectOptions value="{!ContactItems}"/> </apex:selectList> <br /><br /> <apex:commandButton value="Send Email!" action="{!SendEmail}" reRender="fake" /> </apex:form> </apex:page>
Ok I just realized why.
Because I am using selectList as a dropdown and not multipick list it doesn't work. for whatever reason.
All Answers
seems to me all correct....just check debug log with exception keyword if any... also put a apex:pagemessage in the vf page too...r u able to get the debug value of sendemail email i.e. system.debug('debug--->' + UserInfo.getUserId());
That is the weird thing, debug value is not showing up.
Some reason the SendEmail function is not being called.
two things to check:
1. Put rerender="fake" in the command button
Without the rerender the page refreshes
2. Make sure your logging levels are adequate to display the debug statement.
I have found the debug logs to be buggy as of late. For example, I have logging set to error only and finest is in the log. Sometime when changing from error to debug, only error shows up....
Ok I just realized why.
Because I am using selectList as a dropdown and not multipick list it doesn't work. for whatever reason.