I developed my code in my DE and created custom profile name = "XYZ" and i used that profile in my apex class and Test methods but i am having problem while installing that managed beta package in my sandbox this is due to test method failure, because that profile is not visible in test method while installing, so what should i do for that problem? can we create custom profile in test method to ensure success? i don't have detailed idea about test method as i am new to these things.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
No you cannot create profiles in apex code, either through tests or otherwise, this is presumably a security limitation.
The second part of your problem is something I have also encountered. You cannot include a profile in a Managed Package. You can include 'Profile Settings' which can be applied to a subscribers existing profiles. But the name of the subscribers profile will not always match the name of the profile you are referencing in your unit test.
What I have done to eliminate this problem in the past is rather than referencing a profile in code, I use the Schema Describe information to determine the object or field level permissions that implicitly grant the user access. For example if a user has write permission on my Milestone Object, my code lets them perform a priviledged action on the Milestone