+ Start a Discussion
Surya.236Surya.236 

Hi, I am Getting this following error while running the Test class.

System.DmlException: Insert failed. First exception on row 0; first error: LIMIT_EXCEEDED, limit exceeded: [].
While Inserting the user im Getting this error.
karthikeyan perumalkarthikeyan perumal
Hello, 

It would be extremely difficult to answer this without looking at the code. Its most likely some part of your code is doing stuff which is taking up a lot of time to complete..  kinldy  share your test class please. 

Thanks
karthik
Raj VakatiRaj Vakati
Can you share the test class ?
karthikeyan perumalkarthikeyan perumal
Hello, 

Which line you are getting error?  coz its may DML operation in thi test class.  

NOTE: make sure all your DML statement excutes only one whe you run test class. this may help you to resolve this error.

Thanks
karthik
 
Surya.236Surya.236
At the Line System.runAs(usr) in both methods im getting error. So i think that this error was Limt of user creation in org with that profile "HBT RR....". So now i Queried the user and and used that Queried user in Sysytem.runAs(). Following is  the Query.
            *User usr = [select id,name from user where Profile.name='HBT RR Partner Community Login User' AND IsActive = true AND Contactid!=null limit 1];
Now I am Getting this error System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: 0030U00000UChDC: []
This Error was at Line Insert cs.

I think this error was that User has no access to Case. How to resolve this? IS my Approach right instead of inserting User im Queried?
 
karthikeyan perumalkarthikeyan perumal
Hello, 

you approach is right. but need to assign static profile id insted of dunamic. so that you make sure  the test user will have all rights to perform the operation. 
 
User usr = new User(Alias = 'standt', Email='standarduser@testorg.com', 
                                    EmailEncodingKey='UTF-8', LastName='Testingusername', LanguageLocaleKey='en_US', 
                                    LocaleSidKey='en_US', ProfileId = profileList[0].Id, 
                                    TimeZoneSidKey='America/Los_Angeles', UserName='TestingusernameASN@testorg.com',
                                    contactId=cc.id);

ProfileId = profileList[0].Id,

try to assign sysadmin static profile id. 

Thanks
karthik

 
Surya.236Surya.236
we need to check with Portal user. we will get error if we use system admin.
 
karthikeyan perumalkarthikeyan perumal
in this case  have you assigned UserRoleId  for that user roleID will have the record level access..

something like below.

UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1];
UserRoleId = portalRole.Id;
 
Thanks
karthik
 
Surya.236Surya.236
Karthik, In my Sandbox System Overview Portal Roles are completed does this is the effect in running test class?Portal Roles
karthikeyan perumalkarthikeyan perumal
just gohead.. as you know, test records and Testdata not comes under governer limits. 
Surya.236Surya.236
I asssigned Profile id static and userRoleid then i am getting this error System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: Product2: []

Following is the changed code :
assgned static profileId and added userroleid.
 -------------------------------------------------------------------------------------------------------------------------------------------------------------
 List<Profile> profileList = [select id,name from profile where name='System Administrator'];  
     //List<Profile> profileList = [SELECT Id FROM Profile WHERE Name='HBT RR Partner Community Login User']; //HBT RR Partner Community Login User, Partner Community Login
        if(!profileList.isEmpty()){
                
                account a = new account(name='testacc',recordtypeid=EESAcctRecordTypeId );//End user
                insert a;
                contact c = new contact(lastname='test',Contact_Role__c='End user',Contact_Status__c='Inactive',accountid=a.id,Partner_Account__c=a.id,recordtypeid=EESContactRecordTypeId,email='testtesttesttesttest@honeywell.com' );
                insert c;
                 
            UserRole portalRole = [Select Id From UserRole Where PortalType = 'Partner' Limit 1];
                User usr = new User(Alias = 'standt', Email='standarduser@testorg.com', UserRoleId = portalRole.Id,
                                    EmailEncodingKey='UTF-8', LastName='Testingusername', LanguageLocaleKey='en_US', 
                                    LocaleSidKey='en_US', ProfileId = '00e36000001WjFyAAK', 
                                    TimeZoneSidKey='America/Los_Angeles', UserName='TestingusernameASN@testorg.com',
                                    contactId=c.id);
            //User usr = [select id,name from user where Profile.name='HBT RR Partner Community Login User' AND IsActive = true AND Contactid!=null AND UserRoleId = '00E0U000000NBhqUAG' limit 1];
            // User usr = [select id,name from user where Profile.id='00e36000001WjFyAAK' AND IsActive = true  limit 1];
              
            
           System.runAs(usr) {  
               list<string> ss = new list<string>();
               case cs = new case();
               cs.recordtypeid = ASNTechCaseRecordTypeId;
               cs.contactid=c.id;
               cs.accountid=a.id;
               insert cs;
               ss.add(cs.id);
              .
              .
              Remaining code as Above.
               ..

 
karthikeyan perumalkarthikeyan perumal

insted of using System.runAs(usr)   replace  Test.startTest();   and     "Test.stopTest();" like below, 

              Test.startTest(); 

               list<string> ss = new list<string>();
               case cs = new case();
               cs.recordtypeid = ASNTechCaseRecordTypeId;
               cs.contactid=c.id;
               cs.accountid=a.id;
               insert cs;
               ss.add(cs.id);
                .
                .
                       
              Test.stopTest();

Thanks
karthik