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
VaderVader 

Validation Error: Contact/Lead ID: id value of incorrect type:

I have a VF page that uses the standard salesforce Task object  and is almost identical to the standard create task page from SFDC.  

 

When creating a task from an account, it populates the name of the account in the Related To field without any issues.  Same for Product, Contact, Case, etc.

 

The wierd issue is that when creating a Task from an Opportunity, I get the following error:  

Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Contact/Lead ID: id value of incorrect type: (record id here) "

 

I am not referencing any whoid or whatid fields, I am using the standard Task Controller with the standard task Save method and have no validation rules on the Activity or Opportunity objects that would even come close to generating this messag? 

 

Anyone know why I am getting this ONLY when trying to create a task from an opportunity record?

 

VisualForce

<apex:page standardController="Task" extensions="taskCreate">
		   
	<apex:sectionHeader title="{!$ObjectType.Task.label} Edit" subtitle="New {!$ObjectType.Task.name}"/>
	
	<apex:form >
	
		<apex:pageBlock title="{!$ObjectType.Task.label} Edit" mode="edit">
	        <apex:pageBlockButtons >
	                <apex:commandButton action="{!save}" value="Save"/>
	                <apex:commandButton action="{!saveAndAddInformed}" value="Save and Add Informed Users"/>
	                <apex:commandButton action="{!cancel}" value="Cancel"/>
	        </apex:pageBlockButtons>
	        <apex:pageBlockSection showHeader="true" title="Task Information" columns="2">
	                <apex:inputField required="true" value="{!Task.OwnerId}"/>
	                <apex:inputField value="{!Task.WhatId}"/>
	                <apex:inputField required="true" value="{!Task.Subject}"/>
	                <apex:inputField value="{!Task.WhoId}"/>
	                <apex:inputField value="{!Task.ActivityDate}"/>
	                <apex:pageBlockSectionItem />
	        </apex:pageBlockSection>
	        <apex:pageBlockSection showHeader="false" columns="1">
	                <apex:inputField style="width: 400px; height: 150px" value="{!Task.Description}" />
	        </apex:pageBlockSection>
	        <apex:pageBlockSection showHeader="true" title="Additional Information" columns="2">
	                <apex:inputField required="true" value="{!Task.Status}"/>
	                <apex:inputField required="true" value="{!Task.Priority}"/>
	        </apex:pageBlockSection>
	        
	        <apex:pageBlockSection showHeader="true" title="Notifications" columns="2">
	        	<apex:pageBlockSectionItem >
	        		<apex:inputCheckbox value="{!Task.Assignee_Notification__c}" id="assigneeNotification"/>
	        		<apex:outputLabel value="Send Notification Email (To Assignee)" />
	        	</apex:pageBlockSectionItem>
	        	
	        	<apex:pageBlockSectionItem >		        	
	        	</apex:pageBlockSectionItem>
	        	
	        	<apex:pageBlockSectionItem >
	        		<apex:inputCheckbox value="{!Task.Delegator_Notification__c}" id="delegatorNotification"/>
	        		<apex:outputLabel value="Receive Update Notifications" />
	        	</apex:pageBlockSectionItem>
	        	
	        </apex:pageBlockSection> 
		</apex:pageBlock>
		
		
	</apex:form>
</apex:page>

 

 

Apex for custom controller:

 

public class taskCreate {
	public Id tskId {get;set;}	
	private ApexPages.StandardController controller;	
	
	//*************************************************************
	//Constructor
	//*************************************************************
	public taskCreate(ApexPages.StandardController stdController) {
      // Save the standard controller so that we can use its methods later
      controller = stdController;
   }	
	
	//*************************************************************
	//Save the task and redirect to the informed users entry page
	//*************************************************************
	public PageReference saveAndAddInformed() {		
		PageReference taskPage;
			try {
				taskPage = controller.save();
				tskId = controller.getRecord().Id;
			} 
				catch (Exception ex) {
				// If there are caught exceptions, add them to the current page
				ApexPages.addMessages(ex);
			}
		
		//*************************************************************
		// If our task was successfully saved, there will be a non-null 
		// PageReference
		//*************************************************************		
		
		If (taskPage != null) {
			String longTaskId = String.valueOf(tskId);
			String shortTaskId = longTaskId.left(15);
			
			//PageReference tskInformed = new pagereference('/apex/informedUsers?tId='+tskId);
			PageReference tskInformed = new pagereference('/apex/informedUsers?tId='+shortTaskId);
			tskInformed.setRedirect(true);
  			return tskInformed;
  			
		}				
		else 			
		{
			return taskPage;
		} 

	}
	
	public static Task testTsk;

    static testMethod void taskCreateUnitTest() {    	
    	Test.startTest();
        testTsk = new Task(Subject='testTask'); 
        insert testTsk;        
        //Id tskId = task.Id;       

        PageReference pg = Page.informedUsers;
        Test.setCurrentPage(pg);          
              
        ApexPages.StandardController con = new ApexPages.StandardController(testTsk);
        taskCreate tCreate = new taskCreate(con); 
        
        tCreate.SaveAndAddInformed();
        Test.stopTest();        
    }
	
}