In some cases we need to change the owner of an invoice:
List<c2g__codaInvoice__c> linv = [SELECT id, OwnerId, c2g__OwnerCompany__c FROM c2g__codaInvoice__c WHERE id = 'a0z6F000008h3xfQAA'];
if (linv.size() > 0) {
c2g__codaInvoice__c iv = linv[0];
iv.OwnerId = '00G90000000zhIZ';
iv.c2g__OwnerCompany__c = 'a0V90000000KW2uEAG';
update iv;
}
If above code is executed in dev console, I get error message "FIELD_CUSTOM_VALIDATION_EXCEPTION, The company or owner cannot be changed".
Is there a way to change owner and company of an existing invoice?