• Rajar Kumar
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hi Guys,

I am getting this error while inserting user in the test class.
System.DmlException: Insert failed. role type must match user type.

Please find the below code.

 Set<String> customerUserTypes = new Set<String> {'CSPLiteUser', 'PowerPartner', 'PowerCustomerSuccess',   'CustomerSuccess'};
        Profile portalProfile = [SELECT Id FROM Profile WHERE UserType in :customerUserTypes Limit 1];
        UserRole role = [Select Id From UserRole Where PortalType = :'CustomerPortal' Limit 1];
        User user1 = new User(
            Username = System.now().millisecond() + 'test12345@test.com',
            ContactId = contact1.Id,
            ProfileId = portalProfile.Id,
            UserRoleId = role.Id,
            Alias = 'test56',
            Email = 'test12345@test.com',
            EmailEncodingKey = 'UTF-8',
            LastName = 'McTesty',
            CommunityNickname = 'test12345',
            TimeZoneSidKey = 'America/Los_Angeles',
            LocaleSidKey = 'en_US',
            LanguageLocaleKey = 'en_US'
        );
    Database.insert(user1);


 
Hi Guys,

I have two list opps(opprtunity list) and ocList(OpportunityContactRole ) . I want to update one string field on opportunity(records in opps) with the value of contact name of contact role(records in.ocList)  for example opps[0].test__c = ocList [0].Contact.Name
How can I achieve for all the records?
Please help
Thanks
List<Opportunity> opps = new List<Opportunity>();
        for (integer i=0; i<50; i++)
		{
            Opportunity opp = new Opportunity();
            opp.AccountId=acc.Id;
            opp.Name='My Opportunity'+i;
            opp.StageName='Prospecting';
            opp.CloseDate=date.today().adddays(i);
            opp.Open_Tasks__c = 0;
            //opp.LastActivityDate = System.today()+15;
            opps.add(opp);
        }
  insert opps
List<OpportunityContactRole> ocList = new List<OpportunityContactRole>();
for(integer i=0; i<opps.size(); i++){
      OpportunityContactRole ocr = new OpportunityContactRole();
      ocr.ContactId = con.Id;
      ocr.OpportunityId = oppList[i].Id;
      ocr.IsPrimary = TRUE;
      ocr.Role = 'Decision Maker';
      ocList.add(ocr);
      } 
insert ocList;