You need to sign in to do that
Don't have an account?
Robert Lange 6
I have been trying to write an Apex trigger that adds the following Contact to ALL Account records.
The trigger should relate the Contact to the Account record. I have tried the following code. I am getting an error message on the line, "WhatID = acc.ID;"
trigger CreateContact on Account (after insert) {
for (Account acc : Trigger.new){
Contact c = new Contact();
c.FirstName = 'Jo Jo';
c.LastName = 'Murphy';
WhatID = acc.ID;
insert c;
}
}
trigger CreateContact on Account (after insert) {
for (Account acc : Trigger.new){
Contact c = new Contact();
c.FirstName = 'Jo Jo';
c.LastName = 'Murphy';
WhatID = acc.ID;
insert c;
}
}
You need to place c.AccountId=acc.ID in place of whatId. I belive you are trying to relate the contact for any new Account inserted.
Hope this helps! Please mark as best if it does
Thanks
All Answers
You need to place c.AccountId=acc.ID in place of whatId. I belive you are trying to relate the contact for any new Account inserted.
Hope this helps! Please mark as best if it does
Thanks
Thanks