Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question
1  
Execute Anonymous doesn't run code 'anonymously', it runs as the currently connected user, which is you, with all of your Profile & Permission Set granted privileges. –  Mark Pond May 15 at 17:12

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer
    
Yes, the record type wasn't set active for the profiles. Couldn't figure it out until started some URL hacking. Created a second record type. Thanks. –  dzh May 15 at 17:19

Is it possible that you have an inactive record type named "office"?

The bug you listed was related to person accounts which does not apply to your issue given the object type.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.