[SalesForce] Updating Record Types using Execute anonymous throws INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, invalid record type: []

Looked to do something smart and immediately ran into problems. I thought I will trim the page layouts by using record types. For that I need to run a batch (or data loader), but problem I get an error mentioned in title.

Now I am not exactly sure how Execute Anonymous works but the name implies that it indeed could be related to permissions. Although I found there was a bug previously, but it is now marked as fixed.

Here's my code:

list <Line_del__c> linesToUpdate = [select id from Line_del__c where Team_s_Dept_s_del__r.name='BOPS'];
RecordType rtype = [Select id From RecordType Where SobjectType = 'Line_del__c' and name='office' limit 1]; 

for (Line_del__c lines: linesToUpdate){
    lines.recordtypeid=rtype.id;

}
try{
update linesToUpdate;
} catch (DmlException ex){
            system.debug(ex);
        } 

As a side note – can I disable record types? Users now cannot edit their items from a list view. If I would update the record types I could enter them as a criteria into list view filter.

Thanks

Best Answer

1) Check if the recordtype is active

2) See if the profile of the user editing the record has access to the recordtype

Go to Setup --> Administration Setup --> Profiles ( Search for the users profile ) and search for Custom Record Type Settings on the page and check if the "Office" record type is available for the users profile

Related Topic