Monday, November 20, 2017

ScoreIntelligence object

This is the core object for the Einstein Lead Score feature, which one would need when programming trigger off (or for) it.  However I couldn't find official documentation on it (other than mentions in Release Notes).  It's not in the SOAP API Developer Guide, which is usually the (authoritative) place for standard object reference.  It does have ScratchOrgInfo, which belongs to Salesforce DX, a feature came out as GA in the same (or later) release (Summer '17) as Sales Cloud Einstein.  In terms of being "API first", that's strike one for Einsten.  Just saying...

So here's what I can glean from standard describe in Apex.

API NameLabel
ObjectScoreIntelligenceScore Intelligence
Field 1IdScore Intelligence Id
Field 2BaseIdLead Id
Field 3ScoreEinstein Score
All look pretty self-explanatory.  The interesting thing is that from the BaseId field, it looks like the object is a child object of Lead's, but through Apex/Process/SOQL the score can also be accessed as ScoreIntelligence.Score from the Lead object - something I know to be true (as we use it that way) but again cannot point to documentation - which means it's also a parent object of Lead's. 

Appendix: Apex script if you want to see the raw output.
        Schema.DescribeSObjectResult result = ScoreIntelligence.sObjectType.getDescribe();



        for (String s : result.fields.getMap().keyset()) {


Monday, May 15, 2017

Can't login after upgrading to Ubuntu 16.04

After entering password and pressing Enter, the screen just briefly flashed dark then back to the login screen.  Same went for Guest Session.  Looks like the desktop session is unable to start (or crashes when starting).  The system was upgraded from 14.04 and runs inside Virtualbox.

Following advice by Nuno here, I uninstalled nvidia driver and things are back to normal.  I had to drop into root shell at boot to do it though.
apt-get purge nvidia*

Friday, March 24, 2017

Dependencies for Dwarf Fortress

My son was trying to get Dwarf Fortress going on Ubuntu Precise running in Crouton on a Toshiba Chromebook.  Of course that's complicated - but it's not something you assess before starting when you're 12.  So here's some notes for resolving some dependencies for the wonderful little game.

Ubuntu's repo doesn't have it (for Precise anyway).  Add Xbmc PPA first.
sudo apt-add-repository ppa:team-xbmc/ppa 
sudo apt-get update
sudo apt-get install libsdl2
Once Xbmc PPA is there, it's as easy as adding
sudo apt-get install libsdl-image1.2

Monday, December 19, 2016

Thumbs Up/Down ("Solution Helpfulness Rating") Feature for Knowledge with Visualforce/Apex

This is a feature that came out without too much fanfare and was supposedly meant to address an idea.  The only place that mentioned how to use it in Salesforce with details was in Summer '15 Release Notes, when it came out as beta.  Then there's an article about using it with Community templates, in which it's referred as "Article Voting".  None of them gives any clue on how it can be used in a Sites based Public Knowledge Base, which happens to be the use case I need to handle. 

After some back and forth with Salesforce Support, they pointed me to this Developer Forum thread that talks about Vote object for Idea.  I did some simple code to verify, and I could indeed set parentId to __ka objects and programmatically manipulate up/down vote state.  That, was not mentioned at all in the official doc for the Vote object (as of Dec 2016, ver. 38.0).

With almost all the pieces in place, one hurdle remains for to a public KB Up/Down vote solution in VF/Apex, if the KB is used in an unauthenticated context.  Vote object doesn't allow vote on the same parentId more than once by the same user.  If the users are unauthenticated - basically always Public Site Guest User - then votes can't really be recorded for more than once.  That's hardly useful.  I have no workaround so far, other than building a custom solution without using Vote.  That would suck if you'd really want internal and external votes are counted and reported together.

Tuesday, April 5, 2016

Use Apex @InvocableMethod with Process Builder

It's one great way to marry the versatility of Apex to implement complex logic and the easy administration of Processes.  Say you want to auto-unfollow old Contracts a period of time after they're terminated for those who manage a lot of contracts.  It's pretty straightforward to do the unfollowing in Apex, then use Process to invoke the action and leave it to the administrators to control how long the wait period should be.  Bob Buzzard has a good piece on the general pattern, and info about @InvocableMethod can be found here.

The only thing I found a bit non-intuitive is how parameter is passed to the Invocable Method, which only takes List of arguments.  Process Builder, on the other hand, doesn't have an obvious way to create an array/list variable.  It turns out that all you need is to set a single value of the correct type (of the List element).  For instance if the method expects a list of IDs, just set a single ID, which is called reference in Process Builder.

"scids" is the argument expected by the Apex method.

    @InvocableMethod(label='Chatter unsub for Service Contracts' description='Unfollow terminated/cancelled service contracts for PMM team')
    public static List UnfollowSCs(List scIds) {

Monday, February 29, 2016

Apex code example for Kayako signature

Was looking at Kayako's API documentation - don't ask me why - and noticed there's no Apex example for their API request signature scheme (why would they?), so this might be useful for people who's in the same situation as I'm.

public class KayakoAPI {

    public static string getSignature(string secretKey) {
        string signature;

        if (secretKey!=null && secretKey.length()>0) {
            Blob salt = crypto.generateAesKey(128);  //can use other ways for random string generation

            // keyed hash
            Blob hmacsha256 = crypto.generateMac('HmacSHA256', salt, Blob.valueOf(secretKey));

            // Base64 and URL encoding
            signature = EncodingUtil.urlEncode(EncodingUtil.base64Encode(hmacsha256), 'UTF-8');

        return signature;

Wednesday, November 11, 2015

Salesforce AJAX Toolkit update call fails *silently* with field access issue

Some simple button code with Salesforce Ajax Toolkit (connection.js) to send a lead to queue (and related assignment logic in Apex):

var updateRecord = new Array();
var myquery = "SELECT Id, CompleteOwner__c FROM Lead WHERE Id = '{!Lead.Id}' limit 1";

var result = sforce.connection.query(myquery);
var records = result.getArray("records");

if (records[0] && (records[0].CompleteOwner__c === undefined || records[0].CompleteOwner__c === null)) {
    var update_lead = records[0];

        update_lead.OwnerId = "{!$Setup.CompleteQId__c.Id__c}"; /* To complete Q */

        var callback = {onSuccess: updated, onFailure: failed}
        sforce.connection.update(updateRecord, callback);
The trouble is, the update call returned successfully, but update didn't happen at all - I couldn't even capture the API call with a debug log.

It turns out the trouble is the CompleteOwner__c field.  If that's taken out, the code works fine.  The user has no write permission to the field, but, the code isn't updating it either.  Apparently merely having that field member in the record data structure prevents the update from taking place, without any failure message.  Changing the highlighted part to this, which uses an new object for update without that field member, fixed the problem.
var update_lead = new sforce.SObject("Lead"); //can't use query result for update = "{!Lead.Id}";

update_lead.OwnerId = "{!$Setup.CompleteQId__c.Id__c}"; /* To complete Q */
 The frustrating part is the silent failure.  Why not just fail the call when there's a non-writeable (by permission) field?