![Apex Programming Tutorial](/apex/images/apex-mini-logo.jpg)
- Apex Programming Tutorial
- Apex - Home
- Apex - Overview
- Apex - Environment
- Apex - Example
- Apex - Data Types
- Apex - Variables
- Apex - Strings
- Apex - Arrays
- Apex - Constants
- Apex - Decision Making
- Apex - Loops
- Apex - Collections
- Apex - Classes
- Apex - Methods
- Apex - Objects
- Apex - Interfaces
- Apex - DML
- Apex - Database Methods
- Apex - SOSL
- Apex - SOQL
- Apex - Security
- Apex - Invoking
- Apex - Triggers
- Apex - Trigger Design Patterns
- Apex - Governer Limits
- Apex - Batch Processing
- Apex - Debugging
- Apex - Testing
- Apex - Deployment
- Apex Useful Resources
- Apex - Quick Guide
- Apex - Resources
- Apex - Discussion
Apex - Example
Enterprise Application Development Example
For our tutorial, we will be implementing the CRM application for a Chemical Equipment and Processing Company. This company deals with suppliers and provides services. We will work out small code snippets related to this example throughout our tutorial to understand every concept in detail.
For executing the code in this tutorial, you will need to have two objects created: Customer and Invoice objects. If you already know how to create these objects in Salesforce, you can skip the steps given below. Else, you can follow the step by step guide below.
Creating Customer Object
We will be setting up the Customer object first.
Step 1 − Go to Setup and then search for 'Object' as shown below. Then click on the Objects link as shown below.
![Customer Object Ceation Step1](/apex/images/customer_object_creation_step_1.jpg)
![Customer Object Ceation Step1-2](/apex/images/customer_object_creation_step_1_2.jpg)
Step 2 − Once the object page is opened, then click on the 'Create New Object' button as shown below.
![Customer Object Ceation Step3](/apex/images/customer_object_creation_step_3.jpg)
Step 3 − After clicking on button, the new object creation page will appear and then enter all the object details as entered below. Object name should be Customer. You just have to enter the information in the field as shown in the screenshot below and keep other default things as it is.
![Customer Object Ceation Step4](/apex/images/customer_object_creation_step_4.jpg)
Enter the information and then click on the 'Save' button −
![Customer Object Ceation Step5](/apex/images/customer_object_creation_step_5.jpg)
By following the above steps, we have successfully created the Customer object.
Creating the Custom Fields for Customer object
Now that we have our Customer object set up, we will create a field 'Active' and then you can create the other fields by following similar steps. The Name and API name of the field will be given in the screenshot.
Step 1 − We will be creating a field named as 'Active' of data type as Checkbox. Go to Setup and click on it.
![Customer Custom Field Creation Step1](/apex/images/customer_custom_field_creation_step_1.jpg)
Step 2 − Search for 'Object' as shown below and click on it.
![Customer Custom Field Creation Step2](/apex/images/customer_custom_field_creation_step_2.jpg)
Step 3 − Click on object 'Customer'.
![Customer Custom Field Creation Step3](/apex/images/customer_custom_field_creation_step_3.jpg)
Step 4 − Once you have clicked on the Customer object link and the object detail page appears, click on the New button.
![Customer Custom Field Creation Step4](/apex/images/customer_custom_field_creation_step_4.jpg)
Step 5 − Now, select the data type as Checkbox and click Next.
![Customer Custom Field Creation Step5](/apex/images/customer_custom_field_creation_step_5.jpg)
Step 6 − Enter the field name and label as shown below.
![Customer Custom Field Creation Step6](/apex/images/customer_custom_field_creation_step_6.jpg)
Step 7 − Click on Visible and then click Next.
![Customer Custom Field Creation Step7](/apex/images/customer_custom_field_creation_step_7.jpg)
Step 8 − Now click on 'Save'.
![Customer Custom Field Creation Step8](/apex/images/customer_custom_field_creation_step_8.jpg)
By following the above steps, our custom field 'Active' is created. You have to follow all the above custom field creation steps for the remaining fields. This is the final view of customer object once all the fields are created −
![Final View Customer Object](/apex/images/final_view_customer_object.jpg)
Creating Invoice Object
Step 1 − Go to Setup and search for 'Object' and then click on the Objects link as shown below.
![Invoice Object Creation Step1](/apex/images/invoice_object_creation_step_1.jpg)
![Invoice Object Creation Step2](/apex/images/invoice_object_creation_step_2.jpg)
Step 2 − Once the object page is opened, then click on the 'Create New Object' button as shown below.
![Invoice Object Creation Step3](/apex/images/customer_object_creation_step_3.jpg)
Step 3 − After clicking on the button, the new object creation page will appear as shown in the screenshot below. You need to enter the details here. The object name should be Invoice. This is similar to how we created the Customer object earlier in this tutorial.
![Invoice Object Creation Step4](/apex/images/customer_object_creation_step_4.jpg)
Step 4 − Enter the information as shown below and then click on the 'Save' button.
![Invoice Object Creation Step5](/apex/images/invoice_object_creation_step_5.jpg)
By following these steps, your Invoice object will be created.
Creating the Custom Fields for Invoice object
We will be creating the field Description on Invoice object as shown below −
Step 1 − Go to Setup and click on it.
![Customer Object Creation Step1](/apex/images/customer_object_creation_step_1.jpg)
Step 2 − Search for 'Object' as shown below and click on it.
![Customer Object Creation Step1-2](/apex/images/customer_object_creation_step_1_2.jpg)
Step 3 − Click on object 'Invoice'.
![Invoice Custom Field Creation Step3](/apex/images/invoice_custom_field_creation_step_3.jpg)
And then click on 'New'.
![Invoice Custom Field Creation Step](/apex/images/invoice_custom_field_creation_step_4.jpg)
Step 4 − Select the data type as Text Area and then click on Next button.
![Invoice Custom Field Creation Step5](/apex/images/invoice_custom_field_creation_step_5.jpg)
Step 5 − Enter the information as given below.
![Invoice Custom Field Creation Step6](/apex/images/invoice_custom_field_creation_step_6.jpg)
Step 6 − Click on Visible and then Next.
![Invoice Custom Field Creation Step7](/apex/images/invoice_custom_field_creation_step_7.jpg)
Step 7 − Click on Save.
![Invoice Custom Field Creation Step8](/apex/images/invoice_custom_field_creation_step_8.jpg)
Similarly, you can create the other fields on the Invoice object.
![Final Invoice Object View](/apex/images/final_invoice_object_view.jpg)
By this, we have created the objects that are needed for this tutorial. We will be learning various examples in the subsequent chapters based on these objects.
To Continue Learning Please Login