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
- Log in to Salesforce:
- Open your web browser and log in to your Salesforce Developer account.
- Access Developer Console:
- In the Salesforce interface, click on the “App Launcher” (grid icon) and search for “Developer Console.”
- Open the Developer Console.
- 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.”
- In the Developer Console, go to
- 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!';
}
}
}
-
Save the Apex Class:
- Click
File -> Save
(or useCtrl + S
orCmd + S
) to save your Apex class.
- Click
-
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.
- Click
-
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
-
Install Visual Studio Code:
- If you don’t have Visual Studio Code installed, download and install it from Visual Studio Code website.
-
Install Salesforce Extensions:
- Install the Salesforce Extension Pack for Visual Studio Code. You can find it in the Visual Studio Code Extensions Marketplace.
-
Open Visual Studio Code:
- Open Visual Studio Code, and make sure the Salesforce Extension Pack is installed and activated.
-
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.
-
Write Apex Code:
- In the editor, write your Apex code.
-
Save the Apex Class:
- Save Apex class by clicking
File ->
(or useCtrl + S
orCmd + S
).
- Save Apex class by clicking
-
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 Apex Developar
Nice post
Pingback: How to use loop in apex Salesforce O - 9to9clouds