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 › How to create a Community User with a Trigger in Salesforce?

    Tagged: Account, Approval, Community User, Record Type, Salesforce Trigger

    • Salesforce® Discussions

      How to create a Community User with a Trigger in Salesforce?

      Posted by Prachi on December 3, 2019 at 4:32 PM

      When a new Account is created with recordType as 'Corporate', then create Account's Contact as Community User and Submit the record for the Approval.

      Piyush replied 6 years, 10 months ago 2 Members · 1 Reply
      • Account
      • Approval
      • Community User
      • Record Type
      • Salesforce Trigger
    • 1 Reply
    • Piyush

      Member
      December 4, 2019 at 5:14 AM

      Hi,

      Have a look to the below code:-

      trigger UserFromContact on Contact (after insert) {
      set<ID> conids = new set<ID>();
          for(Contact c : trigger.new){
              if(c.accountid != Null && c.recordtype ='Customer_Contact'){
                  conids.add(c.id);           
          }  
      }
      List<contact> conlist = [select id,email,firstName,lastname,accountId from Contact where Id IN : conids];
      List<user> usr = new List<user>();
          for(Contact con : conlist){
           string nick = con.email!=null?con.email.substring(0, con.email.indexOf('@')):''; nick += Datetime.now().getTime();       
          User newUser = new User(
                          alias = ('con.firstName'),
                          email = con.email,
                          emailencodingkey = 'UTF-8',
                          firstname = con.firstName,
                          lastname = con.lastname,
                          languagelocalekey = 'en_US',
                          localesidkey = 'en_US',
                          contactId = con.Id,
                          timezonesidkey = 'America/Los_Angeles',
                          username = con.email,
                          CommunityNickname = nick,
                          ProfileId = '00e1a000000V5BU',
                          IsActive = true);
                          usr.add(newUser);        
          }    
           Insert usr;
      }

      Check the following url for more:-

      https://developer.salesforce.com/forums/?id=906F00000005HPlIAM

    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

    Salesforce Analytics: Uncovering Actionable Insights for Strategic Decision-Making

    Blog in AppExchange

    Data has become essential to modern organizations in the digital age because it provides unmatched insights into consumer behavior, market trends, and operational efficiency. However,…

    Audience Segmentation, Business Innovation, business-analytics, Campaign Performance, Competitive Edge
    Ritika Apr 15, 2024
    1,055  Views

    How to Install Service Setup in the Salesforce Service Cloud

    Blog in Others

    When I started to implement Salesforce einstein Bots for the first time, I found difficult to understand the flow behind it and various channels involved.…

    Lightning Experience, Salesforce Cloud, Salesforce Einstein, Salesforce Implementation, Salesforce Lightning
    Sakthi Saranya Jan 23, 2020
    5,427  Views
    Process Builder in Salesforce

    Getting Started with Process Builder in Salesforce

    Blog in Others, Salesforce

    Process Builder Process Builder is the advanced version of workflow. Process builder is used to automate complex business processes in real-time. Process builder is user-friendly…

    Automate Complex Business Processes, Code, Condition Process, Create Records, Email Alert Actions
    Manish May 5, 2021
    3,556  Views

    Popular Salesforce Videos

    Learning Path and Pay Scale for Salesforce Profiles

    Learning Path and Pay Scale for Salesforce Profiles

    Video in Salesforce Training

    Now it's high time to know about the Learning Path for the different Salesforce profiles. In this video, you also got to know about the…

    Salesforce Training, Salesforce Tutorial, Salesforce Jobs, Salesforce Ecosystem, Salesforce Video
    S2 Jan 24, 2022
    2,321  Views
    8 Steps to Launch Your App on Salesforce AppExchange

    8 Steps to Launch Your App on Salesforce AppExchange

    Video in AppExchange, Salesforce Apps

    AppExchange is the largest business app store in the world, with over 4,000 apps and millions of users. In this video, we will guide you…

    salesforce, Salesforce Apps, Salesforce App Development, Salesforce Video, Salesforce AppExchange
    ENWAY Nov 6, 2023
    4,266  Views
    Manage Packages & Post Installation Script | Salesforce Managed Packages

    Manage Packages & Post Installation Script | Salesforce Managed Packages

    Video in Salesforce Training

    This video will give you a brief overview of Managed Packages and Unmanaged Packages in Salesforce. You will get a quick glance at how to…

    Salesforce Training, Salesforce Tutorial, Salesforce Packages, Salesforce Managed Packages, Salesforce Video
    Algoworks Sep 20, 2021
    1,959  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.