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
birdofpreybirdofprey 

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>

 

Best Answer chosen by Admin (Salesforce Developers) 
birdofpreybirdofprey

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

kiranmutturukiranmutturu

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());

birdofpreybirdofprey

That is the weird thing, debug value is not showing up.

 

Some reason the SendEmail function is not being called.

Starz26Starz26

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....

 

 

birdofpreybirdofprey

Ok I just realized why.

 

Because I am using selectList as a dropdown and not multipick list it doesn't work. for whatever reason.

This was selected as the best answer