0

I have a custom tab which displays a vf page on opening and redirects further So I had to insert another page in between and update user record field and redirect to original location so I inserted my page in between but the original page is redirecting to my page but not updating user record and showing error now it shows error page.

My page

 <apex:page controller="reactivateUser" action="{!reactivateUserMethod}">
 <div> Your account was deactivated due to inactivity.You will be redirected to next page after reactivation now.
 </div>
 </apex:page>

Controller

 public with sharing class reactivateUser {
public reactivateUser(){}
public string reactivateUserMethod(){
    String userId= UserInfo.getUserId();
    User currentUser = [select lmscons__CFS_Status__c from user where id =: userid];
    currentUser.lmscons__CFS_Status__c = 'Active';
    update currentUser;  
    return PRM_Settings__c.getInstance('LMSLearningUrl')==null ? '01r18000000Cnkh' : PRM_Settings__c.getInstance('LMSLearningUrl').Value__c;
  }
  }

I am redirecting it to page where original page was redirected

3
  • 2
    Please post your code and the error message
    – d_k
    Apr 26, 2017 at 9:36
  • Whats the error you are getting @ishan
    – Samir
    Apr 26, 2017 at 12:21
  • @Samir it's showing the error page (a default page that opens when a recognised url is not opened)
    – Ishan
    Apr 26, 2017 at 12:23

1 Answer 1

1

You are returning a String in your method used in action attribute of apex:page. You need to return a PageReference with the URL it should navigate it to.

So modify your method to this:

public PageReference reactivateUserMethod(){
    String userId= UserInfo.getUserId();
    User currentUser = [select lmscons__CFS_Status__c from user where id =: userid];
    currentUser.lmscons__CFS_Status__c = 'Active';
    update currentUser;  
    String navURL = PRM_Settings__c.getInstance('LMSLearningUrl')==null ? '01r18000000Cnkh' : PRM_Settings__c.getInstance('LMSLearningUrl').Value__c;
    return PageReference('/'+navURL); //Remove the / if your custom setting's value already contains a legitimate URL.
  }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .