function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mariappangomathirajmariappangomathiraj 

Contact creation in Site.createPortalUser

How to avoid the new contact creation in Site.createPortalUser(u, accountId, null);Because I have the contact.I don't need to create a new one.I am updating the existing contact to the creating portal user.Is it possible?

 

My code:

 

contactId= ApexPages.currentPage().getParameters().get('conatctid');

 

Contact c = [Select c.Update_Information__c, c.Top_Investor__c, c.Top_Account__c,
c.Title, c.Temporary_Email__c, c.Tags__c, c.SystemModstamp, c.Starred__c, c.Seller__c, c.Salutation, c.Residential_Subcategory__c,
c.ReportsToId, c.Regional_Interest_s__c, c.Phone, c.OwnerId, c.Other_Geographic_Preference__c, c.OtherStreet
From Contact c
WHERE id = :contactId];

 

private User createUsers(){
User u = new User();
u.FirstName = firstName;
u.LastName = lastName ;
u.companyName = CompanyName;
u.Email = email;
u.Username = email;
if (email.length() > 40)
u.CommunityNickname = email.substring(0,39);
else
u.CommunityNickname = email;
u.FederationIdentifier = email;
u.ShareFile_Password__c = sfPassword;
u.ContactId = contact.Id;
return u;
}

 

Account acc = new Account(Name = CompanyName);
acc.ownerId = ownerId;
insert acc;
system.debug('::::acc:::::::::::::'+acc);
accountId = acc.id;

 

String userId = Site.createPortalUser(u, accountId, null);

 

But this code generate the new contact for newly created portal user.How to avoid the new contact create?How to assign the existing contact to this newly created portal user?

Ryan-GuestRyan-Guest

I don't think you can.

 

One thing you could do is copy over all of the old contact info after the new contact is created and then delete the old contact.

Force2b_MikeForce2b_Mike

I've found that as long as the Email address on your new Portal User matches the eMail address on the existing Contact record, Salesforce.com will link the new Portal User to the existing Contact record - though must still be attached to the same Account.

 

Your sample code queries an existing Contact, but creates a new Account to pass to createPortalUser. That will definitely create a new Contact. You have to use the same Account that the Contact is already attached to in order for it to use your existing Contact.

 

 

Best Regards,

 

Mike