Skip to content
  • Surfmyindia |
  • Lifedreamguide |
  • w3webmart |
  • Overstockphoto |
  • News24globalworld |
  • News24classictimes |
  • Incriediableindia |
  • TechW3web |
  • W3Force ..
w3web.net
the vijay kumar Sign Up to Get Free Code Access β†’ |
  • Home
  • Tutorial
    • Lightning Component
    • Salesforce LWC
    • Salesforce Integration
    • Visualforce
    • Trigger
    • JQuery
  • Our Courses
  • Integration
  • Aura Comp
  • Salesforce LWC
  • Visualforce
  • Trigger
  • JQuery
  • React Js
  • More
    • About Us
    • Contact Us
    • Sitemap
    • Course Pricing
    • Blog
    • Gallery
    • Most Popular Articles
    • Download E-Book
    • YouTube Channel


When an Account record is created then Create a related Opportunity automatically in Salesforce

January 14, 2025February 29, 2024 by Vijay Kumar
551 views

Hey guys, today in this post we are going to learn about the Trigger Scenario:- When an Account record is created then Create a related Opportunity automatically in Salesforce..

 

Final Output β†’

 

Other related post that would you like to learn in Salesforce

πŸ‘‰ Download Free Ebook β†’
πŸ‘‰ Get Free Course β†’

Challenges in your career

🎯 If You Are Facing Any Of These 6 Challenges in your career.

  • Learn Salesforce Development
  • Career Confusion
  • No Interview Call
  • Low Salary
  • No Promotion/Growth
  • No Finding New Job Opportunity
  • Why you stucking from past so many years in same company?

 
  • Apex trigger to create and count the number of child records associated with parent object based on custom field when parent record is created/updated in Salesforce
  • Apex Trigger to Send a Custom Visualforce Component Email Template when Record is Created on Custom Object in Salesforce
  • Trigger to Update the Custom Last Modified Date Field in the Parent Object When the Records in the Child Object is Updated Using Apex Trigger in Salesforce
  • Trigger to update count of child records with custom field of parent object | count of child records on parent for lookup relationship uses of apex trigger in Salesforce
  • Create rollup summary using Apex trigger on custom object | rollup summary trigger for count of child records on custom object in Salesforce example
  • Create Duplicate Rule & Matching Rule to Prevent Insert/Update Duplicate Records on Contact sObject based on Contact Email and Contact Phone in Salesforce
  • Apex trigger on Account to avoid creation of duplicate record if the account with same phone exists in the system in Salesforce
  • Write a trigger on contact to update parent record when child is updated using apex trigger in Salesforce
  • Write a trigger whenever Opportunity is deleted the corresponding Account and Contact should be deleted uses of Apex trigger in Salesforce
  • Write a trigger on Contact to Prevent the user to create duplicate Contact based on Phone if Phone number is already exist on related account in Salesforce
  • Write Validation rule for StageName of opportunity sObject that don’t allow the user to move Previous/Next Stage based on User/Profile (Except specific profile of user) in Salesforce

 

Create Apex Trigger β†’

Step 1:- Create Apex Controller : AccountTrigger.apxt

SFDX:Create Apex Trigger>> New >> AccountTrigger.apxt

AccountTrigger.apxt [Apex Trigger]


  1.   TRIGGER AccountTrigger ON Account (BEFORE INSERT, after INSERT) {
  2.  
  3.     IF(TRIGGER.isBefore){
  4.  
  5.     }ELSE IF(TRIGGER.isAfter && TRIGGER.isInsert){
  6.  
  7.      accountTriggerHandler.relatedOppAcc(TRIGGER.new);
  8.     }
  9.  
  10.  
  11. }

 

Create Trigger Handler Controller β†’

Step 2:- Create Apex Controller : accountTriggerHandler.apxc

SFDX:Create Apex Trigger>> New >> accountTriggerHandler.apxc

accountTriggerHandler.apxc [Trigger Handler]


  1.  public class accountTriggerHandler {
  2.  
  3.     public static void relatedOppAcc(List<Account> accList){
  4.          List<opportunity> oppObjList = NEW List<opportunity>(); 
  5.         FOR(Account acc:accList){           
  6.             Opportunity opp = NEW Opportunity();
  7.             opp.Name=acc.Name;
  8.             opp.StageName='Prospecting';
  9.             opp.CloseDate=system.today();
  10.             opp.AccountId=acc.Id;
  11.             oppObjList.add(opp);
  12.         }
  13.         IF(!oppObjList.isEmpty()){
  14.             INSERT oppObjList;
  15.         }
  16.  
  17.     }
  18.  
  19. }

 

Further post that would you like to learn in Salesforce

  • Trigger on contact to update a account custom field | Write a trigger on contact and update the account custom field uses of apex trigger in Salesforce
  • Create a Apex Trigger on Account to Update the Associated Contact Account Name Null Whenever Account Record is Updated in Salesforce
  • Trigger to check duplicate name to custom object in Salesforce | how to prevent duplicate records based on multiple fields through apex trigger in Salesforce
  • Write a Apex trigger to Add the Contact First Name and Last Name to Associated Account Custom Field Whenever the Contact inserted or Updated in Salesforce
  • Trigger to update parent records field when child record is updated | update parent field from child using apex trigger
  • How to call invocable method (@InvocableMethod) from APEX Controller to convert automatic lead to Account, Contact and Opportunity Uses of Flow Builder/Flow Action in Salesforce
  • Write a trigger to update parent account phone number whenever the contact phone number is updated using trigger handler and helper class in Salesforce
  • Trigger on custom object to prevent delete the related list record based on lookup relation whenever trying to delete parent record, throw an error message using apex class handler trigger in Salesforce
  • Write a trigger on lead to prevent duplicate records based on lead email Whenever the records is inserted Or updated using apex class handler trigger in Salesforce
  • Apex Trigger on Contact to Create Account Automatically and map to related account Id to Contact Whenever New Contact is Created in Salesforce

 

FAQ (Frequently Asked Questions)

How do I create an opportunity in Salesforce using Apex?

Navigate to the Opportunities tab, and click New. Enter the Opportunity Name, Account Name, Close Date, and Stage. Enter additional information as required. Click Save.

How do I trigger an opportunity in Salesforce?

The trigger is defined on the Opportunity object and set to execute after an update. The trigger iterates over the updated Opportunities and checks if their stage has changed to 'Closed Won' from a previous stage that is not 'Closed Won'. For each qualifying Opportunity, a new Order is created.

How do I add a custom field of opportunity?

Create Custom Fields: Navigate to 'Custom Fields' under settings. Click on 'Add Field' or 'Create Field'. Define Your Fields: Choose 'Opportunity' as your object and then define your custom field type, such as single-line text, number, dropdown, etc.

Related Topics | You May Also Like

  • Upon Contact record creation if LeadSource Field is having value as β€˜Web’ or β€˜Phone Inquiry’ then Populate Level as β€˜Primary’ through Apex Trigger in SalesforceUpon Contact record creation if LeadSource Field is having value as β€˜Web’ or β€˜Phone Inquiry’ then Populate Level as β€˜Primary’ through Apex Trigger in Salesforce
  • Write a apex trigger on Account, whenever Active is “Yes”, before save the record we will be check the child object (Opportunity) StageName should not be “Closed Lost”, if any of record of child record get “Closed Lost”, it will be through an error.Write a apex trigger on Account, whenever Active is “Yes”, before save the record we will be check the child object (Opportunity) StageName should not be “Closed Lost”, if any of record of child record get “Closed Lost”, it will be through an error.
  • Write a trigger on contact to update parent record when child is updated using apex trigger in Salesforce | How to write trigger to update account Phone when contact Phone is updated in SalesforceWrite a trigger on contact to update parent record when child is updated using apex trigger in Salesforce | How to write trigger to update account Phone when contact Phone is updated in Salesforce
  • Trigger on contact to update a account custom field | Write a trigger on contact and update the account custom field uses of apex trigger in SalesforceTrigger on contact to update a account custom field | Write a trigger on contact and update the account custom field uses of apex trigger in Salesforce
  • When an Account record is created then Create a related Contact automatically through Apex Trigger in SalesforceWhen an Account record is created then Create a related Contact automatically through Apex Trigger in Salesforce
  • Apex Trigger to update Account phone from Contact Phone based on lookup relationship in Salesforce | Update the related Account Phone if Contact Record is Created in SalesforceApex Trigger to update Account phone from Contact Phone based on lookup relationship in Salesforce | Update the related Account Phone if Contact Record is Created in Salesforce
  • Update Parent field when Child record is Updated or Inserted in Salesforce | Trigger updating parent with child value when a field on the child is changedUpdate Parent field when Child record is Updated or Inserted in Salesforce | Trigger updating parent with child value when a field on the child is changed
  • Do not allow delete Account, if any of related Contact associated with Account in Salesforce |  Prevent the deletion of Account which have related contact through apex trigger in SalesforceDo not allow delete Account, if any of related Contact associated with Account in Salesforce | Prevent the deletion of Account which have related contact through apex trigger in Salesforce
 
  

Our Free Courses β†’

πŸ‘‰ Get Free Course β†’

πŸ“Œ Salesforce Administrators

πŸ“Œ Salesforce Lightning Flow Builder

πŸ“Œ Salesforce Record Trigger Flow Builder

πŸ‘‰ Get Free Course β†’

πŸ“Œ Aura Lightning Framework

πŸ“Œ Lightning Web Component (LWC)

πŸ“Œ Rest APIs Integration



Vijay Kumar

Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Categories Trigger, Tutorial Tags account created then create related opportunity using apex trigger, after insert and after update trigger in salesforce example, after update trigger salesforce example, apex trigger salesforce example, Apex Trigger: Automatically create, bulk apex triggers, create a bulk apex trigger, Create a related opportunity automatically in salesforce apex, Create a related opportunity automatically in salesforce example, Create a related opportunity in salesforce using apex trigger example, Create a trigger to add a related opportunity for each new or updated account if no opportunity is already associated with the account, Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won', salesforce apex trigger, salesforce apex trigger developement, salesforce trigger example
When an Account record is created then Create a related Contact automatically through Apex Trigger in Salesforce
When an Account record is created then assigned the Billing Address fields value to Shipping Address fields value in Salesforce

Archives β†’

Categories β†’

  • Blog (4)
  • More (7)
  • Tutorial (260)
    • Formula Field (1)
    • JQuery (12)
    • Lightning Component (60)
    • React Js (3)
    • Salesforce Integration (8)
    • Salesforce LWC (108)
    • Trigger (43)
    • Validation Rule (9)
    • Visualforce (16)

Global Visitors β†’

Popular Posts β†’

  • convert datetime to date in lwc -- w3web.net How to convert date format Using @track with html tag in lwc | How to format today Date in DD/MM/YYYY in lightning web components | Convert String To Current Date In Salesforce LWC 7.83 views per day
  • save Pdf as a attachement in salesforce -- w3web.net Save the Attachment as PDF using Apex Class and Visualforce Page on click button in Salesforce | How to save instantly my pdf visualforcepage as a file/attachment on click button in Salesforce | Rendering a VF page as PDF and saving it as an attachem... 5.33 views per day
  • disabled input field values in lwc -- w3web.net How to disabled all of input field values dynamically based on button click Uses of foreach loop in javascript in Lightning Web component Salesforce – LWC | How to make lightning-input fields values disabled based on click a button Using dynami... 3.83 views per day
  • use the lightning formatted fields in lwc - w3web.net How to use the lightning-formatted-email, lightning-formatted-number, lightning-formatted-phone, lightning-formatted-date-time, lightning-formatted-text, lightning-formatted-address, lightning-formatted-url in Salesforce lightning web component (LWC)... 3.67 views per day
  • display different types of toast message in lwc -- w3web.net How to display different types of custom toast message as Error, Success, Info and warning toast notifications on click button, uses of ShowToastEvent property in Salesforce Lightning Web Component — LWC | display custom toast notification in... 3.67 views per day
  • upload delete and preview files attachments lightning component -- w3web.net How to get upload/delete and preview the files attachments through apex class uses of lightning:fileCard and lightning:fileUpload elements in Salesforce Lightning component | file Uploader With Preview & Delete in aura component Salesforce 2.83 views per day
  • automatically convert lead to account, contact and opportunity salesforce -- w3web.net How to call invocable method (@InvocableMethod) from APEX Controller to convert automatic lead to Account, Contact and Opportunity Uses of Flow Builder/Flow Action in Salesforce | convert automatic lead to Account, Contact and Opportunity through ape... 2.83 views per day
  • tree grid dynamic expand collapse in lwc -- w3web.net Create dynamic tree grid with expande / collapse selected rows and select checkbox for the entire row select/deselect in Salesforce lightning web component LWC | how to create tree grid with expanded/collapsed section for the entire row marked as se... 2.83 views per day
right side banner -- www.surfmyindia.com
right side banner -- overstockphoto.blogspot.com

Join Our Newsletter β†’

Loading
right side banner -- www.lifedreamguide.com

Recent Posts β†’

  • How Does Work a Functional Component vs Class Component in ReactJS
  • How JSX Works in ReactJS (With Live Example)
  • Introduction to ReactJS – Create Your First React App
right side banner -- www.w3webmart.com


header banner -- www.overstockphoto.blogspot.com
  • Follow Me β†’
➑ : Facebook
➑ : Twitter
➑ : Linkedin
➑ : Instagram
➑ : Reddit
➑ : Forcetalks
➑ : Pinterest
➑ : Github
➑ : Medium
➑ : Tumblr
➑ : Telegram
 
header banner -- www.overstockphoto.blogspot.com

Recent Posts β†’

  • How Does Work a Functional Component vs Class Component in ReactJS
  • How JSX Works in ReactJS (With Live Example)
  • Introduction to ReactJS – Create Your First React App
header banner -- www.lifedreamguide.com

Popular Posts β†’

  • convert datetime to date in lwc -- w3web.net How to convert date format Using @track with html tag in lwc | How to format today Date in DD/MM/YYYY in lightning web components | Convert String To Current Date In Salesforce LWC 8 views
  • upload delete and preview files attachments lightning component -- w3web.net How to get upload/delete and preview the files attachments through apex class uses of lightning:fileCard and lightning:fileUpload elements in Salesforce Lightning component | file Uploader With Preview & Delete in aura component Salesforce 4 views
  • add page header or footer into a visualforce -- w3web.net How to make header and footer fixed and repeat on Visualforce page rendered as PDF in Salesforce | How to add header and footer in Visualforce page rendered as PDF in Salesforce 4 views
  • postman request with parameters in Salesforce -- w3web.net How to Work POSTMAN GET / POST / PUT/ PATCH / DELETE in rest API on Account Object in Salesforce | Handling POST, PUT, PATCH and DELETE Requests Rest API in postman request in Salesforce 3 views
  • create lightning datatable row actions in lwc -- w3web.net Creating a Lightning Datatable with Row Actions and Display a Modal Popup on Click View Icon Button in Salesforce Lightning Web Component – LWC | how to create lightning datatable row actions in lwc 3 views
  • use the lightning formatted fields in lwc - w3web.net How to use the lightning-formatted-email, lightning-formatted-number, lightning-formatted-phone, lightning-formatted-date-time, lightning-formatted-text, lightning-formatted-address, lightning-formatted-url in Salesforce lightning web component (LWC) | how to display of lightning-formatted input fields and there values in Salesforce LWC (Lightning Web Component) 3 views
  • button to create new record salesforce lightning -- w3web.net Create a Lightning Component Button to open New Account in Salesforce | Lightning Button to Create New Contact in Salesforce | Create a Lightning Component button to open New Lead in Salesforce 3 views
  • Surfmyindia |
  • Lifedreamguide |
  • w3webmart |
  • Overstockphoto |
  • News24classictimes |
  • TechW3web |
  • Refund Policy |
  • Delivery Policy |
  • Privacy Policy |
  • Term & Conditions
© 2025 w3web.net • Built with GeneratePress

Chat Now