1

I have a custom database [object] called ‘Trainee__c’

And added a custom button that shows on each record,

I followed this website:

Create custom Button using Apex code

Very nicely explained

This code is only internally used,

My VisualForce code is

<apex:page standardController="Trainee__c" extensions="templicenseemail" action="{!doSomething}">
  <apex:pagemessages /> 
</apex:page>

My APEX code is [This is only a portion of the code]

public with sharing class templicenseemail {
     private ApexPages.standardController standardController;
     public Trainee__c trainee { get; set; }
    public templicenseemail(ApexPages.StandardController controller) {
        this.standardController = standardController;
    }
     public PageReference doSomething()
    {
        trainee  = [SELECT Email__c,First_Name__c,Institution__c,Last_Name__c FROM Trainee__c 
                WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, trainee.Email__c  ));
        return null;
    }   

}

I added the button in the custom layout for ‘Trainee__c’ object,

The button redirects the page to an empty page and displays the current Trainee__c record email address.

I want the email message to be displayed on the same record page,

How can I prevent the page from being redirected to an empty page?

1 Answer 1

1

Standard Behaviour Visualforce Buttons

This is the standard behaviour of Custom Buttons associated with Visualforce pages to show the page related to the button, in your case the messages shown by the apex:pageMessages component.

Visualforce Pages on Layouts.

If you want to show this page inline on the same page, you could consider dragging and dropping the Visualforce page into the layout of the custom object if you wish. It actually should be pretty much ready to go as it is right now.

Also consider instead of doing...

ApexPages.currentPage().getParameters().get('id')

Do this, as its a bit more direct to use the standard controller method to get your Id...

standardController.getId()
1
  • standardController.getId() sends me to the VisualForce page, so i used the original line, And the rest works fine, thnx Commented Jan 7, 2014 at 3:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .