You need to sign in to do that
Don't have an account?
krishna p 28
Controller wizard
HI,
I have written a wizard for 3 pages. Problem is with page redirection, in debug I cna see the apex call for page redirection is executed, but page is not redirecting.
public class ONC_CMT_RegistrationWizard
{
public ONC_CMT_RegistrationWizard() {
}
private ApexPages.StandardController con{get;set;}
Account account;
APS_Survey_Questionaries__c surveyquestionaries;
Survey_Result__c surveyresult;
Survey_Response__c surveyresponse;
//account object variables
public string firstparam{get;set;}
public string secondparam{get;set;}
public string thirdparam{get;set;}
public string fourthparam{get;set;}
public string fifthparam{get;set;}
public string sixthparam{get;set;}
public string seventhparam{get;set;}
public string eighthparam{get;set;}
public string ninthparam{get;set;}
public string tenthparam{get;set;}
public string eleventhparam{get;set;}
public string twelethparam{get;set;}
public string thirteenthparam{get;set;}
public string fourteenthparam{get;set;}
Public Boolean optIn1{ get;set; }//optin check box in Consent page
public Boolean optIn2{ get;set; }//optin check box in Registration page
//survey variables
public String q1;
public String q2;
public String q3;
public String q4;
public String q5;
public String diagnosismonth { get; set; }
public String diagnosisyear { get; set; }
public String Prescribed_taking_Medicine { get; set; }
public String duration { get; set; }
public String onlyMedicine { get; set; }
public String engagedinCommunity { get; set; }
public Account getAccount()
{
if(account == null)
account = new Account();
return account;
}
/*public Survey_Response__c getSurvey_Response__c()
{
if(surveyresponse == null)
surveyresponse = new Survey_Response__c();
return surveyresponse;
}
public Survey_Result__c get{
if(surveyresult == null)
surveyresult = new Survey_Result__c();
return surveyresult;}
//getSurvey_Result__c()
*/
public ONC_CMT_RegistrationWizard(ApexPages.StandardController controller)
{
con = controller;
}
public PageReference step1()
{
//Page.ONC_CMT_Survey.setRedirect(false);
return Page.ONC_CMT_survey;
}
public PageReference step2()
{
return Page.ONC_CMT_Registration_info;
}
private date dateconvert(string dat)
{
//String entereddate = ApexPages.currentPage().getParameters().get('thirdparam');
List<String> myDate = dat.split('/');
System.debug(mydate);
Integer myIntDate = integer.valueOf(mydate[1]);
Integer myIntMonth = integer.valueOf(mydate[0]);
Integer myIntYear = integer.valueOf(mydate[2]);
Date dt = Date.newInstance(myIntYear, myIntMonth, myIntDate);
return dt;
}
Public PageReference save()
{
try{
string entereddate = ApexPages.currentpage().getParameters().get('thirdparam');
RecordType rt = [select Id from RecordType where Name = 'Patients' and SobjectType = 'Account' limit 1];
System.debug('############'+rt.Id);
//System.debug(''+);
// account.RecordTypeId = rt.Id;
account.FirstName = ApexPages.currentpage().getParameters().get('firstparam');
account.LastName = ApexPages.currentpage().getParameters().get('secondparam');
account.APS_DOB__c = dateconvert(entereddate);
account.APS_Gender__c= ApexPages.currentpage().getParameters().get('fourthparam');
account.BillingStreet = ApexPages.currentpage().getParameters().get('fifthparam');
account.BillingCity = ApexPages.currentpage().getParameters().get('sixthparam');
account.ShippingStreet = ApexPages.currentpage().getParameters().get('seventhparam');
account.BillingState = ApexPages.currentpage().getParameters().get('eighthparam');
account.BillingPostalCode = ApexPages.currentpage().getParameters().get('ninthparam');
account.PersonEmail = ApexPages.currentpage().getParameters().get('tenthparam');
account.Password__c = ApexPages.currentpage().getParameters().get('twelethparam');
account.ONC_Confirm_Password__c = ApexPages.currentpage().getParameters().get('thirteenthparam');
account.PersonMobilePhone = ApexPages.currentpage().getParameters().get('fourteenthparam');
account.APS_Preferred_Contact_Method__c = 'Email';
account.ONC_CMT_Opt_In_1__c = optin1;//use apex:inputField in page; insert account for 2 checkboxes
account.ONC_CMT_Opt_In_2__c = optin2;
insert account;
q1 = q1.substring(4);
q2 = q2.substring(4);
q3 = q3.substring(4);
q4 = q4.substring(4);
q5 = q5.substring(4);
System.debug('Qusetion 1 without leading chars'+q1);
diagnosismonth = ApexPages.CurrentPage().getParameters().get('monthparam');
System.debug('************'+diagnosismonth);
diagnosisyear = ApexPages.CurrentPage().getParameters().get('yearparam');
System.debug('************year'+diagnosisyear );
Prescribed_taking_Medicine = ApexPages.CurrentPage().getParameters().get('prescribedparam');
System.debug('************prescribed'+Prescribed_taking_Medicine );
duration = ApexPages.CurrentPage().getParameters().get('durationparam');
System.debug('************duration -Months'+duration );
onlyMedicine = ApexPages.CurrentPage().getParameters().get('onlyparam');
System.debug('************onlyMedicine Yes/No'+onlyMedicine );
engagedinCommunity = ApexPages.CurrentPage().getParameters().get('Engagedparam');
System.debug('************engagedinCommunity -Yes/No'+engagedinCommunity );
Integer month = Integer.valueOf(diagnosismonth);
Integer year = Integer.valueOf(diagnosisyear);
Date dt = Date.newInstance(year,month,0);
//Survey_Result__c surveyresult = new Survey_Result__c();
Map<string, string> sr = new Map<string, string>();
sr.put(q1,String.ValueOf(dt));
sr.put(q2,Prescribed_taking_Medicine);
sr.put(q3,duration );
sr.put(q4,onlyMedicine );
sr.put(q5,engagedinCommunity);
//System.debug('2nd Answer'+sqids.get(1));
System.debug(sr.values());
List<Survey_Result__c> surveyres = new List<Survey_Result__c>();
Survey_Response__c sresponse = new Survey_Response__c(APS_SurveyName__c='My Survey',ONC_CMT_Account__c = account.id);
insert sresponse;
for(String idval:sr.keyset()){
Survey_Result__c result=new Survey_Result__c();
result.APS_Question__c = idval;
result.APS_Answer__c = sr.get(idval);
result.Survey_Response__c = sresponse.id;
surveyres.add(result);
}
insert surveyres;
PageReference completePage = new PageReference('/apex/ONC_CMT_Registration_complete');
//completePage.setredirect(true);
return completePage;
}
catch (Exception ex)
{
System.debug('All Exeptions Here'+ex.getStackTraceString());
}
return null;
}
}
I have written a wizard for 3 pages. Problem is with page redirection, in debug I cna see the apex call for page redirection is executed, but page is not redirecting.
public class ONC_CMT_RegistrationWizard
{
public ONC_CMT_RegistrationWizard() {
}
private ApexPages.StandardController con{get;set;}
Account account;
APS_Survey_Questionaries__c surveyquestionaries;
Survey_Result__c surveyresult;
Survey_Response__c surveyresponse;
//account object variables
public string firstparam{get;set;}
public string secondparam{get;set;}
public string thirdparam{get;set;}
public string fourthparam{get;set;}
public string fifthparam{get;set;}
public string sixthparam{get;set;}
public string seventhparam{get;set;}
public string eighthparam{get;set;}
public string ninthparam{get;set;}
public string tenthparam{get;set;}
public string eleventhparam{get;set;}
public string twelethparam{get;set;}
public string thirteenthparam{get;set;}
public string fourteenthparam{get;set;}
Public Boolean optIn1{ get;set; }//optin check box in Consent page
public Boolean optIn2{ get;set; }//optin check box in Registration page
//survey variables
public String q1;
public String q2;
public String q3;
public String q4;
public String q5;
public String diagnosismonth { get; set; }
public String diagnosisyear { get; set; }
public String Prescribed_taking_Medicine { get; set; }
public String duration { get; set; }
public String onlyMedicine { get; set; }
public String engagedinCommunity { get; set; }
public Account getAccount()
{
if(account == null)
account = new Account();
return account;
}
/*public Survey_Response__c getSurvey_Response__c()
{
if(surveyresponse == null)
surveyresponse = new Survey_Response__c();
return surveyresponse;
}
public Survey_Result__c get{
if(surveyresult == null)
surveyresult = new Survey_Result__c();
return surveyresult;}
//getSurvey_Result__c()
*/
public ONC_CMT_RegistrationWizard(ApexPages.StandardController controller)
{
con = controller;
}
public PageReference step1()
{
//Page.ONC_CMT_Survey.setRedirect(false);
return Page.ONC_CMT_survey;
}
public PageReference step2()
{
return Page.ONC_CMT_Registration_info;
}
private date dateconvert(string dat)
{
//String entereddate = ApexPages.currentPage().getParameters().get('thirdparam');
List<String> myDate = dat.split('/');
System.debug(mydate);
Integer myIntDate = integer.valueOf(mydate[1]);
Integer myIntMonth = integer.valueOf(mydate[0]);
Integer myIntYear = integer.valueOf(mydate[2]);
Date dt = Date.newInstance(myIntYear, myIntMonth, myIntDate);
return dt;
}
Public PageReference save()
{
try{
string entereddate = ApexPages.currentpage().getParameters().get('thirdparam');
RecordType rt = [select Id from RecordType where Name = 'Patients' and SobjectType = 'Account' limit 1];
System.debug('############'+rt.Id);
//System.debug(''+);
// account.RecordTypeId = rt.Id;
account.FirstName = ApexPages.currentpage().getParameters().get('firstparam');
account.LastName = ApexPages.currentpage().getParameters().get('secondparam');
account.APS_DOB__c = dateconvert(entereddate);
account.APS_Gender__c= ApexPages.currentpage().getParameters().get('fourthparam');
account.BillingStreet = ApexPages.currentpage().getParameters().get('fifthparam');
account.BillingCity = ApexPages.currentpage().getParameters().get('sixthparam');
account.ShippingStreet = ApexPages.currentpage().getParameters().get('seventhparam');
account.BillingState = ApexPages.currentpage().getParameters().get('eighthparam');
account.BillingPostalCode = ApexPages.currentpage().getParameters().get('ninthparam');
account.PersonEmail = ApexPages.currentpage().getParameters().get('tenthparam');
account.Password__c = ApexPages.currentpage().getParameters().get('twelethparam');
account.ONC_Confirm_Password__c = ApexPages.currentpage().getParameters().get('thirteenthparam');
account.PersonMobilePhone = ApexPages.currentpage().getParameters().get('fourteenthparam');
account.APS_Preferred_Contact_Method__c = 'Email';
account.ONC_CMT_Opt_In_1__c = optin1;//use apex:inputField in page; insert account for 2 checkboxes
account.ONC_CMT_Opt_In_2__c = optin2;
insert account;
q1 = q1.substring(4);
q2 = q2.substring(4);
q3 = q3.substring(4);
q4 = q4.substring(4);
q5 = q5.substring(4);
System.debug('Qusetion 1 without leading chars'+q1);
diagnosismonth = ApexPages.CurrentPage().getParameters().get('monthparam');
System.debug('************'+diagnosismonth);
diagnosisyear = ApexPages.CurrentPage().getParameters().get('yearparam');
System.debug('************year'+diagnosisyear );
Prescribed_taking_Medicine = ApexPages.CurrentPage().getParameters().get('prescribedparam');
System.debug('************prescribed'+Prescribed_taking_Medicine );
duration = ApexPages.CurrentPage().getParameters().get('durationparam');
System.debug('************duration -Months'+duration );
onlyMedicine = ApexPages.CurrentPage().getParameters().get('onlyparam');
System.debug('************onlyMedicine Yes/No'+onlyMedicine );
engagedinCommunity = ApexPages.CurrentPage().getParameters().get('Engagedparam');
System.debug('************engagedinCommunity -Yes/No'+engagedinCommunity );
Integer month = Integer.valueOf(diagnosismonth);
Integer year = Integer.valueOf(diagnosisyear);
Date dt = Date.newInstance(year,month,0);
//Survey_Result__c surveyresult = new Survey_Result__c();
Map<string, string> sr = new Map<string, string>();
sr.put(q1,String.ValueOf(dt));
sr.put(q2,Prescribed_taking_Medicine);
sr.put(q3,duration );
sr.put(q4,onlyMedicine );
sr.put(q5,engagedinCommunity);
//System.debug('2nd Answer'+sqids.get(1));
System.debug(sr.values());
List<Survey_Result__c> surveyres = new List<Survey_Result__c>();
Survey_Response__c sresponse = new Survey_Response__c(APS_SurveyName__c='My Survey',ONC_CMT_Account__c = account.id);
insert sresponse;
for(String idval:sr.keyset()){
Survey_Result__c result=new Survey_Result__c();
result.APS_Question__c = idval;
result.APS_Answer__c = sr.get(idval);
result.Survey_Response__c = sresponse.id;
surveyres.add(result);
}
insert surveyres;
PageReference completePage = new PageReference('/apex/ONC_CMT_Registration_complete');
//completePage.setredirect(true);
return completePage;
}
catch (Exception ex)
{
System.debug('All Exeptions Here'+ex.getStackTraceString());
}
return null;
}
}