You need to sign in to do that
Don't have an account?
Mimica
Issue with Maps that uses String keys with accentuation?
Hi,
After the go live of Spring 12 a lot of tests code failed in our Org and the error was always the same: to create an user, we
used the profile name 'Usuário Padrão' that failed to be retrieved from a Map.
I developed a small test class (testMap) that shows the error, testMethod01, and another that shows a workaround, testMethod02.
Could anyone confirm that it's a bug or if I'm doing something wrong?
Thanks in advance!
@isTest public class testMap { @isTest public static void myTestMethod1() { Map<String,ID> profNameId= new Map<String,ID>(); for (Profile prof : [select Id, Name from Profile where Name in ('Usuário padrão','Administrador Funcional')]) { profNameId.put(prof.Name , prof.Id); } System.assert(profNameId.size() == 2, 'The map should have 2 elements'); System.assert(profNameId.get('Administrador Funcional') <> null, 'The map for Administrador Funcional should not be null'); System.assert(profNameId.get('Usuário padrão') <> null, 'The map for Usuário padrão should not be null'); } @isTest public static void myTestMethod2() { Map<String,ID> profNameId= new Map<String,ID>(); for (Profile prof : [select Id, Name from Profile where Name in ('Usuário padrão','Administrador Funcional')]) { if (prof.Name == 'Usuário padrão') { profNameId.put('Usuario padrao', prof.Id); } else { profNameId.put(prof.Name , prof.Id); } } System.assert(profNameId.size() == 2, 'The map should have 2 elements'); System.assert(profNameId.get('Administrador Funcional') <> null, 'The map for Administrador Funcional should not be null'); System.assert(profNameId.get('Usuario padrao') <> null, 'The map for Usuário padrão should not be null'); } }
Hi Ramakrishna,
Thank you for your response, but I would like after querying the Profile object, create some test users, like this one below.
Note that I used profNameId.get('Usuario padrao') to retrieve from the Map the Id for that Profile name given his name.
If I understood correctly your suggestion I will not be able to retrive the Profile Id.
Best Regards,
Mimica