You need to sign in to do that
Don't have an account?

Error: Illegal assignment from Schema.SObjectField to Id
Hello,
I have the following error message:
Here is the method implementation:
When I try to add
Please advise how to update the User__c lookup field without the error message?
I have the following error message:
Error: Illegal assignment from Schema.SObjectField to Idwhen I try to update lookup field in apex.
Here is the method implementation:
public void addTaskCommentHistory(Task task) { if(task == Null) { return; } String newValue = task.Description; if(newValue != Null && !newValue.equals('')) { String taskId = task.Id; String fieldName = 'Comments'; String oldValue = ''; Task_History__c taskHistory = new Task_History__c(); taskHistory.Task_ID__c = taskId; taskHistory.Field_Name__c = fieldName; taskHistory.Old_Value__c = oldValue; taskHistory.New_Value__c = newValue; String lastModifiedBy = task.LastModifiedById; String userName = ''; // the query will return no more than one row because the data is extracted by user id List<User> listOfUsers = [SELECT Name FROM User where Id = :lastModifiedBy]; if(listOfUsers.size() > 0){ User user = listOfUsers.get(0); userName = user.Name; } taskHistory.User__c = user.Name; insert taskHistory; } }
When I try to add
user.Nameto
taskHistory.User__cin
taskHistory.User__c = user.Name;I get the "Error: Illegal assignment from Schema.SObjectField to Id" message.
Please advise how to update the User__c lookup field without the error message?
Lokesh...
All Answers
Lokesh...
Please check the updated code below :
Hope this helps you!
Thanks
Varaprasad
For Support: varaprasad4sfdc@gmail.com