I have standard salesforce detail page on which I have created a button. I am trying to make a callout from this button so I created a VF page and controller (from where the callout will be made). I need to do some validation in the controller for some fields before the callout line of code.

If there is a validation error I need to display it on the details page. Below is my example of how I am going about the VF page and controller.

public with sharing class MyCalloutExtension
    final ApexPages.StandardController controller;
    public MyCalloutExtension(ApexPages.StandardController controller)
        this.controller = controller;
    public PageReference makeCallout()

        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'This is an error'));
// make callout here
            return controller.view();

VF Page:

<apex:page standardController="MyObject__c"
    <apex:pageMessages />

My requirement is to show the error message on the standard detail page. Is this possible? If so how?

2 Answers 2


Instead of calling VF page, call javascript on click of button, check all the validations what you wants to check, if everything is fine no error found, call the apex class which is making callout. If you find any error you can simply display (JS alert) it on the detail page itself.

For this implementation you will have to use connection.js.


You will only be able to show the message within the inline VF page.

What you could do is create a page to display messages, please it at the top of the detail page without a section header below it.

It would use whatever code the current page uses to validate and display a message.

The current page would simply not show the button / do the callout if the criteria are met.

Basically if you are not willing to put the current page at the top of the detail page then you will need two pages.

In comes down to only being able to display the message within the detail page.

Another option would be to override the entire detail page, then you can place the message anywhere you want.

  • Thanks. If I use on click Javascript logic for the button , will I be then able to show the error message on top of the screen
    – SfdcBat
    Apr 18, 2017 at 13:40
  • @SfdcBat - you are missing the point of the answer. The button would not be visible, only the message would. You validate without user interaction since you are checking to see if a callout should be made.
    – Eric
    Apr 18, 2017 at 15:26
  • Will the user be able to edit and save the record again in this approach. I checked an way where I could use apex detail syntax to create a detail page and show the error message with button as well. <apex:pageMessages /> <apex:detail subject="{!object__c.id}"/>
    – SfdcBat
    Apr 18, 2017 at 15:42
  • @SfdcBat - If done correctly yes.
    – Eric
    Apr 18, 2017 at 15:45
  • Thanks for the inputs. I am trying to verify if I can cover all my scenarios using my new approach of having apex detail.
    – SfdcBat
    Apr 18, 2017 at 15:47

You must log in to answer this question.

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