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?– PradyJul 30, 2013 at 7:18
-
@Prady, thanks for the reply. No i am not using VF page for Opportunity– Lavanya SanathkumarJul 30, 2013 at 7:30
-
@LavanyaSanathkumar: What is it that you have tried??– SamJul 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– PradyJul 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.– Lavanya SanathkumarJul 30, 2013 at 8:39
2 Answers
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"/>
<apex:detail/>