On Account page, I have a Button which opens a VF page which creates Task record. When I click Edit button on the Task record to update it and click Save, it's redirecting to the Task record page on Desktop in both classic and lightning mode. However, when I am performing same action on Mobile, upon clicking on Save, it is giving me error. Page doesn't exist. Enter a valid URL and try again.
public class Sim_NewTaskController {
//private Task taskObjectParent;
public Task taskObjectParent{get;set;}
private Task tempTask;
public String whoId{get;set;}
public String whatId{get;set;}
public String recordId{get;set;}
public String retURL{get;set;}
private String close;
// these three variables will set when log a call button will clicked on activity history
private String title;
private String tsk5;
private String followup;
public String inputValue{get;set;}
public List<MultiSelect> avaiableContactlList {get;set;}
public List<MultiSelect> avaiableGoalList {get;set;}
public List<MultiSelect> avaiableTopicList {get;set;}
public boolean isNAOProfile{get;set;}
public Integer totalAvaiableGoal {get;set;}
public Integer totalAvaiableTopic {get;set;}
public List<SelectOption> avaiableOptionsContacts{get;set;}
public String selectedContact{get;set;}
public string searchstring {get;set;}
//For SOS Profile
//Set<String> setSOSAvlTopics = new Set<String>{'Account Maintenance', 'Co-Management','Material Request','Referral Process','Divisions','Events','Issue Resolution','New Provider'};
public Sim_NewTaskController(ApexPages.StandardController stdController) {
totalAvaiableGoal = 0;
totalAvaiableTopic = 0;
//this.taskObjectParent = (Task)stdController.getRecord();
avaiableOptionsContacts = new List<SelectOption>();
selectedContact = searchText = '';
tempTask=new Task();
taskObjectParent=new Task();
whatId = ApexPages.currentPage().getParameters().get('what_id');
whoId = ApexPages.currentPage().getParameters().get('who_id');
recordId = ApexPages.currentPage().getParameters().get('id');
close = ApexPages.currentPage().getParameters().get('close');
retURL = ApexPages.currentPage().getParameters().get('retURL');
title = ApexPages.currentPage().getParameters().get('title');
tsk5 = ApexPages.currentPage().getParameters().get('tsk5');
followup = ApexPages.currentPage().getParameters().get('followup');
CheckProfile();
}
public void CheckProfile(){
isNAOProfile=false;
//If Logged in user prfile is NAO profile then replace picklist value like below
//Get looged in user profile
User objUser=[select profile.Name from user where id=:UserInfo.getUserId()];
if(objUser!=null && objUser.profile.Name=='NAO Profile'){
isNAOProfile=true;
}
}
public void filterFields() {
//Get Profile Name of logged in user
string profileName=[select profile.Name from user where id=:UserInfo.getUserId()].profile.Name;
System.debug('taskObjectParent.type------------'+taskObjectParent.type);
avaiableGoalList = new List<MultiSelect>();
avaiableTopicList = new List<MultiSelect>();
if(taskObjectParent.type == 'Sports Medicine Phone Call' || taskObjectParent.type == 'Sports Medicine Visit') {
avaiableTopicList.add(new MultiSelect(false, '2 Day Athlete Guarantee', null));
avaiableTopicList.add(new MultiSelect(false, 'Athletic Training Protocols', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Hospitals', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Medical Coverage', null));
avaiableTopicList.add(new MultiSelect(false, 'New Clinic', null));
avaiableTopicList.add(new MultiSelect(false, 'New Physicians', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Sports Injury Clinics', null));
avaiableTopicList.add(new MultiSelect(false, 'Sponsorships', null));
avaiableTopicList.add(new MultiSelect(false, 'Team Physicals', null));
avaiableGoalList.add(new MultiSelect(false, 'Establishing New Relationships', null));
avaiableGoalList.add(new MultiSelect(false, 'Maintaining Relationship', null));
avaiableGoalList.add(new MultiSelect(false, 'Service Update', null));
}
if(taskObjectParent.type == 'E-mail or Fax' || taskObjectParent.type == 'Follow-Up' || taskObjectParent.type == 'Mailed Collateral/Document' || taskObjectParent.type == 'Office Staff Meeting' || taskObjectParent.type =='Outreach or CME Event' || taskObjectParent.type == 'Out of the Field' || taskObjectParent.type == 'Phone Call' || taskObjectParent.type == 'Unsuccessful Visit' ){
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Co-Management', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'New Provider', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho/Walk-In', null));
}
else {
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Co-Management', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'New Provider', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho/Walk-In', null));
/* if(profileName=='SOS Profile'){
for(String st:setSOSAvlTopics){
avaiableTopicList.add(new MultiSelect(false, st, null));
}
}*/
for( Schema.PicklistEntry f : Task.Goal_of_Activity__c.getDescribe().getPicklistValues()) {
if(isNAOProfile==true){
if(f.getValue()!='CORE Referral Manager Training'){
avaiableGoalList.add(new MultiSelect(false, f.getLabel(), null));
}
}
else{
avaiableGoalList.add(new MultiSelect(false, f.getLabel(), null));
}
}
}
//For Goal
system.debug(taskObjectParent.Id + ' =====> ' + taskObjectParent.Goal_of_Activity__c);
if(string.isNotBlank(taskObjectParent.Goal_of_Activity__c)){
for(MultiSelect goal : avaiableGoalList){
for(string str:taskObjectParent.Goal_of_Activity__c.split(';')){
if(goal.Name == str.trim()){
goal.isChecked = true;
}
}
}
totalAvaiableGoal = taskObjectParent.Goal_of_Activity__c.split(';').size();
}
system.debug('avaiableGoalList--111------------->' + avaiableGoalList);
/*if(isNAOProfile==true){
avaiableTopicList = new List<MultiSelect>();
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'NAO Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'New Clinic', null));
avaiableTopicList.add(new MultiSelect(false, 'New Physician', null));
avaiableTopicList.add(new MultiSelect(false, 'NAO Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho', null));
}*/
//For Topics
system.debug(taskObjectParent.Id + ' =====> ' + taskObjectParent.Topics_Discussed__c);
if(string.isNotBlank(taskObjectParent.Topics_Discussed__c)){
for(MultiSelect goal : avaiableTopicList){
for(string str:taskObjectParent.Topics_Discussed__c.split(';')){
if(goal.Name == str.trim()){
goal.isChecked = true;
}
}
}
totalAvaiableTopic = taskObjectParent.Topics_Discussed__c.split(';').size();
}
system.debug('avaiableTopicList--2222------------->' + avaiableTopicList);
}
// Task cannot be created from contact. Button hidden
public PageReference loadNewTask(){
try{
taskObjectParent=new Task();
//Assign default value
taskObjectParent.ActivityDate=Date.Today();
if(recordId != null){
List<Task> taskList = [select whatId,whoId,ActivityDate ,Priority ,Status,
Activity_Cost__c,OwnerId,Visit_Duration__c,Description,Goal_of_Activity__c ,
Topics_Discussed__c,Subject, Type
from task where id=:recordId limit 1];
if(taskList!= null && taskList.size()>0)
{
taskObjectParent=taskList[0];
whatId = taskList[0].whatId;
whoId = taskList[0].whoId;
inputValue = taskList[0].Type;
}
}
if((whatId != null && !whatId.startsWith('001')) || (whoId!=null && !whoId.startsWith('003'))){
PageReference refObject = new PageReference('/00T/e');
refObject.getParameters().putAll(ApexPages.currentPage().getParameters());
refObject.getParameters().put('nooverride', '1');
refObject.setRedirect(true);
return refObject;
}else{
avaiableContactlList = new List<MultiSelect>();
filterFields();
//We do not create task through contact
if(whatId != null && whatId.startsWith('001')){
//get Account Id to fileter contact based on profile
Set<string> setAccountId=new Set<string>();
if(Test.isRunningTest()){
setAccountId.add(whatId);
}
string labelActId=Label.Core_Account_Id;
if(isNAOProfile==true){
labelActId=Label.NAO_Account_Id;
}
if(string.isNotBlank(labelActId)){
for(string st:labelActId.split(',')){
setAccountId.add(st);
}
for(Contact contactObject : [Select id,Name,Email, AccountId From Contact where
RecordType.Name='Internal Provider' AND Inactive__c = false order by Name]){
avaiableContactlList.add(new MultiSelect(false, contactobject.Name, contactObject.Id));
avaiableOptionsContacts.add(new SelectOption(contactObject.Id, contactObject.Name));
}
}
taskObjectParent.WhatId = whatId;
taskObjectParent.OwnerId = Userinfo.getUserId();
}
if(close != null && close =='1'){
taskObjectParent.Status = 'Completed';
}
// when task is created from log a call
System.debug('title > '+ title + 'followup > '+ followup + 'tsk5 > '+ tsk5);
if(title != null && title =='Referral Meeting' && followup !=null && followup == '1' && tsk5 != null && tsk5 == 'Referral Meeting'){
taskObjectParent.Status = 'Completed';
taskObjectParent.Type = title;
}
return null;
}
//return null;
}catch(Exception e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.FATAL,e.getMessage()));
return null;
}
}
public String searchText{get;set;}
public PageReference filterContacts(){
for(MultiSelect option : avaiableContactlList){
if(String.isBlank(searchText)){
option.isDisplay = '';
continue;
}
if(!option.Name.contains(searchText)){
option.isDisplay = 'none';
}
}
return null;
}
// for all activity objectives except 'Physician to physician visit' contact is not required.
public PageReference performSave(){
System.debug('############');
try{
string retId=ApexPages.currentPage().getParameters().get('retURL');
system.debug('retId------------>' + retId);
system.debug('recordId------------>' + recordId);
if(string.isBlank(retId)==null || retId==null){
retId=recordId;
}
system.debug('retId111------------>' + retId);
if(string.isBlank(retId)){
if(string.isNotblank(whatId)){
retId=whatId;
}
if(string.isNotblank(whoId)){
retId=whoId;
}
}
system.debug('retId222------------>' + retId);
//String retId = ApexPages.currentPage().getParameters().get('retURL');
boolean isContactSelected = false;
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
isContactSelected = true;
break;
}
}
List<Task> tasksToBeSaved = new List<Task>();
if(recordId == null){
if((taskObjectParent.Type == 'Physician-to-Physician Visit' || taskObjectParent.Type == 'Unsuccessful Physician-to-Physician Visit' || taskObjectParent.Type == 'Sports Medicine Phone Call' || taskObjectParent.Type =='Sports Medicine Visit') && isContactSelected == true){
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
Task taskObject = createTask(taskObjectParent,conObj.Value);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
}
}else{
Task taskObject = createTask(taskObjectParent,null);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
system.debug(' >>>>> === '+tasksToBeSaved);
upsert tasksToBeSaved;
system.debug(' >>>>> ------'+tasksToBeSaved);
system.debug('retId44------------>' + retId);
System.debug(' Current Url -- '+ApexPages.currentPage().getHeaders().get('Origin'));
System.debug(' > >> > >> > '+Apexpages.currentPage().getUrl());
//PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('retURL'));
//PageReference pg = new PageReference('/'+retId);
System.debug(' >> > > > 299 = = = '+retId);
PageReference pg = new PageReference(retId);
pg.setRedirect(true);
return pg;
// return null;
}else{
if(((taskObjectParent.Type == 'Physician-to-Physician Visit' && inputValue != 'Physician-to-Physician Visit' ) || (taskObjectParent.Type == 'Sports Medicine Visit' && inputValue != 'Sports Medicine Visit') || (taskObjectParent.Type == 'Sports Medicine Phone Call' && inputValue != 'Sports Medicine Phone Call') ) && isContactSelected == true){
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
Task taskObject = createTask(taskObjectParent,conObj.Value);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
}
}else{
taskObjectParent.Subject = taskObjectParent.Type;
taskObjectParent.Topics_Discussed__c = '';
taskObjectParent.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObjectParent.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObjectParent.Goal_of_Activity__c += sltVal.Name + ';';
}
}
upsert taskObjectParent;
}
System.debug('=:tasksToBeSaved:=' +tasksToBeSaved);
if(!tasksToBeSaved.isEmpty()){
upsert tasksToBeSaved;
}
//PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('retURL'));
//PageReference pg = new PageReference('/'+retId);
PageReference pg = new PageReference(retId);
System.debug(' >> > > > 342 = = = '+retId);
pg.setRedirect(true);
return pg;
// return null;
}
}catch(Exception e){
System.debug(e);
return null;
}
//return null;
}
private Task createTask(Task taskObjectParent1,String contactIdStr){
Task taskObject = new Task();
if((taskObjectParent.Type == 'Physician-to-Physician Visit' && inputValue != 'Physician-to-Physician Visit') || (taskObjectParent.Type == 'Sports Medicine Visit' && inputValue != 'Sports Medicine Visit') || (taskObjectParent.Type == 'Sports Medicine Phone Call' && inputValue != 'Sports Medicine Phone Call')){
}else{
taskObject.Id = taskObjectParent1.Id;
}
taskObject.Type = taskObjectParent1.Type;
//taskObject.Subject = taskObjectParent1.Type;
taskObject.whatId = taskObjectParent1.whatId;
taskObject.whoId = contactIdStr;
taskObject.OwnerId = taskObjectParent1.OwnerId;
taskObject.Description = taskObjectParent1.Description;
taskObject.ActivityDate = taskObjectParent1.ActivityDate;
taskObject.Status = taskObjectParent1.Status;
taskObject.Priority = taskObjectParent1.Priority;
taskObject.Goal_of_Activity__c = taskObjectParent1.Goal_of_Activity__c;
taskObject.Topics_Discussed__c = taskObjectParent1.Topics_Discussed__c;
taskObject.Visit_Duration__c = taskObjectParent1.Visit_Duration__c;
taskObject.Activity_Cost__c = taskObjectParent1.Activity_Cost__c;
return taskObject;
}
//Wrapper class
public class MultiSelect{
public boolean isChecked{get;set;}
public String Name{get;set;}
public Id Value{get;set;}
public String isDisplay{get;set;}
public MultiSelect(boolean isChecked, String Name, Id Value){
this.isChecked = isChecked;
this.Name = Name;
this.Value = Value;
this.isDisplay = '';
}
}
}```