When we are creating one person account it is allocating one accountid and one Contactid. When i am trying to assign that person account with task i need whoId. How can i get that contact Id(Related to Person account) which is generated at the time of person account creation.

  • 1
    you can use PersonContactId field like Select PersonContactId From Account Jun 19, 2018 at 11:06

1 Answer 1

Account person = new Account();
person.FirstName = 'John';
person.LastName = 'Doe';
person.RecordTypeId = personRTid;
//other fields...
insert person; 

person = [SELECT Id, PersonContactId FROM Account where Id =: person.Id];
//Contact personContact = [SELECT Id FROM Contact where AccountId =: person.Id];

Task myTask = new Task();
myTask.WhoId = account.PersonContactId;
//myTask.WhoId = personContact.Id;
//other fields...
insert myTask;

Not the answer you're looking for? Browse other questions tagged .