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
$$ 

2 scenarios in one button

I have a vfp button that redirects to a standard page on a custom object which is child object of a master object. Now the condition is, on clicking of the button it would take user to a new record insert screen and users can insert their record. However if there is already a record in the child object, instead of going to the new screen it would take user to detail page on click of that button. 

Can anyone please help me to use this functionality in one button. Right now it goes to the new screen only. 

<apex:pageBlock title="Inferno:" >
            <apex:pageBlockSection >    
                <apex:outputPanel >
                    <apex:outputLabel />
                    <apex:outputLabel />
                    <apex:outputText ><b>Inferno Page: </b></apex:outputText>
                    <apex:commandButton value="Inferno Screen" oncomplete="window.open('/a1a/e?{!$Label.Inferno_ID}={!Clover__c.Name}&{!$Label.Inferno_ID}_lkid={!Clover__c.Id}&retURL=%2F{!Clover.Id}','_parent')"  />  </apex:outputPanel>
            </apex:pageBlockSection>


Clover is the master object. 
Matthew CokeMatthew Coke
you'll need to write a controller with a pageref object, then use two urls and set the pageref object according to whether a child object exsists
Harpreet On CloudHarpreet On Cloud
If you do not want to create controller as Matthew pointed, you can do the following

(1) Create a rollup summary field on Clover i.e. on the Master obejct.
(2) Create two apex:commandButton with same value attribute and set the rendered property on each -- show button 1 if rollup value is 0, show button 2 if rollup value is non-0.

Harpreet
OSI Consulting