You need to sign in to do that
Don't have an account?
max.alexander1.3945796734965325E12
Prompt user to confirm when calling VF page from custom button
HI I have following VF page
it called controller
this controller deletes all Opportunity Line items, ti works just fin, is there any way i can add a prompt to ask user Are yo USure you want to delete?
If they say yes then Delete if they say No then go back to the Opportunity page, i tried numebr us thisng but i cna get th eprobpt appear stright away, i moves me to VF page with command button then it prompts me if i'm sure, is ther any way to go directly to prompt and hten execute controller?
<apex:page StandardController="Opportunity" extensions="DeleteOpportunityLIneItems" action="{!Autorun}" > </apex:page>
it called controller
public class DeleteOpportunityLIneItems { Opportunity oli; public DeleteOpportunityLIneItems(ApexPages.StandardController stdController){ this.oli = (Opportunity)stdController.getRecord(); } public PageReference autoRun() { OpportunityLineItem[] objsToDelete = [SELECT id FROM OpportunityLIneItem WHERE Opportunityid = :this.oli.id]; delete objsToDelete; PageReference pageRef = new PageReference('/' + Oli.id); pageRef.setRedirect(true); return pageRef; } }
this controller deletes all Opportunity Line items, ti works just fin, is there any way i can add a prompt to ask user Are yo USure you want to delete?
If they say yes then Delete if they say No then go back to the Opportunity page, i tried numebr us thisng but i cna get th eprobpt appear stright away, i moves me to VF page with command button then it prompts me if i'm sure, is ther any way to go directly to prompt and hten execute controller?
Got it what you are looking for,below should work for you.You should create a custom button with below attributes :-
Display Type : Detail Page Button
Behavior : Execute Javascript
Content Source : Onclick Javascript
and in the text box copy the below JS code , If this helps,please mark it as best answer to help others :)
All Answers
<script>
function popup()
{
var p = prompt('Please press yes or no to delete' );
if (p == 'yes')
{
alert("oppurtunity going to delete");
}
else
{
window.location="http://www.newlocation.com";
}
</script>
and in the commandbutton
<apex:commandbutton onclick="popup" Value="Delete">
If it helps mark it as best answer
and then use this function on Onclick event of commandbutton something like below :-
If this helps,please mark it as best answer to help others :)
this will show to the confirm box and once you selected yes it will call you Autorun method.
Please mark my answer as a solution to your question if it solves your problem.
<apex:page StandardController="Opportunity" extensions="DeleteOpportunityLIneItems" >
<script>
var r = confirm('Are you sure you want to delete');
if (r == true) {
callAutorun() ;
}
</script>
<apex:form>
<apex:actionFunction action="{!Autorun}" name="callAutorun" />
</apex:form
</apex:page>
gives me the alert whic is perfect but does not executte !AutoRun for some reason
alert('Do you want to proceed?');
If you want to pass id to some page use the below one,
location.href="/apex/YourPageName?EmailtempId={!Opportunity.Id}"
get the warning
but get this error
Formula Expression is required on the action attributes.
it shows another page with the button, when i press it and say yes it delete teh line items, but if i press cancell it does nothing
what i need is this button not to show at all as it is extra step that i dont need
VF page :-
Apex Class :-
Got it what you are looking for,below should work for you.You should create a custom button with below attributes :-
Display Type : Detail Page Button
Behavior : Execute Javascript
Content Source : Onclick Javascript
and in the text box copy the below JS code , If this helps,please mark it as best answer to help others :)