Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • 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
  • Marketplace
  • Advertise With Us
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • 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
    • Marketplace
    • Advertise With Us
    • 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, 1 month 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

    application solution

    Popular Salesforce Blogs

    Financial Service Trends

    4 Financial Service Trends for Businesses and FSIs | Salesforce Financial Services Cloud

    Blog in Salesforce, Salesforce Cloud Platform

    Digital adoption has increased in the past few years, especially across banking, insurance, and wealth management segments. It has shown a steady growth despite the…

    Banking, Business Leaders, Business Strategy, CRM, Customer Data
    Carol Aug 18, 2022
    2,472  Views

    How Developers instruments are Helping Salesforce lightning Web parts

    Blog in Lightning

    Salesforce Recently announced the latest programming sample for Lightning component Development known as lightning web components. Lightning components Development starts latest tooling terms and conditions…

    Lightning Components, Lightning Experience, Salesforce Certifications, Salesforce CLI, Salesforce Components
    Akhila Apr 19, 2019
    2,818  Views

    No Code Salesforce and Xero Integration

    Blog in Salesforce

    For expanding organizations, Xero is an intuitive cloud-based accounting solution. Invoices, paychecks, Financial consensus, Purchasing, Expenses, Bookkeeping, and more are now all manageable by businesses…

    Authentication Provider, Automation, Bank Feeds, Bank Relationships, Bookkeeping
    Apphienz May 15, 2023
    1,056  Views

    Popular Salesforce Videos

    Salesforce India Engineer Salary Revealed | Salary Break Up | Company Review

    Salesforce India Engineer Salary Revealed | Salary Break Up | Company Review

    Video in Salesforce Stories

    In this video, Soumyajit Bhattacharyay has given a detailed review of Salesforce. Talked about the tech stack that they work in. Talked about their offices…

    salesforce, Salesforce Developers, Salesforce Video, Salesforce Learning, Salesforce Job
    Nauman Apr 30, 2021
    2,497  Views
    GS DevOps Mate: Your Free Flexible Toolkit for Faster and Smoother Salesforce Deployments

    GS DevOps Mate: Your Free Flexible Toolkit for Faster and Smoother Salesforce Deployments

    Video in Salesforce DX

    Are you considering automated Salesforce deployments based on repos? Or are you struggling with setting up CI/CD utilizing SFDX on the CI/CD platform of your…

    Salesforce Developers, DevOps, Javascript, Google, Webinar
    Groundswell Cloud Nov 23, 2020
    3,818  Views
    5 Facts You Didn't Know About Salesforce

    5 Facts You Didn't Know About Salesforce

    Video in Salesforce Stories

    In this video, we have tried to share some amazing facts about Salesforce, the world leader in CRM, that you didn't know about so that…

    Salesforce Integration, Salesforce Implementation, salesforce, salesforce knowledge, CRM
    Algoworks Sep 7, 2020
    2,014  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®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.