Monday, May 18, 2015

Forecasting Quota and Risk of Salesforce Upgrade


Problem

This is a bit of old problem, but we had this custom Visualforce interface in our internal org that allows you to mass insert and edit Forecast Quota.  This has been working fine for years, but when we tried to enter forecast for this year, we suddenly got this error:

Missing Required Field: [Quota Quantity]
However, when we tried to modify the code to allow manual entering of quota, we were getting error indicating that this field is not writable.


Solution

What turned out happen was that you need to have ForecastingType set if you are using ForecastingQuota inside of code after API v28.  Once we enabled a revenue forecast on opportunity (Setup > Customize > Forecasts > Setting), the interface worked again.

Takeaway

This was another lesson on using custom code with Salesforce (especially something that interacts with Standard feature, such as Standard object) and Salesforce upgrade.  Writing custom code can certainly improve the usability of Salesforce, and I do believe it to be one of major feature of Salesforce, but one has to be mindful that it can suddenly get broken without warning.  This is one of the reason why Salesforce recommends using as much of standard functionality as possible (70 to 80% standard functionality is the Salesforce benchmark).

Strange error when saving from Developer Console

This post is more of a reference for future if I encounter this error again, but I had a rather strange error when trying to save a modification to a Apex class from Developer Console:

Failed to create createContainerMember for containerId=undefined: null is not a valid containerId
After some googling, I had found following help article indicating that you need to create a new workspace when this error appears.  This did fix my error, but it doesn't really explain why this error appears.  If you have more in-depth explanation as to why this would happen, let me know.

Taking control of Custom Action in Salesforce1

I have been involved with a few projects that incorporated Visualforce pages into Salesforce1's custom action since the launch of Salesforce1, and one thing I had found annoying was that there was no documentation on how one can take over the action associated with "Submit" and "Cancel" button on top of the custom action page.



However, Salesforce has recently updated their documentations on how you can add your own action to these two buttons using Publisher SDK.  I first saw this on Visualforce Mobile Trailhead, but they have updated Salesforce1 Mobile App Developer Guide to include it as well.

To add your own Javascript action to the "Save" button, you would first include Publisher SDK:


<!-- Publisher SDK -->

<script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script>

Then, you would modify following Javascript function inside your Visualforce page.

// When the panel is displayed, enable the submit button
Sfdc.canvas.publisher.subscribe({name: "publisher.showPanel", onData:function(e) {
    Sfdc.canvas.publisher.publish(
        {name: "publisher.setValidForSubmit", payload: "true"});
}});

// Action to be performed when submit button is pressed
Sfdc.canvas.publisher.subscribe({ name: "publisher.post", onData: function(e) {

    // ***************************************************
    // Add your own action here
    /* myOwnAction([params], 
          // Callback
          function(error, records) {
             if (error) {
               // Do something on error
             }
             else {
               // Close the window
               Sfdc.canvas.publisher.publish(
                { name: "publisher.close", payload:{refresh:"true"}});
             }
       }); */
}});

Tabs and Searching

As you gain more experience with Salesforce, you come to run into limits that make you think "why did they put that limit?"  One of such feature is searching custom object.  Over a year ago, we had a project with a customer who had quite a few custom objects in its org and had used up all their tabs.   One of the requirements for the project is to enable the search on a new custom object, but when we have set all the search layout, we weren't seeing the object in the search.  After some googling, we found out that you can search a custom object only if you have custom tab associated with it.  When we had contacted Salesforce support, we found out that you could purchase additional tabs just so that you can enable additional searching.  Also, you could implement your own Visualforce searching page, but I still find this to be rather strange limitation.