The company utilizes salesforce sales cloud to manage leads and customer details. Leads are pushed from an external system to salesforce via REST API. The lead object in salesforce requires a 'Company' field, which is not mandatory in the external system.
To address this, the salesforce team has opted to implement an apex trigger. The apex trigger will automatically populate the 'Company' field on leads when it's missing during lead record creation.
Complete the given apex trigger handler to achieve this requirement.
Instructions:
1. If the company name is blank, then update the company name field to 'TBA'
2. If the company name is not blank, keep the company name as it is
Note:
1. The lead trigger has been deployed to your salesforce instance, and the provided beforeInsert method will be invoked for the "before insert" event.
2. Use trigger context variables (i.e., trigger.new) to access the records from the trigger handler.
Example:
//Lead
Insert new Lead (lastname='Decodeforce', company=null);
//Result
The lead 'Decodeforce' will have company name populated as 'TBA'
Hint:
In this scenario, the record that is inserted into the database requires a field value to be filled in. Utilize the "before" trigger event to fill the field value for the records that initiated the trigger.
Ensure that the trigger code is bulkified, using appropriate variable types to prevent any potential breaches of governor limits.