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 Answer
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;