3

A little background, for some reason my sandbox orgs are adding an "A" or "D" to role developer names when queried or when added to changesets. SF is investigating why this is happening.

Regardless, one of the current workarounds is to change developer name to something and then back to the previous role name and that seems to stick and prevents the "A" or "D" being added when queried or added to a changeset.

Rather than manually open up each role and change the name, I thought of updating the roles via Apex.

I am receiving an insufficient access on cross-reference Id, but I cannot understand why. The error is a result of the update.

Any ideas or is this another bug with the org?

Group[] roles = [select id, DeveloperName from group where type='Role'];

for (integer i = 0; i< roles.size(); i++) {
    system.debug('BEFORE:' + roles[i].DeveloperName);
    roles[i].DeveloperName = roles[i].DeveloperName.removeEnd('A');
    roles[i].DeveloperName = roles[i].DeveloperName.removeEnd('D');
    system.debug('AFTER:' + roles[i].DeveloperName);
}

update roles;

Solution as recommended by SFDCFox (Verified):

UserRole[] roles = [select id, DeveloperName from UserRole];

for (integer i = 0; i< roles.size(); i++) {
    system.debug('BEFORE:' + roles[i].DeveloperName);
    roles[i].DeveloperName = roles[i].DeveloperName.removeEnd('A');
    roles[i].DeveloperName = roles[i].DeveloperName.removeEnd('D');
    system.debug('AFTER:' + roles[i].DeveloperName);
}

update roles;
1

The DeveloperName for a Group of type 'Role' is read-only, and derived from the UserRole DeveloperName. To update it, query the UserRole table and modify the DeveloperName from there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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