Category Archives: “CRM Customization”

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!

 

 

 

 

 

 

 

 

 

 

Salesforce Elevate Workshop Atlanta Rocked!

On January 15th I was lucky to get to attend a sold out hands-on developers workshop, Salesforce Elevate, held in midtown Atlanta’s Proscnium Building.

The entire outline for the course is available at http://bit.ly/elevate-intro.

We started from scratch by signing up for a clean new Salesforce Developers account, then diving into declarative programming, Apex, SOQL, DML, Triggers, Visualforce Pages, and Controllers all before noon.

After lunch the class dove into the advanced portion of the workshop. The outline for which can be found here:  http://bit.ly/elevate-advanced.

Subjects covered in the afternoon were, Using javascript in Visualforce pages, Salesforce1 Platform APIs, Using Static Resources, Canvas Applications, Writing Tests, and Batching and Scheduling.

It was definitely a full day for a workshop that included something for everyone, with both beginner and experienced Salesforce developers able to gain a good amount of information from the materials and exercises and interactions with the instructors who both did an awesome job!

Force.com Dev 501 Class

The week of October 10th I was fortunate to have the opportunity to attend Force.com’s Dev 501 class in Atlanta. This class went beyond the declarative capabilities of Force.com covered in Dev 401 and expanded into APEX and Visualforce controllers.

Apex is an object oriented  programming language,  similar to Java and C#,  for building software as a service (SaaS) applications on top of Salesforce.com’s customer relationship management (CRM) functionality.  Apex gives developers access to Salesforce.com’s back-end database and metadata objects to create third-party SaaS applications. These 3rd party applications are offered for sale or free of charge in the Salesforce AppExchange marketplace, similar to the Apple and Android app stores.

Visualforce is a framework that includes a tag-based markup language,  similar to HTML or ASP.Net.

In the Visualforce markup language, each Visualforce tag corresponds to a user interface component, such as a section of a page or a field. The behavior of Visualforce components can be controlled by the same logic used in standard Salesforce pages, or developers can create  their own logic with controller classes written in Apex.

The Dev 501 class covers an amazing array of topics…just a few of which are APEX triggers, Force.com IDE Eclipse plugin, development sandboxes, SOQL queries, DML (data modeling language), deployment from sandbox to production organizations, consuming web services, and unit testing Apex classes.

Format of the class was lecture mixed with hands on exercises reinforced by formal questions answered out loud by attendees at the end of every lecture and exercise.  This was actually the most challenging formal training class I have attended since college…and also one of the best.

 

 

Microsoft CRM 3.0 Customization Class

This technology training didn’t occur in Georgia but I have to mention anyway as it was a great experience. At work I am in process of upgrading our old MS CRM version 1.2 to the latest version 3.0 and was given the chance to attend Microsoft’s 3-day instructor led Customization class. Due to scheduling I needed to attend during the first week in February and I have to say it was very difficult finding a Microsoft partner actually holding the class during that (or any other) week in February. Apparently most of these classes even though scheduled routinely at partner locations don’t actually “make” due to zero or low attendee signups. The one class I found that actually “made” was at a Microsoft partner, Vortex Data Systems, located in San Diego.

I have attended countless technology training classes during my career, but I must say Vortex is the coolest and best run training facility I have experienced. Highlights include the Internet Cafe, a really cool room with free fountain drinks, coffee (of course), snacks, computers, and wifi available for student breaks. Wifi was available throughout the facility even though not necessary since each student computer was Internet connected. Thursday afternoon they feature free ice cream sundaes for all students. Student computers were top notch as was all of the equipment. Registration was well organized and they cut us a good price for the class. I really can’t say enough about the great job Vortex did and how much I enjoyed taking a class there. If I ever get another chance to attend a Microsoft CRM class I will definitely choose Vortex in San Diego if at all possible.

While the vast majority of the hours spent in San Diego were dedicated to class, we did manage to view a couple of incredible West coast sunsets, something we rarely see in Atlanta.