You need to sign in to do that
Don't have an account?
3421
System.DmlException: Insert failed. First exception on row 0; first error: PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT, portal user already exists for contact: []
I am trying to insert portal user records and receiving this error
System.DmlException: Insert failed. First exception on row 0; first error: PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT, portal user already exists for contact: []
Here is the code
The Controller code is below
Can someone help in this scenario
System.DmlException: Insert failed. First exception on row 0; first error: PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT, portal user already exists for contact: []
Here is the code
@IsTest static void testRegFormWithNewUserAddress11() { Contact con = new Contact(); con.Firstname = 'test'; con.LastName ='test'; con.OtherPhone = '8765432167'; con.Organization_Type__c = 'test'; con.Email ='Sitetestg466@hotmail.com'; insert con; Order__c ordr = new Order__c(); ordr.Contact__c = con.Id; ordr.Account__c = a.Id; insert ordr; Order_Line__c ordrline = new Order_Line__c(); ordrline.Order__c = ordr.id; insert ordrline; ControllerTest controller = new ControllerTest(); controller.con = con; controller.acc = a; controller.Password= 'testpass123'; controller.checkIfContactExists(); controller.checkIfAccountExists(); controller.setTab(); Profile p = [select Name, id From Profile where UserLicense.Name like '%Customer Community%' limit 1]; User u = new User (); u.FirstName = 'test'; u.LastName ='test'; u.Email ='testemail'+Math.round(Math.random()*Math.pow(10, 7))+'@testemail.com'; u.Username = 'testemail'+Math.round(Math.random()*Math.pow(10, 8))+'@testemai.com'; u.Alias ='test'; u.CommunityNickname ='tst'; u.ContactId =con.Id; u.LanguageLocaleKey = 'en_US'; u.LocaleSidKey ='en_CA'; u.TimeZoneSidKey ='America/Chicago'; u.ProfileId = p.Id; u.EmailEncodingKey = 'UTF-8'; insert u; }
The Controller code is below
List<User> existalready = [select id,Contact.FirstName,Username,Contact.LastName from user where username =:Email and IsActive = true LIMIT 1]; if(existalready.size()<0){ for(User u: existalready){ insert u ; insert con;
Can someone help in this scenario
I can't really tell if lines 4 & 5 of the controller are in the for-loop or not.
The if-condition will never be true though, as the size of a list can never be less than zero.
If you post a more complete example, someone might be able to help.
It is greater than 0. Sorry I copied incorrectly. I did remove the condition entirely, but still the issue is continuing. Not sure if I am missing something
I did try that code too, but I still have the same error