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
Amit Singh.ax1042Amit Singh.ax1042 

How to display alert box???

Hi Friends,

i Have Created an object Estimate... and created a custom button Approve...and override it with a visualforce...

 

<apex:page standardController="Estimate_Line_Items__c" extensions="ApproveEstimateController" action="{!autoRun}">
  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>
</apex:page>




Apec Class-->

public class ApproveEstimateController 
{
private final Estimate_Line_Items__c est;
    public ApproveEstimateController(ApexPages.StandardController controller)
    {
    this.est=(Estimate_Line_Items__c)controller.getRecord();
    }
 public PageReference autoRun() 
    {
    
         try
        {
        est.Approved__c=true;
        update est;
        }
        catch(System.DMLException e)
        {
        return null;
        }
    
     String theId = ApexPages.currentPage().getParameters().get('id');
     if (theId == null) 
        {
            // Display the Visualforce page's content if no Id is passed over
            return null;
        }
        PageReference pageRef = new PageReference('/' + theId);
        pageRef.setRedirect(true);
        return pageRef;
    
    }        

 
}

 

 

now the thing is that,,,when i am pressing this button from any Estimate Line Items Record page...

i want a popup window to ask "Do you want to Approve this Item"...after pressing yes it should process otherwise nothing shoul happen...

How it can be???

goabhigogoabhigo

Override the Approve button with JavaScript behaviour. In the JavaScript specify alert and then redirect to your VF page.

Amit Singh.ax1042Amit Singh.ax1042

hey Abhi...

could you please provide me any sample that can help me solve my issue...

 

actually i had tried in your way but i dont know hoq to give url... and if you want that your new page should be open in new window then how to do this...

ashish raiashish rai

Hello,

   Use this:

<apex:page standardController="Estimate_Line_Items__c" extensions="ApproveEstimateController" >
  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>
  <script>
    function cnfrmApprove()
    {
      var r=confirm('Do you want to Approve this Item?');
       
      if (r==true)
      {     
      delStep2();     
      }
    else
      {
    //  alert("You pressed Cancel!");
      }
     
    }
    window.onload = cnfrmApprove;
  </script>
  <apex:actionFunction name="delStep2" action="{!autoRun}">
                    </apex:actionfunction>
</apex:page>

Think this will help you.Make sure there is no any error in javascript code.


goabhigogoabhigo

Ok, here you go... Try this code in your button's javascript behaviour.

var msg=confirm('Do you want to Approve this Item?'); 
if (msg==true) {
 window.open('/apex/YourVFPage?id='+ObjectId);
}

 

ObjectId can be pasted using merge field by selecting appropriate object in 'Select Field Type' picklist and field in 'Insert Field' picklist. If it was Opportunity record the merge field will look like : {!Opportunity.Id}

 

This will also open your VF page in new window.

Amit Singh.ax1042Amit Singh.ax1042

Abhi It is working fine...

but the thing is that... i do not want a new window...

i want that after clicking it should open popup and after pressing OK... i should be on same page (after process i am getting new window)

goabhigogoabhigo

Then modify like this:

window.open('/apex/YourVFPage?id='+ObjectId, '_self');

 

 

ashish raiashish rai

Hello,

  Please select Behaviour as Display in Existing Window without Side Bar or Header inside Button Behaviour..This will help you to meet your reqirement if you reqirement in on that VF page.

<apex:page standardController="Estimate_Line_Items__c" extensions="ApproveEstimateController" >
  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>
  <script>
    function cnfrmApprove()
    {
      var r=confirm('Do you want to Approve this Item?');
       
      if (r==true)
      {     
      delStep2();     
      }
    else
      {
    //  alert("You pressed Cancel!");
      }
     
    }
    window.onload = cnfrmApprove;
  </script>
  <apex:actionFunction name="delStep2" action="{!autoRun}">
                    </apex:actionfunction>
</apex:page>

Think this will help you.Make sure there is no any error in javascript code.

goabhigogoabhigo

You can also check out Ashish's suggestion. But overriding default onload functionality results in some strange behaviour (one which I faced was date picker not working).