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.

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.

share|improve this question
1  
You can create the profile first in sandbox and then map that profile with the packaged profile during installation. –  doga Dec 6 '12 at 6:54
    
your answer can solve my problem but my question is when i need to use the app in any ORG i need to create first profile in that ORG? or is there any way to create custom profile in test method. –  Axaykumar Varu Dec 6 '12 at 7:00
    
I think salesforce doesn't allow creation of profiles during installation. We can think of this as suppose target org is already having a profile with same name as your profile and if your profile overrides that profile then it might lead some of components not working properly. –  doga Dec 6 '12 at 8:12
    
Is your profile included in the package ? Is anything preventing you from using a standard profile ? –  Samuel De Rycke Dec 6 '12 at 8:32
1  
Your test should not be running during install these days unless your at an older API level or using the IsTest(OnInstall=true) annotation. If your happy for this to be a regression test in your packaging org and not something that is needed to be retested in the subscriber org. You can either upgrade to the lastest API for your test (since the default is not to run on install these days) or remove the annotation if your using it. –  Andrew Fawcett Dec 7 '12 at 9:21
show 1 more comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
add comment

Have you tried this: @isTest (SeeAllData = true) Here some info

share|improve this answer
1  
yes, but this can not solve the problem because custom profile could not found at the time of installation. –  Axaykumar Varu Dec 6 '12 at 7:23
add comment

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.