• Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce Consultants
      • Marketing Cloud Consultants
      • Service Cloud Consultants
      • Experience Cloud Consultants
      • Analytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud Consultants
      • Financial Service Cloud Consultants
      • Health Cloud Consultants
      • Commerce Cloud Consultants
      • Manufacturing Cloud Consultants
  • Jobs
  • Marketplace
  • Stories
  • Top Bloggers 2022
  • Advertise With Us
  • Quizzes
  • Discussions
  • Groups
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce Consultants
        • Marketing Cloud Consultants
        • Service Cloud Consultants
        • Experience Cloud Consultants
        • Analytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud Consultants
        • Financial Service Cloud Consultants
        • Health Cloud Consultants
        • Commerce Cloud Consultants
        • Manufacturing Cloud Consultants
    • Jobs
    • Marketplace
    • Stories
    • Top Bloggers 2022
    • Advertise With Us
    • Quizzes
    • Discussions
    • Groups

    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 3 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

    Reply

    Subscribe

    airslate

    SALESFORCE PRODUCT EXPERTISE

    • Top Salesforce Consultants
    • Top Salesforce Experience Cloud Consultants
    • Top Salesforce Analytics Cloud Consultants
    • Top Salesforce Service Cloud Consultants
    • Top Salesforce Marketing Cloud Consultants

    SALESFORCE INDUSTRY EXPERTISE

    • Top Salesforce Consultants
    • Top Salesforce Manufacturing Cloud Consultants
    • Top Salesforce Non-Profit Cloud Consultants
    • Top Salesforce Health Cloud Consultants
    • Top Salesforce Financial Service Cloud Consultants
    • Top Salesforce Commerce Cloud Consultants

    Popular Salesforce Blogs

    Multi Factor Authentication

    MFA (Multi-Factor Authentication) in Salesforce

    Blog in Salesforce Security

    Introduction MFA is a special security feature provided by Salesforce that provides an extra layer of protection against suspicious or unauthorised logins. After enabling the…

    API Login Users, AppExchange App, Authenticator App, connected app, Custom Domain
    Arun Nov 1, 2021
    4,524  Views
    Visualforce Page

    Upload Data Through CSV File in Visualforce Page | Salesforce Developer Guide

    Blog in Others, Salesforce Apex, Salesforce Tutorial

    You might have a requirement where you need to upload a csv file in your custom object. In this blog, we’ll see how to upload…

    Apex Class, Command Button, Create Validation, CSV File, custom object
    krati vishnoi Dec 18, 2020
    6,962  Views

    6 Salesforce Administration Mistakes You Must Avoid

    Blog in Salesforce Admin

    It takes a variety of roles, experiences, and skill sets to manage Salesforce. From tech architects, developers, and admins to consultants, companies need diverse resources from…

    Admin, Admin Errors, Admins to Consultants, Automate Process, Business
    Alok Jun 17, 2022
    1,283  Views

    Popular Salesforce Videos

    Introduction To Salesforce Apex | DataType | Collection | Conditional Statements

    Introduction To Salesforce Apex | DataType | Collection | Conditional Statements

    Video in Salesforce Apex

    In this video salesforce apex hours creators provides an introduction to Apex. Apex enables developers to access the Salesforce platform, back-end database and client-server interfaces…

    salesforce, salesforce platform, Apex, Salesforce Developers, Salesforce Video
    Mayra Aug 11, 2022
    825  Views
    Governor Limits in Salesforce | Video Tutorial

    Governor Limits in Salesforce | Video Tutorial

    Video in Salesforce Apex, Salesforce Training

    Watch this amazing video to learn all about Governor Limits in Salesforce and a description of Governor Limits in Salesforce. If you have any doubts…

    Salesforce Training, Salesforce Tutorial, Salesforce Apex, Salesforce Developer, salesforce
    CRS Info Solutions Oct 28, 2021
    1,751  Views
    What is Salesforce? | Why is it So Good ? | High Demand Skills

    What is Salesforce? | Why is it So Good ? | High Demand Skills

    Video in Salesforce Stories

    In this video, Technical Suneja explains what Salesforce is and why it is such a valuable skill set to have. He goes into detail about…

    Salesforce Training, Salesforce Tutorial, Salesforce Functions, Salesforce Learning, Accounts in Salesforce
    Rahul kapoor Sep 15, 2022
    428  Views
    Footer Forcetalks logo

    [email protected]

    Forcetalks Android App
    Forcetalks IOS App

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2022

    Top Salesforce® Bloggers 2021

    Tips to choose Best Salesforce® Consulting Company

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    Submissions

    Write a Blog

    Start a New Discussion

    Post a Video

    Post an Infographic

    © 2023 - 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®.

    Forum Description

    Report

    There was a problem reporting this post.

    Harassment or bullying behavior
    Harassment or bullying behavior
    Contains mature or sensitive content
    Contains misleading or false information
    Mobile App Reported Contents
    Contains abusive or derogatory content
    Contains spam, fake content or potential malware

    Block Member?

    Please confirm you want to block this member.

    You will no longer be able to:

    • See blocked member's posts
    • Mention this member in posts
    • Invite this member to groups
    • Message this member
    • Add this member as a connection

    Please note: This action will also remove this member from your connections and send a report to the site admin. Please allow a few minutes for this process to complete.

    Report

    You have already reported this .
    Clear Clear All
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.