how to create apex class in salesforce


Creating an Apex class in Salesforce involves writing server-side code to extend the functionality of your Salesforce application. Follow these steps how to create Apex class in salesforce:. Here are step-by-step instructions for both methods:

There are some useful link please click the link below

  1. Log in to Salesforce:
    • Open your web browser and log in to your Salesforce Developer account.
  2. Access Developer Console:
    • In the Salesforce interface, click on the “App Launcher” (grid icon) and search for “Developer Console.”
    • Open the Developer Console.
  3. Create a New Apex Class:
    • In the Developer Console, go to File -> New -> Apex Class.
    • Enter a name for your class in the “Name” field (e.g., “MyApexClass”).
    • Click “OK.”
  4. Write Apex Code:
    • In the editor, write your Apex code. Here’s a simple example:

	public class MyApexClass {
           public String greeting {
             get {
                return 'Hello, Salesforce!';
        }
    }
}

				
  1. Save the Apex Class:

    • Click File -> Save (or use Ctrl + S or Cmd + S) to save your Apex class.
  2. Compile and Check for Errors:

    • Click Run -> Compile All Classes to compile your Apex class.
    • Check the “Problems” tab for any compilation errors. If there are errors, review the code and fix them.
  3. Execute or Integrate:

    • Once your Apex class is error-free, you can use it in other parts of your Salesforce environment, such as triggers, controllers, or batch jobs.

Method 2: Using Visual Studio Code with Salesforce Extensions

  1. Install Visual Studio Code:

  2. Install Salesforce Extensions:

    • Install the Salesforce Extension Pack for Visual Studio Code. You can find it in the Visual Studio Code Extensions Marketplace.
  3. Open Visual Studio Code:

    • Open Visual Studio Code, and make sure the Salesforce Extension Pack is installed and activated.
  4. Create a New Apex Class:

    • Click on the “Explorer” icon on the sidebar.
    • Right-click on your Salesforce project folder and select SFDX: Create Apex Class.
    • Enter a name for your class when prompted.
  5. Write Apex Code:

    • In the editor, write your Apex code.
  6. Save the Apex Class:

    • Save  Apex class by clicking File ->  (or use Ctrl + S or Cmd + S).
  7. Deploy to Salesforce:

    • Use the Salesforce CLI commands or the Salesforce Extensions to deploy your Apex class to your Salesforce environment.
    •  

    thanks for read….

Raghavendra Pratap Singh
Raghavendra Pratap Singh  Apex Developar

2 thoughts on “how to create apex class in salesforce”

  1. Pingback: How to use loop in apex Salesforce O - 9to9clouds

Comments are closed.

Scroll to Top