You need to sign in to do that
Don't have an account?
cher
Showing an alert box in a visualforce page
HI,
I have a custom button "Remove from Territory", which when clicked deletes data, I want the user to get a promopt asking "Are you sure you want to RemoveFromTerritory", if the user clicks Yes only then the action should be executed. Thanks in advance..
VF Page Code:-
<apex:page standardcontroller="Account" extensions="RemoveFromTerritory" action="{!deleteterritory}">
</apex:page>
Controller Code:-
global class RemoveFromTerritory {
public static List<UserTerritory> UserList{get;set;}
public RemoveFromTerritory (ApexPages.StandardController cont){
UserList=new List<UserTerritory>();
}
// public String u {get; set;}
//u = Userinfo.getUserId();
String UserId=Userinfo.getUserId();
static pagereference movetonext()
{
pagereference pageref= new pagereference('/servlet/servlet.Integration?lid=01rA0000000RGei&ic=1');
pageref.setRedirect(true);
return pageref;
}
webservice static void deleteterritory(id accountid){
/*if(apexpages.currentpage().getParameters().get('id')!=null)
accountid=apexpages.currentpage().getParameters().get('id');*/
/* system.debug('@@@'+accountid);
Account acc=[select id from Account where id=:accountid];
UserList=[Select UserId,TerritoryId from UserTerritory where UserId=:Userinfo.getUserId()];
//List<Group> GroupList=new List<Group>([Select Id from Group
// where RelatedId =:UserList.TerritoryId]);
Set<Id> TerritoryIds=new Set<Id>();
for(UserTerritory ust: UserList){
TerritoryIds.add(ust.TerritoryId);
}
List<Group> GroupList=[Select Id from Group
where RelatedId IN:TerritoryIds
and Type='Territory'];
Set<Id> GroupIds=new set<Id>();
for(Group g: GroupList){
GroupIds.add(g.id);
}
AccountShare AccSh=[Select Id from AccountShare where UserorGroupId IN: GroupIds and AccountId=:acc.id];
///AccountShare AccSh= [Select Id from AccountShare where UserorGroupId=:GroupList];
delete AccSh;
movetonext(); */
}
public pagereference deleteterritory(){
String accountid;
accountid=apexpages.currentpage().getParameters().get('id');
system.debug('@@@'+accountid);
Account acc=[select id from Account where id=:accountid];
UserList=[Select UserId,TerritoryId from UserTerritory where UserId=:Userinfo.getUserId()];
//List<Group> GroupList=new List<Group>([Select Id from Group
// where RelatedId =:UserList.TerritoryId]);
Set<Id> TerritoryIds=new Set<Id>();
for(UserTerritory ust: UserList){
TerritoryIds.add(ust.TerritoryId);
}
List<Group> GroupList=[Select Id from Group
where RelatedId IN:TerritoryIds
and Type='Territory'];
Set<Id> GroupIds=new set<Id>();
for(Group g: GroupList){
GroupIds.add(g.id);
}
AccountShare AccSh=[Select Id from AccountShare where UserorGroupId IN: GroupIds and AccountId=:acc.id];
///AccountShare AccSh= [Select Id from AccountShare where UserorGroupId=:GroupList];
delete AccSh;
pagereference pageref= new pagereference('/servlet/servlet.Integration?lid=01rA0000000RGei&ic=1');
pageref.setRedirect(true);
return pageref;
}
}
I have a custom button "Remove from Territory", which when clicked deletes data, I want the user to get a promopt asking "Are you sure you want to RemoveFromTerritory", if the user clicks Yes only then the action should be executed. Thanks in advance..
VF Page Code:-
<apex:page standardcontroller="Account" extensions="RemoveFromTerritory" action="{!deleteterritory}">
</apex:page>
Controller Code:-
global class RemoveFromTerritory {
public static List<UserTerritory> UserList{get;set;}
public RemoveFromTerritory (ApexPages.StandardController cont){
UserList=new List<UserTerritory>();
}
// public String u {get; set;}
//u = Userinfo.getUserId();
String UserId=Userinfo.getUserId();
static pagereference movetonext()
{
pagereference pageref= new pagereference('/servlet/servlet.Integration?lid=01rA0000000RGei&ic=1');
pageref.setRedirect(true);
return pageref;
}
webservice static void deleteterritory(id accountid){
/*if(apexpages.currentpage().getParameters().get('id')!=null)
accountid=apexpages.currentpage().getParameters().get('id');*/
/* system.debug('@@@'+accountid);
Account acc=[select id from Account where id=:accountid];
UserList=[Select UserId,TerritoryId from UserTerritory where UserId=:Userinfo.getUserId()];
//List<Group> GroupList=new List<Group>([Select Id from Group
// where RelatedId =:UserList.TerritoryId]);
Set<Id> TerritoryIds=new Set<Id>();
for(UserTerritory ust: UserList){
TerritoryIds.add(ust.TerritoryId);
}
List<Group> GroupList=[Select Id from Group
where RelatedId IN:TerritoryIds
and Type='Territory'];
Set<Id> GroupIds=new set<Id>();
for(Group g: GroupList){
GroupIds.add(g.id);
}
AccountShare AccSh=[Select Id from AccountShare where UserorGroupId IN: GroupIds and AccountId=:acc.id];
///AccountShare AccSh= [Select Id from AccountShare where UserorGroupId=:GroupList];
delete AccSh;
movetonext(); */
}
public pagereference deleteterritory(){
String accountid;
accountid=apexpages.currentpage().getParameters().get('id');
system.debug('@@@'+accountid);
Account acc=[select id from Account where id=:accountid];
UserList=[Select UserId,TerritoryId from UserTerritory where UserId=:Userinfo.getUserId()];
//List<Group> GroupList=new List<Group>([Select Id from Group
// where RelatedId =:UserList.TerritoryId]);
Set<Id> TerritoryIds=new Set<Id>();
for(UserTerritory ust: UserList){
TerritoryIds.add(ust.TerritoryId);
}
List<Group> GroupList=[Select Id from Group
where RelatedId IN:TerritoryIds
and Type='Territory'];
Set<Id> GroupIds=new set<Id>();
for(Group g: GroupList){
GroupIds.add(g.id);
}
AccountShare AccSh=[Select Id from AccountShare where UserorGroupId IN: GroupIds and AccountId=:acc.id];
///AccountShare AccSh= [Select Id from AccountShare where UserorGroupId=:GroupList];
delete AccSh;
pagereference pageref= new pagereference('/servlet/servlet.Integration?lid=01rA0000000RGei&ic=1');
pageref.setRedirect(true);
return pageref;
}
}
<apex:page standardcontroller="Account" extensions="RemoveFromTerritory" action="{!deleteterritory}">
<apex:form >
<apex:commandButton value="click to confirm" onclick="return confirm('are you want to remove the Account from the territory');"/>
</apex:form>
</apex:page>
The only thing you are getting wrong here is "you are using action of page". The page action method is very first method called after constructor of controller.
Below is the updated code:
<apex:page standardcontroller="Account" extensions="RemoveFromTerritory">
Let me know if you still face issues, Happy coding!!
I tried the updated code but still the alert box is not showing up.
https://www.codekiat.com/2019/07/confirm-dialog-in-salesforce-lightning.html
--
Naveen K N