Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8149369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:50:14+00:00 2026-06-06T14:50:14+00:00

I am writing a task’s trigger and getting an error in salesforce Illegal polymorphic

  • 0

I am writing a task’s trigger and getting an error in salesforce Illegal polymorphic assignment from polymorphic domain [SOBJECT:User, SOBJECT:Calendar]

trigger Status_Change on Task (after update) {

    List<Task>updated_tasks=trigger.new;
    List<Task> tt=trigger.old;
    Task_History__c history=new Task_History__c();
    Integer i=0;
    for(i=0;i<updated_tasks.size();i++)
    {
    history.Name=tt.get(i).Subject;
    history=new Task_History__c();
    history.OldValue__c=tt.get(i).Status;
    history.NewValue__c=updated_tasks.get(i).Status;
    history.User__c=updated_tasks.get(i).Owner;
    insert history;


    }
}

error is on line
history.User__c=updated_tasks.get(i).Owner;

When I write history.User__c=updated_tasks.get(i).owner.id then there is no error
but when I tried to get a User’s email address from this id then its showing no user corresponding to this id. How do I get Owner’s user id from Task SObject’s owner field. I think error is due to Owner is a lookup to [SObject.User,SObject.Calender].so owner’s id should be different from User’id .but how to get only User’s id from Owner’s field in Task object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:50:15+00:00Added an answer on June 6, 2026 at 2:50 pm

    You are so close. The syntax is:

    history.User__c=updated_tasks.get(i).OwnerId;
    

    You were correct. the task.Owner field is an SObject, task.Owner.Id is valid, but the value being referenced is not populated in the trigger context.

    Your trigger is not very well written, it has a dml statement in a loop, and there doesn’t appear to be a lookup from the task history to the task, I have referenced one in the updated example below.

    trigger Status_Change on Task (after update) {
        List<Task_History__c> histories = new List<Task_History__c>();
        Task oldValue;
        for(Task task : Trigger.new) {
            oldValue = Trigger.oldMap.get(task.Id);
            histories.add(new Task_History__c(
                Name=task.Subject,
                OldValue__c=oldValue.Status,
                NewValue__c=task.Status,
                User__c=task.OwnerId,
                //This should be created as well
                Task__c=task.Id
            ));
        }
        if(histories.size() > 0) {
            insert histories;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I am trying to achieve is writing a task which will list all
I'm writing a custom Ant task that needs to accept a custom nested type.
I have been given the task of re-writing some libraries written in C# so
Writing a python program, and I came up with this error while using the
I am writing a deferred task which is intended to construct a file in
I am writing a simple task planner and reminder using Qt which will play
I am writing a scheduled task which I would like to run frequently. The
Trying to do the simple task of writing to the registry to make a
I have been given the painful task of writing a C# application to sync
I'm writing a Custom SSIS task that, as one of it's functions, should execute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.