All posts by Mike Parks

How to Dynamically Populate Fields in Salesforce Data Entry Screens Using Apex Classes

I recently had to solve this use case for a work project and I thought I would share as it could be very useful across a number of scenarios within  Salesforce. Why this is really useful and powerful is that it works on a New Object screen BEFORE the save occurs. So you can see results while the screen is still in edit mode.

The application has two custom objects, Proposal and Project, that are related with a lookup from Project to Proposal. While the relationship  is not Master-Detail, the Proposal lookup field is required on the Project screen so that a Proposal is required before a Project can be created.  Both Proposal and Project have fields in common of Title, Account, Contact, and Scope of Work. Title, Account, and Contact are required on both objects.

The Use Case is that when creating a new Project all four of these fields should copy over from the related Proposal so the user doesn’t have to reenter them,  while remaining editable on the Project data entry screen, all before saving the Project. So when the New Project button is clicked, and the related Proposal is selected, all of the related common field values from the Proposal should immediately copy over into matching fields on the Project screen prior to clicking the Project save button.  Workflow field updates and triggers don’t work for this scenario because (1) we don’t want to first have to click save and then go back into edit before making changes and finish filling out other fields on the New Project screen. And (2) since these fields are required on the Project screen the record won’t save in the first place unless all of the required fields contain values.

proposalexample

 

The solution has to work in two different cases when creating a new Project. One is clicking the Project tab and then selecting the New Project button. In this scenario the user will need to first select the related Proposal after which the related fields should be copied over from Proposal to Project. The other case occurs when starting from the Proposal screen and clicking the New Project button in the related project list. In this case the Proposal__c.Name is automatically copied over to the related Proposal__c field on new Project screen and so is unnecessary for the user to select. Our solution has to work correctly for both of these cases.

The solution for this problem is to create a Visualforce page with an extended controller class that replaces the standard New Project page. Three files have to be created to make this work, a Visualforce page,  an Apex class, and a unit test. Salesforce requires you to run a unit test on all code before you are able to deploy from sandbox into production.

The VisualForce Page

I won’t go into how to create a VisualForce page here, but I will mention a free tool I use which makes turning a standard or custom object page into a VisualForce page a snap.  It’s called Layout Page and can be found in the App Store. It converts any Salesforce Page Layout (Standard OR Custom) into a Standard Visualforce Page instantly.

Once you have created the VisualForce page the following changes should be made.

The first line of the VisualForce page shown below sets the controller and extension for the page. The main controller is the Project__c object and the Apex extension class is named RelatedController1.

<apex:page standardController="Project__c" extensions="RelatedController1">

This next line of code calls the Apex function PopulateProject() whenever a user selects the related Proposal. The PopulateProject() method will locate the selected Proposal record in Proposal__c and copy the fields, Title, Contact, Account, and Scope_of_Work from the selected Proposal record into the appropriate fields on the new Project screen. This line handles the scenario where the user selects the New Project button from the Projects tab and so on the New Project screen the related Proposal is blank and needs to be manually selected.

<apex:inputField value="{!Project__c.Proposal__c}">
            <apex:actionSupport event="onchange" action="{!PopulateProject}" rerender="accinfo, msgs"/> 
         </apex:inputField>

The following line handles the scenario where the user selects New Project button from the Project related list on the Proposal screen where the Proposal Name will already be filled in and so not necessary to select. This line calls an inline Ajax function located at the bottom of the VisualForce page that checks to see if the  Project__c.Proposal__c field is NOT null, in which case it calls the Apex method PopulateProject to copy in all of the Proposal field values.

<apex:actionFunction name="CallApexMethod" action="{!PopulateProject}" reRender="accinfo, msgs"/>

The Ajax code below should be located at the bottom of the VisualForce page just above the </apex:page> tag. This script executes on every page load, which is what we need in order to check if the related Proposal has already been selected.

<script>
    function addLoadEvent(func) 
{ 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') 
  { 
     window.onload = func; 
  } 
  else
  { 
      window.onload = function()  
      { 
        if (oldonload) 
        { 
           oldonload(); 
        } 
        func(); 
      } 
   } 
} 
   
addLoadEvent(function()  
{ 
var controllervariable='{!Project__c.Proposal__c}';
if(controllervariable==null){return false;}
else {
  CallApexMethod(); }
});
</script>

The Apex Class

The Apex class, RelatedController1, is shown below. This where all the work happens to locate the selected Proposal record and set fields in the new Project record equal to fields from the selected Proposal record.

public with sharing class RelatedController1
{
public Proposal__c prop {get;set;}

private ApexPages.StandardController stdCtrl;

public RelatedController1(ApexPages.StandardController std)
{
stdCtrl=std;
}

public void PopulateProject()
{
Project__c proj=(Project__c) stdCtrl.getRecord();
if(proj.Proposal__c == null){return;}
else{
prop=[select Name,  Account__c, Scope_of_Work__c, Contact__c from Proposal__c where Id=:proj.Proposal__c];

proj.Name=prop.Name;
proj.Account__c=prop.Account__c;
proj.Scope_of_Work__c=prop.Scope_of_Work__c;
proj.Project_Contact__c=prop.Contact__c;}
}
}

All of the work described so far has to be completed in a Salesforce sandbox or developer account. I used a  partial sandbox under my Production org which copies a subset of data into the sandbox along with all of the Production org metadata.

The Unit Test

Once everything is working correctly in sandbox, you will have to create a unit test that when run exercises at least 80% of the code in the Apex class without error. Only then will Salesforce allow you to create an outbound change set and deploy it into your Production org.

The code for the test class is shown below.

@isTest(SeeAllData=true)

public class RelatedController1Test {

static testMethod void testRelatedController1() {
// Select an actual proposal record from Proposal__c
Proposal__c p = [SELECT Id, Name FROM Proposal__c WHERE       Name=’Test Proposal Dekra’ LIMIT 1];
// Clone the selected proposal record and set some of the fields
Proposal__c testProposal = p.clone();

testProposal.Name = ‘Acme Test’;
testProposal.Scope_of_Work__c = ‘test’;
// Create the test proposal record
insert testProposal;

// Create the test project record and set the related Proposal__c field equal to the Id of the newly created test Proposal__c.Id.
Project__c prj = new Project__c();
prj.Name = ‘test’;
prj.Proposal__c = p.Id;

insert prj;
// Now run the test by instantiating the RelatedController1 class and calling the PopulateProject() method. This test gives 100% coverage.
Test.startTest();
ApexPages.Standardcontroller std = new ApexPages.Standardcontroller(prj);
RelatedController1 clsObj = new RelatedController1(std);
clsObj.PopulateProject();
Test.stopTest();
}
}

When the test has run successfully you are ready to create an outbound Change Set containing  two files, the RelatedController1 Apex class file and the Visualforce page, and deploy them into your Production org.

ERP in 2015 – free and open!

cmitBack in the 1990’s I ran an IT Center in Georgia with a mission to help small to mid size companies select and implement off the shelf ERP software. Over an eight year period I assisted hundreds of companies in their quest to upgrade or acquire an ERP system. Back then ERP systems all tended to be proprietary commercial, client/server, installed on on-premise servers, and accessed by users over local and wide area networks. None ran as web apps over the public Internet aka SaaS (Software as a Service) and there were virtually no open source ERP systems of any consequence.

Fast forward to today and you see ERP systems running on a variety of platforms, Windows and most flavors of Linux, and many are available as SaaS (Software as a Service) solutions where you don’t have to know or care which operating system they are running on.

While the most popular ERP systems, especially for larger companies, are from SAP, Oracle, and Microsoft; there are also a number of open source solutions available to freely download and deploy as you see fit.

Besides the obvious benefit of being free, today’s open source ERP solutions have several other advantages including a wide variety of deployment scenarios, hundreds of volunteer developers, and large support communities. Most of these systems are backed by companies who provide optional fee based Software as a Service plans, premier support, installation, migration, and integration  support, etc. But you always have the option of downloading and implementing the software yourself completely free of charge, either on premise on your own server or on a cloud platform such as Amazon EC2 or Microsoft Azure.

Some of the most popular open source ERP solutions include the following:

Odoo – With over two million users Odoo seems to be by far the most popular of the open source ERP options. I’ve used Google Trends to compare all of these open source ERP systems and Odoo seems to stand out far ahead of all the others as you can see in the following Google trend graph. I’ve tried all combinations and get similar results each time regardless of which (open source) ERP systems I compare with Odoo.

erptrends

Odoo provides an integrated suite of apps for CRM, Accounting, Manufacturing, Warehouse Management, Project Management, eCommerce, Web Site, and on and on with hundreds of applications that can be bolted on as the need arises. Odoo offers a fee based cloud hosted solution (free for the first 2 users) or you can download all of the software for free and install it yourself.

odoo
Odoo Setup Screen to Install Optional Modules

Odoo is written in Python and uses the PostgreSQL database. Screens can be customized but you should be able to handle Python if you want to do the customization yourself.

With Odoo and most of these systems you have a wide variety of deployment options; local on premise server, Amazon Web Services, Rackspace, Digital Ocean, etc. So far my favorite method of deployment for a multi-user Odoo server is the Bitnami Odoo Stack which can be launched with a single click onto Amazon Web Services, Microsoft Azure, Google Cloud Platform, or VM Ware vCloud. There are also pre-configured Docker containers for Odoo.

ERPNext – This system is inexpensive at only $300 per year for 5 users on the hosted version. It’s also easy to install the free version yourself either on premise or cloud. ERPNext is designed for self-implementation. The Setup Wizard helps you get started with your Company, Items, Customers, and Suppliers. Included are modules for accounting, managing inventory, sales, purchase, and project management. The applications that make up ERPNext are form-driven—you fill information in a set of fields and let the application do the rest. The whole suite is easy to use.

ERPNext is written in Python and uses the MariaDB database.

Dolibarr – Easy one-click install onto most Linux hosting platforms such as Hostgator and Siteground. Designed for small companies,  foundations and freelances.  Written in PHP and uses either MySql or PostgreSQL database and installers are available for Windows, Debian/Ubuntu, Fedora/Redhat/OpenSuse. Documentation is available at http://wiki.dolibarr.org/

Opentaps – I haven’t tried this package but their website highlights some impressive case studies with high profile companies like Honeywell and Toyota. You can read about features available here.

An Opentaps Amazon Machine Image is available to install onto Amazon’s EC2 cloud platform. I haven’t tried it yet but I know it’s available.

Written in Enterprise Java using either MySQL or PostgreSQL databases.

Compiere – This ERP system is the only one I recall from back in the 1990’s as the first open source ERP package of any consequence. Back then it seemed hard to install compared to competing commercial packages and so I did not promote it in my IT Center. Compiere has since been acquired by Aptean, a company that has acquired many commercial ERP packages over the years including some I demonstrated at my center…Made2Manage for example is now owned by Aptean.

Compiere is written in Java and runs on Postgres and Oracle databases.

webERP – This is an easy to install ERP web application available on most commercial hosting platforms such as Siteground and Hostgator.  I installed on my Siteground hosting account with a single click of the mouse. webERP is a complete web based accounting and business management system that requires only a web-browser and pdf reader to use. It has a wide range of features suitable for many businesses particularly distributed businesses in wholesale, distribution and manufacturing.

Written in PHP with a mysql database.

There are other ERP systems that claim to be open source…and technically I’m sure are open source. However they make obtaining and installing the “free” version (usually called the Community version) of their software difficult and hard to find with virtually zero support of any kind.  I’m leaving them out of this list on purpose. Not that there is anything wrong with these packages but in this post I wanted to try and highlight some of the easiest open source ERP systems to obtain and install as well as provide readers with a glimpse of the many solutions that are available nowadays in this space.

In summary open source software is being used more than ever before in modern Enterprises, including open source ERP solutions, that may be just as functional as their commercial counterparts but without a marketing organization to promote them get much less attention and awareness.  Hopefully articles like this one will help get the word out!

 

 

 

 

 

 

 

 

 

 

SQL Saturday Atlanta – 2015 is in the books!

One of my favorite technology events every year is SQL Saturday. For the past few years it’s been held at Georgia State’s Alpharetta campus. Each year I’m newly amazed by the huge turnout at this event, which is always sold out with a couple of dozen people standing around check-in early in the morning just hoping to get in. It always makes me realize that SQL Server is a big deal!

Some of this years tracks included Big Data & Data Science, Powershell, BIML, BI, ETL/SSIS, Reporting & Visualization, and DBA. I found myself glued to the big data track with sessions so interesting I couldn’t bring myself to leave the room! My favorite session for the day was Sentiment Analysis with Big Data by Paco Gonzalez, which touched upon data mining techniques including natural language processing and text mining Twitter data for sentiment and tone analysis. Pretty cool stuff!

SQL Saturday events are held worldwide throughout the year. You can check the schedule for events in your area on this site which lists them all.

http://www.sqlsaturday.com/

 

 

Salesforce Platform Workshop

Living in Atlanta gives me the opportunity to attend many top quality technology events entirely free of charge (except for an occasional parking fee). I recently attended one such event…a one day hands-on development class held at the Atlanta Salesforce offices, located on the 33rd floor of the One Atlanta Plaza building in Buckhead just across the street from the Lenox Marta Station…nice location!

buckhead
View of Buckhead skyline from Atlanta Salesforce Offices

The class, Salesforce Platform Workshop, was standing room only and they actually had to bring in extra chairs to accommodate additional unexpected attendees. A printed workbook was provided but you could also follow online at http://bit.ly/atlantadevworkshop.

Class entailed a series of hands-on exercises building a conference management application from scratch that included applying some of the latest Force.com technologies, Process Builder and Lightening Connect.  We even entered and deployed some Apex code for triggers to send email notifications whenever new records were entered. We ran out of time before the final module, deploying an app on Heroku and using the Salesforce REST APIs, but since we have the workbook I was able to work through this module afterwards on my own.

Two best tips I picked up were (1) you can’t make a standard object the detail in a Master-Detail relationship and (2) always put the relationship field on the object that needs to lookup, a concept I often get confused about.

The most valuable part of the day for me was working through an exercise using Lightening Connect to sync an external data source via a REST interface so that it looks like part of the Force.com application. This was something I wasn’t aware of prior to the workshop and something I can put to use immediately.

All in all a good day…much thanks to the local Atlanta Salesforce team for hosting the workshop!

 

 

 

Rise of the Rest in Atlanta with Steve Case

Yesterday I was privileged to attend Steve Case’s Rise of the Rest tour stop held in Atlanta at the Opera House on Crescent Street in midtown Atlanta. I have to say it was an awesome event!

Whenever I attend an event at the Opera House I try to get a spot in one of the 2nd floor box seats…where often I’m all alone in a big comfy cushioned seat with a table (to set my laptop) and a great view of the main stage. Today I got a perfect spot from which to watch the show!

The first hour was a fireside chat by Steve where he discussed how Atlanta could increase entrepreneurship through more celebrating of entrepreneurship, mentoring of new entrepreneurs, and connecting; while focusing on Atlanta’s advantages of diversity and large company partnering opportunities.

According to Steve, 75% of all venture capital in the US goes to white men located in three states (New York, Massachusetts, and California).  His #riseofrest message is that we need to level this playing field and provide opportunities to all the other communities of capable entrepreneurs by leveraging the unique strengths found in each community.

one

Atlanta Mayor Kasim Reed was a  surprise speaker at the event who gave a short welcome speech.

two

For the next two hours we were treated to 5 minute pitches from eight local Atlanta startup companies all competing to win $100,000 from Steve that afternoon! Judging was done by a distinguished panel of judges seen below.

three

The pitch competitors this afternoon were:

1. Cooleaf

2. Ground Floor

3. local roots

4. Village Micro Fund

5. Zyrobotics

6. eCredable

7. revealestate

8. partpic

All of the pitches were well done. If I had the money I would invest in all of them. But only one won the day with the panel of judges.

And the $100,000 winner was, partpic!

four

The after-party was held on the outside patio of the Opera House Nightclub. ..very nice indeed!

five

 

Some of the tweets from the day…..

“Partnering between startups and large corporations can be a core competence of Atlanta.”

Pitch #5: provides personalized accessible robotic therapy to kids with motor limitations. Company.

Pitch #6. makes every payment count and builds a credit score that uses ALL your payment data.

. uses technology & robotics to help kids with disabilities get therapy in pitch #5

Huge thanks to for bringing his tour to our ATL. Congrts to on the $100k pitch prize.

The 3rd wave of the internet will require more partnerships btwn startups and corporations and government.

The mission of -based is to build a better experience for private real estate transactions.