I am having one custom object "Site" which has lookup relationship with opportunity. Which means each site record has more than one opportunity. For example if a site record has 5 opportunity in that 4 opportunity has already closed then when i am trying to close the last opportunity in that site record it must display a alert message " your opportunity is closed, would you like to close the site record also yes or no". If i press yes means it must go to that particular site record their we can manually close the site record.

  • are you using a Vf page for the opportunity?
    – Prady
    Jul 30, 2013 at 7:18
  • @Prady, thanks for the reply. No i am not using VF page for Opportunity Jul 30, 2013 at 7:30
  • @LavanyaSanathkumar: What is it that you have tried??
    – Sam
    Jul 30, 2013 at 7:47
  • @LavanyaSanathkumar i am afraid, that might not be possible.. I hope somebody has a workaround for it.. Yes you could do all these using VF page on opportunity but in a standard page i dont think its possible
    – Prady
    Jul 30, 2013 at 7:57
  • @Prady, after creating a site record i am having a custom button "Create OPP" which will create a new opportunity under that site record. Jul 30, 2013 at 8:39

2 Answers 2


I think you're going to need a VF page for this on the opportunity record. You just have to write a custom controller to display a pageMessage when all the opportunities are closed. Something like this:

Integer numNonClosedOpps = [select count() from Opportunity where Site__c = :siteId and StageName != 'Closed' and Id != :thisOppId];
if (numNonClosedOpps == 0) {
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 
        'All opps closed in this site.  Please <a href="urlforsite">go here</a> to close the site.'));

Within your vf page, you just need to add the pageMessages tag. Make sure to add the escape attribute to get your url to show up correctly:

<apex:pageMessages escape="true"/> 

You're looking for this idea on the IdeaExchange: Warning messages. Go vote now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.