Im trying to set the RecordTypeId of a contact to a certain value if the contact was created by a specific user. Im getting the error:
A value cannot be stored to RecordTypeId in type Contact.
How can i set the RecordType without getting an error?
public void OnBeforeInsert(Contact[] newContacts){
ID id=[SELECT Id FROM User WHERE Name='Niki Müller'].ID;
ID B2C=[Select RecordTypeId FROM Contact WHERE Name='Aamer Ayoob' limit 1].ID;
for(Contact newContact : newContacts){
if(newContact.createdById==id){
contact.RecordTypeId=B2C;
contact.AccountId=contact.Email;
}
}
}
ID B2C=[Select RecordTypeId FROM Contact WHERE Name='Aamer Ayoob' limit 1].ID;
should be changed toID B2C=[Select RecordTypeId FROM Contact WHERE Name='Aamer Ayoob' limit 1].RecordTypeId;