Category Archives: Salesforce

Salesforce Schedule APEX Batch Job

To test an APEX Batch job, open the Developer Console then the Anonymous Execute window. Here’s the code to run the job:

datetime thisTime = system.now().addMinutes(1); 
integer second = thisTime.second(); 
integer minute = thisTime.minute(); 
integer hour = thisTime.hour(); 
integer day = thisTime.day(); 
integer month = thisTime.month(); 
integer year = thisTime.year(); 

String timeStamp = second + ' ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ? ' + year; 

String jobId = System.schedule('Test Opportunity Contact Lookup', timeStamp, new ZD_UpdateContactOpportunityBatch());

Salesforce Add Action To apex:EnhancedList

There’s no quick way to add actions to a Salesforce VisualForce page with an EnhancedList. Here’s the workaround.

apex:page >
    script type="text/javascript">    
    function endsWith(str, suffix) {
        return str.indexOf(suffix, str.length - suffix.length) !== -1;
    }
    function setActions() {        
        Ext.ComponentMgr.all.each( function(item, index, length) {
            if(endsWith(item.id, "grid")) {        
                var store = item.store;                    
                item.store.each( function(record) {
                    record.set("ACTION_COLUMN", ["My Action"]);
                });
            }
        });
    }
    /script>
    apex:enhancedList type="Systems__c" height="300" oncomplete="setActions();" />
/apex:page>

Salesforce uses the Extjs framework (Sencha.com) to implement list views. All user interface components on an Extjs page are registered with a component manager. The code accesses the component manager, looks for a component whose id corresponds to a grid (our EnhancedList), and then changes the action items in the store associated with the grid.

Salesforce Group Tables with Conga Composer

For a recent client project working with the Salesforce.com platform I used Conga Composer to create custom quotes. The client is an engineering firm and one of the quotes required employee hours billed under dynamic categories. The quote needed each employee’s hours listed under the associated category.

Here’s how to create the quote.

1. Create a report table in Salesforce using the schema builder. Give the table 10 or so text columns, and an identifier column that will store the object id of the associated Salesforce Opportunity object (i.e. a key in normal database nomenclature).

2. Create a hours master-detail object in Salesforce using the schema builder. In my example each hours billed will be grouped by a project role and part.

3. Create an APEX trigger that will fill the report table each time an hours item is added to our opportunity. I keep my APEX logic code in individual classes with a single APEX trigger – this keeps everything clean and easy to debug if you have multiple APEX triggers that are order dependent.

Continue reading

Salesforce Custom Hours Billed Quote with Conga Composer

For a recent client project working with the Salesforce.com platform I used Conga Composer to create custom quotes. The client is an engineering firm and one of the quotes required employee hours billed under dynamic categories. The quote needed each employee’s hours listed under the associated category.

Here’s how to create the quote.

Continue reading

Salesforce.com Data Download via Java Swing, RSSBus JDBC Driver, and Apache Commons Daemon

I recently developed an application that synchronizes Salesforce.com data to a local PC. The application is developed in Java using the Swing graphical framework and uses a Salesforce.com JDBC driver provided by RSSBus. The application stores Salesforce.com credentials and synchronization interval timing data in a Java properties file. The application allows non-graphical execution via the “nogui” command argument. I also include an Apache Commons Daemon class and script that allows running the application as a service.

Continue reading

Salesforce Trigger To Add Contacts From Account Linked to Opportunity

I couldn’t find any example code on the Net to accomplish a task that is probably common amongst many Salesforce implementations. I have a requirement to link a second account to an opportunity in Salesforce. In my use case, the primary opportunity account represents a construction project general contractor, and the second linked account represents the building owner. I need to automatically pull the building owner account contacts into the opportunity contact roles list. Here’s the Salesforce Trigger to do just that:

Continue reading