We have a custom object, and the Contact object is linked to it. Using a trigger on this custom object, I want a User record to be created using Contact data. Below is my code, and I am getting this error:
Apex trigger creatingportaluser caused an unexpected exception, contact your administrator: creatingportaluser: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Username, Last Name, Email, Nickname]: [Username, Last Name, Email, Nickname]: Trigger.creatingportaluser: line 18, column 1
trigger creatingportaluser on Assignment__c (after insert) {
for(assignment__c objcustom : trigger.new){
if( objcustom.submit__c == true){
User u = new User();
u.ContactId=objcustom.resource__r.Id;
u.username=objcustom.resource__r.Email;
u.firstname=objcustom.resource__r.FirstName;
u.lastname=objcustom.resource__r.LastName;
u.email=objcustom.resource__r.Email;
u.TimeZoneSidKey='America/Los_Angeles';
u.LocaleSidKey = 'en_US';
u.EmailEncodingKey='UTF-8';
u.LanguageLocaleKey = 'en_US';
u.alias = 'thething';
u.profileid = '00e28000001ZSJH';
insert u;
}
}
}
objcustom.resource__r.Email