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
Dhananjaya BulugahamulleDhananjaya Bulugahamulle 

How do you give an alert when my message in sent?

I want to display an alert when user click on the Submit button. It should be display in <apex:Messages/> . Any Idea how to do that, I tried using onComplete="alert('Mail Sent')" but it just prompting a box. I want my alert in apex message field. thanks
 
<apex:form>
    <apex:messages><apex:messages/>
        <apex:pageBlock>
           <apex:pageblockButtons >
                <apex:commandButton value="Submit" action="{!send}" /> 
           </apex:pageblockButtons>
         <apex:pageBlock >
<apex:form >
 
ublic String subject { get; set; }
    public String body { get; set; }

    private Account account;
    public Account getAccount() {
    account = [select Name, (SELECT user.Name, user.email from AccountTeamMembers) 
                from Account where id = :ct.AccountId];
        return account;
    }

    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 

    String addresses;
    if (account.AccountTeamMembers[0].user.Email != null)
    {
        addresses = account.AccountTeamMembers[0].user.Email;
        // Loop through the whole list of contacts and their emails
        for (Integer i = 1; i < account.AccountTeamMembers.size(); i++) 
        {
            if (account.AccountTeamMembers[i].user.Email != null)
            {
                addresses += ':' + account.AccountTeamMembers[i].user.Email;
            }
        }
    }

        String[] toAddresses = addresses.split(':', 0);

        // Sets the paramaters of the email
        email.setSubject( 'New Media/Buffer Product Brief from '  + ct.Name + ' at ' + acname.Name);
        email.setToAddresses( toAddresses );
        String htmlBody= 'Dear ' + ct.Name + ':<br/><br/>';
                htmlBody += 'This is a reminder that your review of ' + ct.Name + ' for the position of ' + 
                    ct.Name + ' has not been completed yet. Please complete this review as soon as possible.' +
                    '<br/><br/>Review Link: <a href=https://cs2.salesforce.com/' + ApexPages.currentPage().getParameters().get('id') + '>click here</a><br/><br/>Thank You,<br/>Recruiting Dept.';
                email.setHtmlBody(htmlBody);

        // Sends the email
        Messaging.SendEmailResult [] r = 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});   

        return null;
    }

 
Best Answer chosen by Dhananjaya Bulugahamulle
Amit Chaudhary 8Amit Chaudhary 8
pLease try below code.  I hope that will help u
ublic String subject { get; set; }
    public String body { get; set; }

    private Account account;
    public Account getAccount() {
    account = [select Name, (SELECT user.Name, user.email from AccountTeamMembers) 
                from Account where id = :ct.AccountId];
        return account;
    }

    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 

    String addresses;
    if (account.AccountTeamMembers[0].user.Email != null)
    {
        addresses = account.AccountTeamMembers[0].user.Email;
        // Loop through the whole list of contacts and their emails
        for (Integer i = 1; i < account.AccountTeamMembers.size(); i++) 
        {
            if (account.AccountTeamMembers[i].user.Email != null)
            {
                addresses += ':' + account.AccountTeamMembers[i].user.Email;
            }
        }
    }

        String[] toAddresses = addresses.split(':', 0);

        // Sets the paramaters of the email
        email.setSubject( 'New Media/Buffer Product Brief from '  + ct.Name + ' at ' + acname.Name);
        email.setToAddresses( toAddresses );
        String htmlBody= 'Dear ' + ct.Name + ':<br/><br/>';
                htmlBody += 'This is a reminder that your review of ' + ct.Name + ' for the position of ' + 
                    ct.Name + ' has not been completed yet. Please complete this review as soon as possible.' +
                    '<br/><br/>Review Link: <a href=https://cs2.salesforce.com/' + ApexPages.currentPage().getParameters().get('id') + '>click here</a><br/><br/>Thank You,<br/>Recruiting Dept.';
                email.setHtmlBody(htmlBody);

        // Sends the email
        Messaging.SendEmailResult [] r = 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});   
		
		ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Main sent'));
        return null;
    }

Always use below code to show message on VF page
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account number'));
http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/
Please let us know if this will help you

Thanks
Amit Chaudhary