My VF code
<apex:page standardController="Contact" extensions="Restore_Former_User" action="{!formerUserUpdate}" >
<apex:pageMessages ></apex:pageMessages>
<apex:sectionHeader title="Open Salesforce Case and Pop Page"/>
<apex:outputPanel >If you see this page, something went wrong. Please contact [email protected] for assistance.
</apex:outputPanel>
</apex:page>
and
Controller code
public class Restore_Former_User {
Contact cont=new Contact();
Account acc=new Account();
Contact conobj=new Contact();
string strConId;
set<String> tmpString = new set<String>();
id accId;
boolean validateformeruser;
public Restore_Former_User(ApexPages.StandardController stdcontroller) {
this.conobj= (Contact)stdController.getRecord();
System.debug('The value of the current conobj-------------------------->'+conobj);
}
// Code invoked on page load.
public PageReference formerUserUpdate() {
String strConId = ApexPages.currentPage().getParameters().get('id');
System.debug('The value of the current Contact ID-------------------------->'+strConId );
cont=[select id,OMG_ContactType__c,OMG_FormerUserRel__c ,account.id,Clear_Trust_User_Name__c from contact where id=:strConId limit 1];
System.debug('The value of cont is---->'+cont);
if(cont.OMG_ContactType__c != Null){
tmpString.addAll(cont.OMG_ContactType__c.split(';'));
System.debug('The value of the tmpString-------------------------->'+tmpString);
}
String[] stringList = new String[0];
if(tmpString.size() > 0){
validateformeruser = checkformeruser (tmpString);
System.debug('The value of the validateformeruser-------------------------->'+validateformeruser);
if(validateformeruser == False){
System.debug('<--------------------------Not Former User--------------------->');
//ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Type has to be Former User'));
try{
if(!tmpString.contains('Former User')){
throw new CustomException('Type has to be Former User');
}
}
catch(Exception ex){
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.Error, ex.getMessage());
ApexPages.addMessage(msg);
}
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info, 'Type has to be Former User'));
apexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Type has to be Former User');
ApexPages.addmessage(msg);
}
else{
System.debug('Contains Former User -------------------------->'+tmpString);
tmpString.remove('Former User');
System.debug('The value of the Former User removal-------------------------->'+tmpString);
if(tmpString.size() == 0){
cont.OMG_ContactType__c = 'User';
System.debug('<------------------The value of tmpString is inside NUll condition-------------------------->');
}else{
for(string item: tmpString) {
stringList.add(String.valueOf(item));
}
System.debug('The value of the stringList-------------------------->'+stringList);
String result = String.join(stringList,';');
System.debug('The value of the result-------------------------->'+result);
cont.OMG_ContactType__c = result;
}
accId=cont.account.id;
cont.accountId=cont.OMG_FormerUserRel__c;
cont.OMG_FormerUserRel__c=accId;
try{
update cont;
}
catch(System.DMLException e){
for(Integer i=0;i<e.getNumDml();i++) {
System.debug(e.getDMLMessage(i));
}
}
if(cont.Clear_Trust_User_Name__c != Null){
String sessionID = UserInfo.getSessionId();
string url = 'https://'+Label.SalesforceUtilityServer+'/contact2.0/restoreFormerUser.html?id='+cont.Id+'session='+sessionID;
//var popURL = "https://{! $Label.SalesforceUtilityServer }/contact2.0/restoreFormerUser.html?id={!Contact.Id}&session={!$Api.Session_ID}";
PageReference reference=new PageReference(url);
reference.setRedirect(true);
return reference;
}else{
// Send the user to the detail page for the case that gets updated.
PageReference contactPage= new ApexPages.StandardController(cont).view();
contactPage.setRedirect(true);
return contactPage;
}
}
}
return null;
}
public boolean checkformeruser (set<String> strg){
boolean bol;
if(!tmpString.contains('Former User')){
bol = False ;
}else{
bol = True ;
}
return bol;
}
}
i am hitting this button from Contact detail page (Standard)
i getting the error message but in a vf page not on the standard contact detail page , screen shot below

i need the error to be on the standard contact detail page from where this button is hit .
Thanks for the help