I have an Apex Test where I have problems with my Permissions. But even with the right Permission Sets I can't insert Quotes.
Here's my code :
Profile p = [SELECT Id FROM Profile WHERE Name='Custom User'];
User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', ProfileId = p.Id, UserName='[email protected]');
insert u;
System.runAs(u) {
PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Label = 'Salesforce CPQ User' LIMIT 1];
insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id);
SBQQ__Quote__c principalQuote = new SBQQ__Quote__c();
principalQuote.RecordTypeId = quoteRecordTypeIdsByDeveloperName.get('MyRecordType');
principalQuote.SBQQ__Opportunity2__c = opportunity.Id;
insert principalQuote;
}
But it says that I don't have the right permission to insert principalQuote. I found a bypass but I don't understand why. If I do :
SBQQ__Quote__c principalQuote = new SBQQ__Quote__c();
principalQuote.RecordTypeId = quoteRecordTypeIdsByDeveloperName.get('MyRecordType');
insert principalQuote;
principalQuote.SBQQ__Opportunity2__c = opportunity.Id;
update principalQuote;
It works. So basically I'm not able to insert my data with fields. I have to update it afterward. Is it something common in Apex behaviour and Permission Sets ?