I have developed one visualforce page and controller for account object and checking account.type is empty or not. If account.type is empty then page should be redirect to other page, this should be execute whenever page is reload or refresh. I called docheck method inside constructor but page is not redirecting to other page when account.type is empty.
Can anybody help me on this requirement
public class myaccountcontroller
{
public String accId {get;set;}
public myaccountcontroller(ApexPages.StandardController sc)
{
accId = ApexPages.CurrentPage().getparameters().get('id');
doCheck();
}
public PageReference doCheck()
{
Account acc = [SELECT Id,Name,Type FROM Account WHERE Id=:accId];
if(acc.Type =='')
{
PageReference mainHome= Page.Custom_Error_Page;
mainHome.setRedirect(true);
return mainHome;
}
}
}
<apex:page standardcontroller="Account" extensions="myaccountcontroller">
-------------------
-------------------
-------------------
</apex:page>
ApexPages.Message
so they can read the error.if (String.isBlank(acc.Type)) ...
is the preferred construction as it tests for both null and empty string