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
Eager-2-LearnEager-2-Learn 

Trying to get a confirmation box before and after executing a custome clone process

Hello again,

 

I appreciate everyone's help.  I am new to all this stuff, Apex, OOP, Java, and HTML.

 

I have created a custom clone process that clones the opportunity and related partner records.  I would like to have a confirmation box (Are you sure?) and if the user clicks yes then create the clone otherwise stay at the original Opportunity page.  If they click Yes, then run my custom class/method that clones and finally pop up an ok box that just lets them know the clone was successful.  When they click 'Ok' then they should see the cloned opportunity.

 

Right now they click my custom button and then the current opp gets cloned and they see the new cloned opportunity.

 

Here is my the code that my custom button calls

<apex:page standardController="Opportunity"
     extensions="OppCloneWithPartnerRecsController"
     action="{!oppCloneWithPartners}">
     <apex:pageMessages />
</apex:page>

 

 

I see examples using the java script confirmCancel method but it is not clear to me where I would move the action=oppCloneWithPartners piece???

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Yes, I think you should be directing the user to the VF page and passing the opportunity id that you are going to clone.

 

Something like:

 

 

var loc="/MyVfPage?id={!Opportunity.Id}";
window.parent.location.href = loc;

 

 

All Answers

bob_buzzardbob_buzzard

I think you should be able to do this by using a custom button that executes javascript and only directs to the clone page when the user clicks 'Yes'.

Eager-2-LearnEager-2-Learn

Yes, I believe that is the path as well; however, all these different languages are new for me and I am still struggling on learning.  This is what I put in the custom button but it  tells me that the $Action is not defined.  When I click the Cancel the Opportunity page stays on the screen (this is what I want) but I need to get the "OK" side to work!

 

The java script that I created is below.  Can you please tell me what I am doing wrong?  I believe I should be trying to call the custom VF page?

 

 

function confirmCancel() {
                var isCancel = confirm("Are you sure?");
        if (isCancel) return true;
           return false;
         }

if (confirmCancel()) {
    page.OppCloneWithPartnerRecs;
}

 

bob_buzzardbob_buzzard

Yes, I think you should be directing the user to the VF page and passing the opportunity id that you are going to clone.

 

Something like:

 

 

var loc="/MyVfPage?id={!Opportunity.Id}";
window.parent.location.href = loc;

 

 

This was selected as the best answer
Eager-2-LearnEager-2-Learn

It worked:smileyvery-happy:

 

I am still amazed that I got a process that clones an opportunity and all related partner records and it has a confirmation before the cloning starts.  I could not have done this without everyone who has helped through this forum.

 

I am still scratching my head on how some of this stuff works.  Here is the final code in the custom button:

 

Can you explain how pass the opportunity id is getting picked up by my VF page?  That code was previously pasted in this communication stream.  I have done the the hello world for VF page and the wizard example and got them to work but it all still has not clicked like programming in Visual Basic or MS Access that I know pretty well.

function confirmCancel() {
                var isCancel = confirm("Are you sure?");
        if (isCancel) return true;
           return false;
         }

if (confirmCancel()) {
    var loc="/apex/OppCloneWithPartnerRecs?id={!Opportunity.Id}";
    window.parent.location.href = loc;
}

 

 

ahab1372ahab1372

you don't have to write your own function, use the javascript function "confirm". You can create a custom button of type Onclick Javascript with the following javascript code:

 

if( confirm("Sure you want to clone?")){
window.top.location = "/apex/yourPage?yourParameter=ParameterValue&oppID={!Opportunity.Id}";
}

 

same thing works in VF pages too, you just have to wrap it in an onClick handler yourself:

 

 

<apex:commandButton action="{!send}" value="Send" id="doSend" 
                    onclick="if(confirm('Sure you want to send?')) {document.getElementById('processing').style.display = 'block'; return true;} else return false;"/>

 

 

Eager-2-LearnEager-2-Learn

Thank you for the additional information.  If I am putting the pieces together just a little your suggestion would not work for me because I have a custom button the out of the box opportunity page.  That is why I needed the confirmation function to be called from there and in turn call my VF page.  What I have is working like a charm but if you have further suggestions or concerns with my approach please continue to communicate your thoughts.   I truly appreciate it.

bob_buzzardbob_buzzard

If you have a VisualForce page that uses a standard controller, part of the functionality provided by the standard controller is to retrieve the record identified by the 'id' parameter on the URL and populate whichever fields you have used in the page.   Neat eh?

ahab1372ahab1372

the first of my examples above actually works with a custom button on a standard detail page (that's how I use it);

 

 

if( confirm("Sure you want to clone?")){
 window.top.location = "/apex/yourPage?yourParameter=ParameterValue&oppID={!Opportunity.Id}";
}

 

 

Eager-2-LearnEager-2-Learn

Sure enough that worked too (happy-happy)

 

The next project the Stake Holders I believe they are going throw at me soon (it just a whisper wish right now) is the ability to close an account say because a business changes their name (it is happening more and more lately I guess because of the economy).  But if the account is closed (say a checkbox  to represent closed) then they want something automated that replicates the closed account but it would get the new name and all contacts and only the current opportunity and all related records to the opportunity must be created.

 

I believe I will use that Opportunity wizard example that I created from one of SFDC's example a few months ago as a starter template.

 

I am thinking the a button on the Account page that says Close Account.  When the user clicks it then the first page would come up with the current account name and a blank field for them to enter the new account name.  When they click a button that says Close and Create all the horse work to create the the temporary objects that replicate the records such as the account being closed, related contact id's, opp id's, and all the opportunity related records just for the most recent opportunity.  Then magically iterate through that junk pile to create the new account and all the related data.

 

I am just grasshopper just starting to crawl and they think I can pull something like that off!  They have high expectations of me--I only hope that I can pull it off.

 

I am sure I will be creating a post in the future on this topic if they make this a requirement.  Again, it has just been talk but you know if someone dreams it a programmer has to make it happen.. Thanks again so much.

 

if( confirm("Sure you want to clone the opportunity an related partner record(s)?") ){
 window.top.location = "/apex/OppCloneWithPartnerRecs?id={!Opportunity.Id}";
}

 

 

 

miiWorksmiiWorks

Hi Tom

 

Is there any chance you could publish your final code on the message box, im in a similar situation


Thanks


Dave

Eager-2-LearnEager-2-Learn

Hi Dave,

 

It has been awhile but I do not remember having to actually use the code as of yet.  But if you check on the first page of this post and the comment just under the green post (solution), I posted some code that I believe you just reference inside your custom button.  You would have to replace the VF page with your VF page.  Hope that helps.