Tag Archives: Salesforce Apex Trigger

Wedid: Supply Forecast


A retailer supplies agricultural products to hypermarkets. It is crucial for this retailer to keep track of the level of supply every month in order to ensure that their suppliers will always have sufficient supply for future order. However, at this moment the visibility of the supply level against the number of contracted order is not available.


A supply and order forecast module is built in Salesforce. The users can now enter supply forecast records for each month and each product. Any opportunity line item created will be linked to the right supply forecast record.

A report is then created to display the supply vs demand for the particular month.

Related Objects Account, Opportunity, Opportunity Product, Product, Custom Objects, Custom Settings
Components Data Model Design, Apex Trigger, Apex Classes, Report & Dashboard
Complexity Medium

Wedid: Automated Energy Savings Certificate (ESC) Calculations


The IPART has a specific formula for the Energy Savings Scheme (ESS) to calculate Energy Savings Certificates (ESC). The company needs to capture the baseline lighting system (current) and compare it with the upgraded lighting system (proposed). The current calculation is done using excel and it poses some challenges:

  • the calculation is not accurate because not all scenarios are considered
  • not extensible
  • difficult to track the itemised calculations


  • Capture current and new lighting system in Salesforce
  • Calculate saved MWH and ESC
  • Calculate the estimated ESC money value and prepare a ROI report to end customer in quote

Related Objects Opportunity, Quote, Custom Object
Components Apex Class, Apex Trigger, Visualforce Page, Data Model Design
Complexity Complex

Wedid: Automate Installation Job from Closed Opportunity


The business organisation runs an electrical appliance shop. The typical sales cycle for this business includes:

  • sales to convert leads to account/opportunities
  • sales to close won successful opportunities
  • coordinator to receive a notification from sales
  • coordinator to manually create an installation record (custom object) and link to the closed won opp to track on the status
  • coordinator to manually update the installation status back to opportunity upon completion

Some additional challenges,

  • the coordinator must not see all data related to the sales figures for the opportunity
  • the coordinator only has Force.com App Subscription license (no access to Opportunity object)


  • Create separate data model for job installation
  • Automate the job to create the installation record via a button ‘Create Installation Job’
  • Provide validation to ensure only one installation record is created per Opportunity

Related Objects Opportunity, Custom Object
Components Apex Trigger, Apex Class, Visualforce Page, Custom Button
Complexity Medium

Wedid: Allow Tracking/Converting Multiple Contacts Per Lead


In the business world of marketing it’s only natural that you will be communicating with different user roles such as the marketers, publishers, strategist and the list goes on. Our customer faces a problem when they try to track these users going into a prospective lead. SF currently converts one contact per lead and it poses the following issues for our customer:

  • unable to track multiple contacts within a lead
  • will have to create multiple leads and manually attach to existing account which takes too much time
  • manual creation of the contacts only after the lead is converted


To allow tracking and converting multiple contacts per lead

Related Objects Lead, Account, Contact
Components Apex Class, Apex Trigger
Complexity Medium

Wedid: Data Population to Activity


User requires a feature to populate mobile numbers into tasks and events from related leads or contacts.

From this, they will be able to see the mobile numbers which are more relevant when scheduling appointments with their leads and contacts in Salesforce.
This is also useful when other invitees of the event needs to view the mobile numbers without having to navigate to the related lead or contact records.
In Salesforce, the only data that is brought over from leads or contacts is the phone number. Standard formula and workflow are not the solution to this as they can not work with the Whoid and Whatid in Activity.


To populate mobile number from leads/contacts to tasks/events.

Related Objects Activity
Components Apex Trigger
Complexity Moderate

Wedid: Copy Related List during Lead Conversion


The users are running a solar panel business. Each of their leads have more than one location data  (related list). Once the lead is converted, the customer would like the related list to be copied over into the Account object as well.


To bring over the installation location data from Lead related list to opportunity and account realted list on lead convert

Related Objects Lead, Account, Opportunity and Custom Object
Components Apex Trigger
Complexity Moderate

Wedid: Invoice Pro-rata Calculation


In a subscription business model, its important that the monthly invoice/bill amount is presented correctly to their customer and the following scenarios are the common challenges in managing the monthly bill amount:

A simple full month scenario is as explained here. However, there may be situation where the subscription starts in the middle of the month, for example:
The Subscription for Product A for the customer has the following details:
Subscription Start Date: 10th Mar 2013
Subscription period: 6 months
Subscription End Date; 10th Sep 2013
Total Subscription Price: $6,000
In this case, the following billing items will automatically be created:
Billing #1 = Period: 10th Mar – 31st Mar 2013; Bill Date: 1st Apr 2013; Amount: $709.68
Billing #2 = Period: 1st Apr – 30th Apr 2013; Bill Date: 1st May 2013; Amount: $1,000
Billing #3 = Period: 1st May – 31st May 2013; Bill Date: 1st Jun 2013; Amount: $1,000
Billing #4 = Period: 1st Jun – 30th Jun 2013; Bill Date: 1st Jul 2013; Amount: $1,000
Billing #5 = Period: 1st Jul – 31st Jul 2013; Bill Date: 1st Aug 2013; Amount: $1,000
Billing #6 = Period: 1st Aug – 31st Aug 2013; Bill Date: 1st Sep 2013; Amount: $1,000
Billing #7 = Period: 1st Sep – 10th Sep 2013; Bill Date: 1st Oct 2013; Amount: $290.32
The customer is looking for a solution which includes the handling of the full subscription as well as the pro-rata subscription scenario.


  • Automatically calculate, for example the bill amount of a subscription (i.e. a subscription deal)
  • Ensure that the bill amount is reflected correctly in the subscription (i.e. including a non-full month subscription which requires pro-rata calculation)

Related Objects Standard/Custom object
Components Apex Class & Apex Trigger
Complexity Complex

Wedid: Dynamic Form Field Population


The customer has a huge number of applicants applying for different range of products everyday.

One application requires one application form and most of the sections in the application form are filled up manually.
The complexity extends to a level where:
  1. Applicant details are filled up into different sections of the form based on different criteria e.g. product type.
  2. The application form will be filled up repeatedly for each different applications even if they are for existing applicants. e.g, Full name with be manually filled up over and over again for new applications for the same applicants.
Normal template generator may not work in this scenario due to the complexity of the customer’s existing Salesforce data model and the complexity of the criteria relevancy.
Customer is looking for a solution that allows them to generate the form with pre-populated values in the relevant sections based on relevant criteria.


  • Generate form with pre-populated values.
  • Pre-populate values into different section of the form based on relevant criteria.

Related Objects Standard/Custom object
Components Apex Trigger
Complexity Complex

Wedid: Dynamic Auto Number


The customer plans and implements programs/services for their clients.

They keep track on opportunities using ascending/unique auto numbers. These job numbers will only be assigned to opportunities that hits certain stage.

For this scenario, we have ruled out the Salesforce standard auto-number field as the unique numbers are assigned to all opportunity records.


Opportunity Stage Auto Number
Opportunity 1 Closed Won 001
Opportunity 2 Prospecting -
Opportunity 3 Negotiating -
Opportunity 4 Closed Won 002


Dynamically assigned auto number to opportunities at certain stage.

Related Objects Opportunity, Custom Settings
Components Apex Trigger and Apex Class
Complexity Moderate

Wedid: The Default Quote Template Alternative


Customer would like to have more flexibility in designing the quote template (i.e. more control over the content style, page break, etc.) which meets their requirement.


  • An easy one click button from Quote record to display a PDF rendered Quote in the format that meets the customer’s requirement
  • Capability to send email to contact with the PDF Quote attached

Related Objects Standard Quote Object
Components Apex Trigger
Complexity Simple