+ Start a Discussion
Chris Walters 9Chris Walters 9 

force a new Task to have a specific Account

I can create a new Task but cannot set AccountId as one of the fields - it gets assigned implicity somehow. 
Task task = new Task(
            Description = 'test_02',
            TaskSubType = 'Email',
            Email_Direction__c = 'Outbound',
            WhoId = contact_EC_email.Id,
            OwnerId = user_EC.Id,
//          AccountId = null,       // non-writable fields, where are they getting their values from?
            Actual_End__c = Datetime.valueOf( '2020-05-20 00:00:00')

By what magic can I assign a specific Account object's Id to a Task.AccountId field ?
David Zhu 🔥David Zhu 🔥
You will need to use field WhatId of Task object.