Slaesforce FAQ

how to create portal user in test class in salesforce

by Jarrell Braun Published 2 years ago Updated 2 years ago
image

Hi Pranav,Use the below code to assign portal user in test class. ID ProfileID = [ Select id from Profile where name = 'Customer Portal Manager Custom'].id; Account acc = new Account (Name = 'Test Account');

Full Answer

How to extend privileges of a portal user in Salesforce?

First we need to understand which profile is assigned to the portal user. When we enabled customer portal for any salesforce org, some standard profiles are already there like ‘Authenticated Website’, ‘High Volume Customer Portal’ etc. and you can clone that profile to extend the privileges.

How to add role in the newly created portal user?

But If you need to add Role in the newly created portal user then query the UserRole and assigned that role to the user.But there is a problem when we do that. It gives an error “DML operation on setup object is not permitted after you have updated a non-setup object and vice versa original object – Account ,User”.

What is the difference between user and account in Salesforce?

Salesforce categorizes objects into so called setup and non-setup objects. User is a setup object while Account is a non-setup object. Salesforce restricts DML operations so that both kinds of objects can't be manipulated in the same context.

How to assign role to customer portal user in apex?

To assign role to customer portal user in apex we need to query the UserRole where PortalType equals to ‘CustomerPortal’ . But If you need to add Role in the newly created portal user then query the UserRole and assigned that role to the user.But there is a problem when we do that.

image

How do I create a community portal user in Test class?

How to create Community User in Test Class?roleId – The Id of the Role if Applicable otherwise pass blank string.profileId – The Id of the Profile and it is Mandatory to pass.firstName – FirstName of the User.lastName – LastName of the User.

How do I create a partner in Test class Salesforce?

I think the preconditions to create a partner community user in a test class are:Having an account enabled as partner. How to enable an account as partner via apex?Having a contact attached to said account.Having a partner community profile. Necessary, because we use a custom partner community Profile.

How do I enable a portal user in Salesforce?

How to Enable Customer PortalFrom Setup, enter Customer Portal Settings in the Quick Find box, then select Customer Portal Settings.Click Edit.Select Enable Customer Portal.Click Save.Continue setting up the portal.View of Customer Portal after Enable.Click Edit.More items...•

How do I add a portal user to Apex Salesforce?

portal account owner must have a role : Account for which user is being created, It's owner does not have any role assigned. Assign some role to account owner....Steps for Portal User Creation for Personal Account:Create User Role.Create Personal Account with above role.Create Portal User with PersonContactId.

How do I query a customer portal in Salesforce?

Query against multiple contacts List lContacts = [SELECT Id FROM Contact]; List lUsers = [SELECT Id,Contact.Id,Name,Email FROM User WHERE Profile.Name = 'Customer Portal User' AND ContactId IN :lCont]; NOTE: The first query on Contact will have to be limited so Apex Governor limits are not exceeded.

How do I create a community user in Salesforce?

Create Community User ProfileFrom Setup, in the Quick Find box, enter Profiles , then select Profiles.On the Profiles page, click Clone next to the Customer Community Login User, the Customer Community Plus Login User, the Customer Community Plus User, or the Customer Community User profile.More items...

What is a Salesforce portal user?

Customer Portal in Salesforce provides online support for the customers to resolve their inquiries by providing best user interface to customer. The Customer Portal allows you to deliver a personalised, service application to your most important customers.

How do I activate Partner portal?

Enable Partner Accounts and Create Partner UsersFrom the App Launcher, select Accounts.Select the All Accounts list view.Click Edge Communications.Click the dropdown menu to see all the quick actions available for the page.Click Enable as Partner.In the confirmation dialog, select Enable As Partner.

How do I enable partner portal in Salesforce?

Create Partner AccountsCreate a business account.Click Manage External Account, and then click Enable as Partner. ... In the confirmation dialog, select Yes, I want to enable this account as a Partner Account.Click Confirm.

Can we create user using apex?

we can create user through apex. here is the code. User u = new user(); u. LastName = 'Test Code'; u.

What is database DMLOptions?

You can specify DML options for insert and update operations by setting the desired options in the Database. DMLOptions object. You can set Database. DMLOptions for the operation by calling the setOptions method on the sObject, or by passing it as a parameter to the Database.

How do I add a tab to a community in Salesforce?

Add Tabs to Your CommunityOpen Community Workspaces orCommunity Management.Click Administration | Tabs. ... Select the tabs to include in your community from the Available Tabs list. ... To add a tab, click Add. ... To change the order that the tabs display, click Up orDown. ... Click Save.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9