Toggle Side Panel

  • Blogs
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Blogs
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › Is there any way to can create the profile in the salesforce in apex test class. How?

    Tagged: Profile, Salesforce Apex, Test Class, User Profile

    • Salesforce® Discussions

      Is there any way to can create the profile in the salesforce in apex test class. How?

      Posted by Mohit on July 26, 2016 at 4:38 PM

      Hi all,

      Is there any way to can create the profile in the salesforce in apex test class. How?

      Please give suggestions.

      PRANAV replied 8 years, 9 months ago 3 Members · 2 Replies
      • Profile
      • Salesforce Apex
      • Test Class
      • User Profile
    • 2 Replies
    • Sourabh

      Member
      July 27, 2016 at 2:06 PM

      Hi Mohit,

      You cannot create profiles in apex code, either through tests or otherwise, this is presumably a security limitation.

      Thanks

    • [adinserter block='9']
    • PRANAV

      Member
      January 19, 2018 at 11:26 AM

      Hi Mohit,

      You can create an user but you need to query the required profile according to the requirement..! As you cannot create a profile.

      Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
      User usr = new User(LastName = 'Bhardwaj',
      FirstName='Pranav',
      Alias = 'pbhar',
      Email = 'Pranav.Bhardwaj@asdf.com',
      Username = 'Pranav.Bhardwaj@asdf.com',
      ProfileId = profileId.id,
      TimeZoneSidKey = 'GMT',
      LanguageLocaleKey = 'en_US',
      EmailEncodingKey = 'UTF-8',
      LocaleSidKey = 'en_US'
      );

      You can use the above code snippet for your test class. This may helps you to cover your apex class.

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    Popular Salesforce Blogs

    SOQL in Salesforce

    All You Need to Know About SOQL in Salesforce

    Blog in Salesforce Apex

    SOQL SOQL stands for Salesforce Object Query Language. Similar to SQL, but SOQL is designed especially for Salesforce data. The structure and keywords of SOQL…

    Developer Console, Logical Operators, Multi-Select Picklists, Multiple Conditional Operators, Query
    Anshu Dec 2, 2021
    4,643  Views
    Visualforce Page

    How to Add Your Visualforce Page in your Application as a Tab | Salesforce Guide

    Blog in Visualforce

    Introduction Sometimes our requirement is to access our VF page as a tab in our application. So we gonna learn here how to use our…

    Application, Apps, Code, Controller, Create Visualforce Page
    Rajat Shende Mar 2, 2022
    5,676  Views
    Sales Process In Salesforce

    Sales Process In Salesforce - Explained

    Blog in Salesforce

    Stage 1: Contact To Your Leads  78% of business purchasers in the UK look for salesmen who go about as confided in guides. Before you…

    Business, Business Bargains, Business Purchasers, Business Venture, Client Relationship
    Anjali Sep 10, 2020
    12,156  Views

    Popular Salesforce Videos

    Salesforce DX simplified with AutoRABIT - Bay Area Salesforce Developer Group

    Salesforce DX simplified with AutoRABIT - Bay Area Salesforce Developer Group

    Video in Salesforce Implementation, Salesforce DX

    A common need that teams developing on the Salesforce platform express is the desire for a single solution that will take their developers through the…

    Salesforce Release Management, Salesforce Continuous Integration, Salesforce Git Integration, Salesforce Svn Integration, Salesforce Test Automation
    Pooja Jan 17, 2018
    2,261  Views
    Video in
    Forcetalks Jun 26, 2024
    582  Views
    Salesforce and Disney Studios Join Forces

    Salesforce and Disney Studios Join Forces

    Video in Salesforce Stories

    Salesforce and Disney Studios Content recently announced a five-year innovation partnership to help support Disney filmmakers and marketers using the Salesforce platform. By naming Salesforce…

    salesforce, salesforce platform, Salesforce Video, Salesforce Learning, Technology
    Algoworks Jul 6, 2021
    1,886  Views
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.