Before You Begin:
1. If you haven't already, deploy the pre-requisite Flows: Flow-Into-Apex Package
2. Click on "Run Tests Only" before making any changes. This ensures the Flow works as is without updating the challenge progress.
3. Deactivate the Flow & rebuild as Apex
4. Hit the "Submit" button when you're ready to have your final solution evaluated and challenge progress updated
1. If you haven't already, deploy the pre-requisite Flows: Flow-Into-Apex Package
2. Click on "Run Tests Only" before making any changes. This ensures the Flow works as is without updating the challenge progress.
3. Deactivate the Flow & rebuild as Apex
4. Hit the "Submit" button when you're ready to have your final solution evaluated and challenge progress updated
Flow To Convert
Create Renewal Opportunity
Description
After an opportunity is "Closed Won", a renewal opportunity should get created for the related account. The close date should be set to 12 months in the future, and the following fields should be mapped over to the new opportunity:
- Account ID
- Owner ID
Object & Trigger Event
Opportunity, on After Update
Concepts to learn
- Reusing existing record information to create new records
- String Concatenation
- Setting close date in the future
- Catching DML Exceptions
Resources
YouTube Videos
- Flow into Apex: TRIGGER your Coding Powers in Salesforce
- Flow into Apex: Transform Your Salesforce Skills
Salesforce Documentation
- Triggers Overview
- Trigger Syntax
- Trigger Context Variables
- Bulk Apex
- For loops (needed for bulk apex)
- Conditional Statements
- addMonths Date method
- Inserting and Updating Related Records
Challenge Cheat Codes
- Place your insert logic inside a try-catch block. If a DML Exception occurs, you can simply log it using System.debug() to help with troubleshooting.
- Pro Tip: While debug logs work for this challenge, in real applications, you’ll need a better way to capture and address errors, such as custom logging, email alerts, or tracking with Salesforce tools.
- You don't want the trigger to fire every time an Opportunity is updated. Use conditional statements to check for specific values.
- Pro Tip: You can also check if a specific field value has changed by comparing the old values (Trigger.old) and new values (Trigger.new) for that field. While we aren't checking for changed values in this challenge, this tip is good for preventing unnecessary code execution and improving performance.
- In Apex, you can use the + operator to merge multiple strings into one. This is known as string concatenation.
- Example 1: "Opportunity Name: " + oppty.Name
- Example 2: "The " + oppty.Name + " opportunity is in the following stage: " + oppty.StageName