I have a class to create an User but I'm getting these errors trying to deploy:
=== Deploy Errors PROJECT PATH ERRORS
────────────────────────────────────────────────────────────────── ───────────────────────────────────────────────────── force-app\main\default\classes\OneSFA_SalesStructureHandler_ws.cls Field is not writeable: User.AccountId (446:49)
force-app\main\default\classes\OneSFA_SalesStructureHandler_ws.cls Field is not writeable: User.IsPortalEnabled (446:49)10:57:47.675 ended SFDX: Deploy Source to Org
This is the code:
private without sharing class AsyncCreateUser implements Queueable {
private String accId;
private String usrRep;
private List<Contact> lstContact;
private List<Sales_Structure__c> lstSSUp;
private asyncCreateUser(String accId, String usrRep, List<Contact> lstContact, List<Sales_Structure__c> lstSSUp){
this.accId = accId;
this.usrRep = usrRep;
this.lstContact = lstContact;
this.lstSSUp = lstSSUp;
System.debug('Create Contact - accId ' + this.accId);
System.debug('Create Contact - usrRep ' + this.usrRep);
System.debug('Create Contact - lstSSUp ' + this.lstSSUp);
}
public void execute(QueueableContext context){
if (!Schema.sObjectType.Contact.isUpdateable()) {
return;
}
//List<Contact> lstContact = new List<Contact>();
List<User> lstUser = new List<User>();
Profile p = [SELECT Id FROM Profile WHERE Name = 'Customer Community Plus Login User'];
for(Sales_Structure__c ss : lstSSUp){
for(Contact cct : lstContact){
User userXP = new User(
AccountId = accId,
ContactId = cct.Id,
IsPortalEnabled = true,
FirstName = cct.FirstName,
LastName = cct.LastName,
Alias = cct.LastName+ss.SalesRep__c,
SAP_Number_of_SalesRep__c = ss.SalesRep__c,
Division_Allocation__c = cct.Department__c,
Email = cct.Email,
UserName = cct.Email+ss.SalesRep__c+'.store',
ProfileId = p.Id,
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US',
LocalesIdKey = 'en_US',
TimezonesIdKey = 'America/Los_Angeles'
);
insert userXP;
}
}
}
}
How can I handle this error?