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
Ishan Singh 4Ishan Singh 4 

How can I access a custom field on Lead object from Task object in Apex class

There is a custom field name - RR id on lead object.
I want to access that RR id field in my apex class from Task object 
AnudeepAnudeep (Salesforce Developers) 
Hi Ishan, 

The Who Id field on Task looks upto Contact or Lead. Can you try something like this?
List<Task> tskList = new List<Task>(); 
List<Lead> ldList = new List<Lead>();
tskList = [Select Who.Id from Task] 
ldList = [Select RRid__c from Lead where Id IN:tskList]

User-added image

If you find the information I shared useful, please mark this as solved by selecting this answer as best. It may help others in the community. Thank You!

Anudeep
Ishan Singh 4Ishan Singh 4
@Anudeep
I have created new task.
Now I want that if RRid field(on lead object) value = 1 then task owner = XYZ

Thank you! 
Israel SchmidtIsrael Schmidt
Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man,Keep it up. tellpizzahut (https://www.tellpizzahut.online/)