function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amit SAmit S 

Task URL Not working

Hi All, 

I am trying populate the URL with Values for What ID and Who ID. but it is not populating on the custom VF Page. 

below is the URL I have constructed.
https://c.cs6.visual.force.com/apex/HCPTasksVFPage?accid=001N000000XZuVZIA1&ent=Task&ownerid=005N00000023EKyIAM&RecordType=012N00000000b70&retURL=%2F001N000000XZuVZIA1&whatId=001N000000XZuVZIA1&whoId=001N000000XZuVZIA1

This page load but does not populate the Account(Related To) and Name on the New Task Page.

If anyone has come across such an issue, please let me know the solution for this. Do I need to populate any other fields for the Related To & Name on the screen?
pconpcon
Are you using a controller with your custom VF page?  Can you please provide the current Visualforce page and the controller (if there is one)?

NOTE: When adding code, please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.
Amit SAmit S
Yes, I am using the VF page and a Custom Controller. Here is the controller
public class taskLTAEditExtension {

    public PageReference page{get; set;}
    public Task t {get;set;}    
    public HCP_Task__c tLTA {get;set;}        
    public TaskRecordTypeRef rc {get; set;}    
    public Boolean recordLocked{get; set;}
    public Boolean okToDelete{get; set;}    
    public Boolean isHCPRecordType{get; set;}
    public Boolean isStandardRecordType{get; set;}        
	public String HTaskId;
    public string RecordType2Set;    
    public string AccountId2Set;
    public string AccountId3Set;
    public String rType {get; set;}
    public User_Profiles__c user_profile_Recruiter = User_Profiles__c.getValues('Recruiter');
    public User_Profiles__c user_profile_HCP = User_Profiles__c.getValues('National HCP');    
    public User_Profiles__c user_profile_LID_Center = User_Profiles__c.getValues('LID Center');
    public User_Profiles__c user_profile_Executive = User_Profiles__c.getValues('Executive');     
    public User_Profiles__c user_profile_Sys_Admin = User_Profiles__c.getValues('System Administrator');
    public User_Profiles__c user_profile_Contract_Approver = User_Profiles__c.getValues('Contract Approver');
    
    public TaskRecordType__c StandardRecType = TaskRecordType__c.getValues('Standard');
    public TaskRecordType__c HCPRecType = TaskRecordType__c.getValues('HCP_Task');
    
    public HCPAccessRecruiters__c HCPRecruiter1 = HCPAccessRecruiters__c.getValues('Recruiter Exception1');
    public HCPAccessRecruiters__c HCPRecruiter2 = HCPAccessRecruiters__c.getValues('Recruiter Exception2');
    public HCPAccessRecruiters__c HCPRecruiter3 = HCPAccessRecruiters__c.getValues('ContractApprover1');
    public HCPAccessRecruiters__c HCPRecruiter4 = HCPAccessRecruiters__c.getValues('ContractApprover2');

    
    public taskLTAEditExtension(ApexPages.StandardController c) {
        t = (Task) c.getRecord();     	
        checkRecordType();        
        tLTA = new HCP_Task__c();
        rType = ApexPages.currentPage().getParameters().get('RecordType');        
        //AccountId3Set = ApexPages.currentPage().getParameters().get(t.WhatId);   
        //AccountId2Set = String.valueOf(t.WhatId).substring(0, 15);        
        
        system.debug('Account to be added after reset' + AccountId2Set);
        if(t.Id == null){
            //system.debug('Inside 1st taskLTAEditExtension IF Loop ');            
            t.OwnerId = UserInfo.getUserId();            
            system.debug('Account to be added AccountId2Set + AccountId3Set inside IF ' + AccountId2Set + AccountId3Set);
            //t.WhatId = ApexPages.currentPage().getParameters().get('accid');                        
        }
        else{
            t = [SELECT Subject, OwnerID, Status, CreatedDate, LastModifiedDate, Type, ActivityDate, WhoId, WhatId, Priority, RecordTypeId, Category__c, Category_Item__c, Description, Task_Activity_Type__c, IsReminderSet, ReminderDateTime, CreatedById, LastModifiedById
                 FROM Task WHERE Id = :t.Id];
            //system.debug('HCPRecType value ' + HCPRecType);            
            system.debug('User Id ' + UserInfo.getUserId() );            
            if(	String.valueof(t.RecordTypeId).contains(HCPRecType.RecordTypeId__c) && 
               	(
                UserInfo.getProfileId().contains(user_profile_HCP.Profile_Id__c) || 
                UserInfo.getProfileId().contains(user_profile_LID_Center.Profile_Id__c) || 
                UserInfo.getProfileId().contains(user_profile_Executive.Profile_Id__c) ||
                UserInfo.getProfileId().contains(user_profile_Sys_Admin.Profile_Id__c) ||                    
                  (
                      UserInfo.getProfileId().contains(user_profile_Recruiter.Profile_Id__c)  &&                      
                      (
                          UserInfo.getUserId().contains(HCPRecruiter1.UserId__c) ||
                       	  UserInfo.getUserId().contains(HCPRecruiter2.UserId__c)                       
                       )
                  ) ||
                  (
                      UserInfo.getProfileId().contains(user_profile_Contract_Approver.Profile_Id__c)  &&                      
                      (
                          UserInfo.getUserId().contains(HCPRecruiter3.UserId__c) ||
                       	  UserInfo.getUserId().contains(HCPRecruiter4.UserId__c)                       
                       )
                  )
                )
              )
            {            	
                tLTA = [SELECT Id, Parent_Task_Id__c, HCP_Task_Comments__c from HCP_Task__c where Parent_Task_Id__c = :t.Id];                
            }
        }
    }    
     /* Check record type when loading the page */
    public PageReference checkRecordType(){        
        rc = new TaskRecordTypeRef();
        if(t.RecordTypeId == rc.getHCPTaskRecordTypeId()){
            isHCPRecordType = true;  
            isStandardRecordType = false; system.debug('checkRecordType 1 ' + isHCPRecordType + isStandardRecordType);
        }
        else if(t.RecordTypeId == rc.getStandardTaskRecordTypeId()){
            isStandardRecordType = true;
            isHCPRecordType = false; system.debug('checkRecordType 2 ' + isHCPRecordType + isStandardRecordType);
        }
        return null;                
    }    
    /* Redirect to new edit page */
    public PageReference redirect(){        
        if(
            (
             UserInfo.getProfileId().contains(user_profile_HCP.Profile_Id__c) || 
             UserInfo.getProfileId().contains(user_profile_LID_Center.Profile_Id__c) || 
             UserInfo.getProfileId().contains(user_profile_Executive.Profile_Id__c) ||
             UserInfo.getProfileId().contains(user_profile_Sys_Admin.Profile_Id__c) 
           	)
            && String.valueof(t.RecordTypeId).contains(HCPRecType.RecordTypeId__c)){            
            //page = new PageReference('/apex/HCPTasksVFPage'); // this is working
            page = new PageReference('/apex/HCPTasksVFPage' + '?ownerid=' + UserInfo.getUserId() + '&accid=' + t.whatId + '&whatId=' + t.whatId + '&whoId=' + t.whoId + '&ent=Task' + '&retURL=/' + t.whatId);             
        }
        else{            
        	page = new PageReference('/00T/e' + '?nooverride=1' + '&RecordType=' + RecordType2Set + '&ownerid=' + UserInfo.getUserId() + '&accid=' + t.whatId + '&whatId=' + t.whatId +'&whoId=' + t.whoId + '&ent=Task'); // Account Id is coming as Null at this point        	
        }        
        if(t.Id != null){
            page.getParameters().put('id', t.Id);            
            
        }                
        page.getParameters().put('RecordType', rType);
        
        page.setRedirect(true);        
        return page;
    }
    public List<Schema.FieldSetMember> getTaskViewFields() {        
        if(isStandardRecordType){
            return SObjectType.Task.FieldSets.Task_Standard_Field_Set.getFields();
        }
        if(isHCPRecordType){
            return SObjectType.Task.FieldSets.Task_HCP_Field_Set.getFields();    
        }
        return null;  
    }    
    public List<Schema.FieldSetMember> getTaskHCPCommentsFields() {        
        if(isHCPRecordType){
            return SObjectType.HCP_Task__c.FieldSets.HCPTaskComments.getFields();    
        }
		return null;        
    }
    public List<Schema.FieldSetMember> getTaskCommentsFields() {        
        if(isHCPRecordType){
            return SObjectType.Task.FieldSets.StandardTaskComments.getFields();    
        }
		return null;        
    }
    public List<Schema.FieldSetMember> getTaskAdditonalInfoFields() {        
        if(isHCPRecordType){
            return SObjectType.Task.FieldSets.Task_HCP_Additional_Info.getFields();    
        }
		return null;        
    }
    public List<Schema.FieldSetMember> getSysteminfoFields() {        
        if(isHCPRecordType){
            return SObjectType.Task.FieldSets.HCP_System_Information.getFields();    
        }
		return null;        
    }
    public List<Schema.FieldSetMember> getReminderFields() {        
        if(isHCPRecordType){
            return SObjectType.Task.FieldSets.HCP_Reminder_Field.getFields();    
        }
		return null;        
    }    
    /* Initialize other parameters */
    public void initialise(){
        
    }    
    public PageReference notOverrideCheck(){         
        RecordType2Set = t.RecordTypeId;                
        if(String.valueof(t.RecordTypeId).contains(HCPRecType.RecordTypeId__c))        
        {   system.debug('Inside redirect if 1 ');
            
            return null;
        }
       else{system.debug('Inside redirect else 2 ');
        	page = new PageReference('/' + t.Id + '?nooverride=1');
            page.setRedirect(true);
            return page;}
    }
    /* Re-Render called method */
    public PageReference partialRefresh(){return null;}    
    
    /* Override standard cancel method */
    public PageReference cancel(){
        if(t.Id != null){ page = new PageReference('/' + t.Id); }
        else{            
            page = new PageReference('/home/home.jsp'); // this is working to take to homepage instead need to redirect it to Account's page           
        }        
        page.setRedirect(true);
        return page;
    }
    /* Override standard edit method */
    public PageReference edit(){
        return null;
    }    
    public PageReference saveAction() {
        if(t.Id == null){            
            t.RecordTypeId = rType;//This resolved the issue of Incorrect record type getting populated due to default record type of the Task Object                        
            insert t;            
        }
        else{
            update t;
        }
        if(tLTA.Id == null){
            tLTA.Parent_Task_Id__c = t.Id;
            insert tLTA;
        }
        else{
            update tLTA;
        }        
        PageReference pr = new PageReference('/'+t.Id);
        pr.setRedirect(true);
        return pr;
    }    
}

And here is the Edit Page referenced: 
<apex:page standardController="Task" tabstyle="Task" extensions="taskLTAEditExtension">     
    
    <apex:form >
        <apex:sectionHeader title="Task" subtitle="{!t.Subject}"></apex:sectionHeader>
        <apex:pageBlock title="Task Edit" id="thePageBlock" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Save" action="{!saveAction}" />
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageblockSection title="Task Information">
                
                <apex:inputfield id="task__assignedto" value="{!t.OwnerID}"/>
                <apex:inputfield id="task__relatedto" value="{!t.whatId}">                
                    <apex:param name="ownerId_VF" value="{!t.whatId}" assignTo="{!ownerId_VF}"/>
                </apex:inputfield>
                                                                                     
                <apex:inputfield required="true" id="task__type" value="{!t.type}" />                
                <apex:inputfield id="task__name" value="{!t.WhoId}" />
                <apex:inputfield required="true" id="task__subject" value="{!t.Subject}" />
                <apex:inputfield required="true" id="task__Category" value="{!t.Category__c}" />                
                <apex:inputfield required="false" id="task__activitydate" value="{!t.ActivityDate}" />
                <apex:inputfield required="true" id="task__Category_Item" value="{!t.Category_Item__c}" />                
                
                <apex:inputfield id="task__HCP_Comments1" value="{!tLTA.HCP_Task_Comments__c}" style="width:400px" rendered="true"/>				
                <apex:inputfield id="task__comments1" value="{!t.Description}" style="width:400px" rendered="true"/>
                
            </apex:pageblockSection>
           			
            <apex:pageBlockSection title="Additional Information">
                <apex:inputfield required="true" id="task__Status" value="{!t.Status}"  />
            	<apex:inputfield required="true" id="task__Priority" value="{!t.Priority}"  />
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="System Information" rendered="true">
                <apex:inputfield required="false" id="Task_Activity_Type" value="{!t.Task_Activity_Type__c}" rendered="true" />            	
            </apex:pageBlockSection>
            
           <!--<div style="border: 0px solid rgb(0,191,255); width:100%;height:25px; background:#00bfff;"><p style="margin-left:20px;"><table width="100%"><tr><td  align="left" width="50%"><B>Recurrence </B></td></tr></table></p></div>-->
			<!-- Commenting the below part as it is not working 
				1) on unchecking of the Recurrence Button and 
				2) on selecting Year and other options in Recurrence

            <apex:pageBlockSection id="pbs3" title="Recurrence"  rendered="true">
            <apex:inputfield value="{!t.IsRecurrence}" onclick="CheckDiv()"/> 
            </apex:pageBlockSection>
             
              <div id="Recurrencediv"  style="display:none;">   
                        <apex:pageBlockSection columns="1" id="pbs4" > 
                            <apex:pageBlockSectionItem id="pbsi1" >
                                
                                <table border="0px">
                                        <tr>
                                            <td style="width:120px;">&nbsp;</td>
                                            <td><b>Frequency</b></td>
                                            <td style="width:80px;"></td> 
                                            </tr>  
                                            </table>                                                                                                     
                                            <div>
                                                    <input type="radio" id="Dailydiv" checked="true"  name="checkrctype" value="RecursEveryWeekday"/>Daily<br/>
                                                    <input type="radio" name="checkrctype"  value="Weekly"/>Weekly<br/>
                                                    <input type="radio" name="checkrctype"  value="RecursMonthly"/>Monthly<br/>
                                                    <input type="radio" name="checkrctype"  value="RecursYearly"/>Yearly
                                                </div>
                                           
                                           <div name="Daily" id="Daily">
                                                                            
                                                        <input type="radio" id="RecursEveryWeekday"   name="recurrencetype" value="RecursEveryWeekday"/>Every weekday<br/>
                                                        <input type="radio" id="RecursDaily"   name="recurrencetype" value="RecursDaily"/>Every
                                           </div>
                                                  
                                                </apex:pageBlockSectionItem>
                            <apex:inputField value="{!t.RecurrenceStartDateOnly}" />
                            <apex:inputField value="{!t.RecurrenceEndDateOnly}" />
                                                   </apex:pageBlockSection> 
                                                    </div> 
                            
                                   
            HCP_Reminder_Field
            <apex:pageBlockSection title="Reminder" rendered="true">                
                <apex:inputField value="{!t.IsReminderSet }"/>
                <apex:inputField value="{!t.ReminderDateTime}" onfocus="DatePicker.pickDate(false, 'DueDate', false);" />				
            </apex:pageBlockSection>


				<apex:repeat id="Reason_Comments" value="{!OpportunityStageReasonFields}" var="f" rendered="true">                     
                     <apex:pageBlockSectionItem rendered="{!if(sOpportunity.stagename == 'Closed On Hold','true','false')}">
                         <apex:outputLabel id="fs_Reason_label" value="{!$ObjectType.Opportunity.Fields[f].label}"/>
                         <apex:inputField id="fs_Reason" value="{!sOpportunity[f]}" rendered="{!if(sOpportunity.StageName == 'Closed On Hold','true','false')}"/>    
                     </apex:pageBlockSectionItem>                                                                             
                 </apex:repeat>

			--> 
            <!--
            <apex:pageBlockSection id="Reminder" title="Reminder" >
                 <apex:repeat id="field_set_Reminder" value="{!ReminderFields}" var="f">
                      <apex:pageBlockSectionItem >
                          <apex:outputLabel id="fs_Task_reminder_label" value="{!($ObjectType.Task.Fields[f].label)}"/>
                          <apex:InputField id="fs_Task_reminder" value="{!t[f]}">                              
                          </apex:InputField>                                    
                      </apex:pageBlockSectionItem>
                 </apex:repeat>                                     
            </apex:pageBlockSection>
            -->
            
        </apex:pageBlock>
    </apex:form>
    
<script>
function CheckDiv()
    {    
   document.getElementById("Recurrencediv").style.display='block';
   document.getElementById("Daily").style.display='block';
}  
</script>
</apex:page>

Hope this helps. I am redirecting from New Task button to following page
 
<apex:page standardController="Task" extensions="taskLTAEditExtension" action="{!redirect}">    
</apex:page>

 
Amit SAmit S
Hi PCON,

Please let me know me this code is helpful for you to understand the problem statement

Thanks,
Amit
Amit SAmit S
public taskLTAEditExtension(ApexPages.StandardController c) {
        t = (Task) c.getRecord();     	
        checkRecordType();        
        tLTA = new HCP_Task__c();
        rType = ApexPages.currentPage().getParameters().get('RecordType');                        
        AccountId3Set = t.WhatId;                       
        
        if(t.Id == null){            
            
            t.OwnerId = UserInfo.getUserId();            
            system.debug('Account to be added AccountId2Set + AccountId3Set inside IF ' + AccountId2Set + AccountId3Set);
            
            //t.WhatId = '001N000000ZLZaB';              //Populating Value here works to display the correct Related To, need to ensure the variable has value here of Account id
            
            ApexPages.currentPage().getParameters().put('whatId',AccountId3Set);            
            
        }

I have tried the above options in the controller, but it is not able to fetch the correct values for me to assign
pconpcon
You need to assign the values from the parameter to your task obect.
 
if (t.Id == null) {          
    t.OwnerId = UserInfo.getUserId();            
    t.WhatId = ApexPages.currentPage().getParameters().get('whatId');
    t.WhoId = ApexPage.currentPage().getParameters().get('whoId');
    t.AccountId = ApexPages.currentPage().getParameters().get('accId');
}

NOTE: This code has not been tested and may contain typographical or logical errors
Amit SAmit S
I am getting this error on adding these lines. Somehow the variable is getting null values.

Invalid id: null 
An unexpected error has occurred. Your development organization has been notified.
pconpcon
Line 5 should read
 
t.AccountId = ApexPages.currentPage().getParameters().get('accid');

 
Amit SAmit S
Appreciate you response pcon.

But for t.AccountId I get error, "not allowed".

On other two fields, the value from ApexPages is null.

Please let me know if I am missing something else while initializing the task?
pconpcon
It turns out that you cannot update the AccountId (data below from the MetadataAPI.  Note updateable: false).  As for the other two fields, when you see them being null, what is the current URL set to?
 
{
    "autoNumber": false,
    "byteLength": 18,
    "calculated": false,
    "calculatedFormula": null,
    "cascadeDelete": false,
    "caseSensitive": false,
    "controllerName": null,
    "createable": false,
    "custom": false,
    "defaultValue": null,
    "defaultValueFormula": null,
    "defaultedOnCreate": false,
    "dependentPicklist": false,
    "deprecatedAndHidden": false,
    "digits": 0,
    "displayLocationInDecimal": false,
    "encrypted": false,
    "externalId": false,
    "extraTypeInfo": null,
    "filterable": true,
    "filteredLookupInfo": null,
    "groupable": true,
    "highScaleNumber": false,
    "htmlFormatted": false,
    "idLookup": false,
    "inlineHelpText": null,
    "label": "Account ID",
    "length": 18,
    "mask": null,
    "maskType": null,
    "name": "AccountId",
    "nameField": false,
    "namePointing": false,
    "nillable": true,
    "permissionable": false,
    "picklistValues": [],
    "precision": 0,
    "queryByDistance": false,
    "referenceTargetField": null,
    "referenceTo": [
        "Account"
    ],
    "relationshipName": "Account",
    "relationshipOrder": null,
    "restrictedDelete": false,
    "restrictedPicklist": false,
    "scale": 0,
    "soapType": "tns:ID",
    "sortable": true,
    "type": "reference",
    "unique": false,
    "updateable": false,
    "writeRequiresMasterRead": false
}