1

I'm running into an issue with modifying the default Social Customer Service apex class and would really appreciate some guidance. I'm not a developer so this requirement is probably really simple to achieve, however I've hit a dead end...

The default class provided by SF for inbound social posts to Salesforce is as follows:

global class MyInboundSocialPostHandlerImpl extends
Social.InboundSocialPostHandlerImpl implements Social.InboundSocialPostHandler {
    global override SObject createPersonaParent(SocialPersona persona) {
        String name = persona.Name;
        if (persona.RealName != null && String.isNotBlank(persona.RealName))
        name = persona.RealName;
        String firstName = '';
        String lastName = 'unknown';
        if (name != null && String.isNotBlank(name)) {
            firstName = name.substringBeforeLast(' ');
            lastName = name.substringAfterLast(' ');
            if (lastName == null || String.isBlank(lastName))
            lastName = firstName;
        }

        //You must have a default Person Account record type
        Account acct = new Account (LastName = lastName, FirstName = firstName);

        insert acct;
        return acct;
    }
    global override String getDefaultAccountId() {
    return '<account ID>';
    }

    global override Integer getMaxNumberOfDaysClosedToReopenCase() {
    return 5;
    }
}

...And instead of creating a new Person Account for each incoming social post/persona, I want to assign all Persona's to a default "shell" account record. Therefore I want to explicitly say in my class to find and use this shell account, every time.. I've tried a SOQL query to retrieve the shell account id, assigned it to a variable and attempted to use it in the following, but apparently I can't do this...

global override String getDefaultAccountId() {
    return '<acct.ID>';
    }

I've also tried hardcoding the ID just to test (I know it's a terrible way to handle this scenario), and that also gave me an error: invalid ID

Could anybody provide some insight on how to go about solving this?

Many Thanks!

1 Answer 1

0

I've figured it out doing a bit of playing around. If I query the existing account and update/return it accordingly, I can then return the relevant ID in getDefaultAccountID()

Hereby the final snippet in case someone wants to assign all incoming social personas/posts/cases to a single shell Account. The reason for wanting to do so is because the default class will spam empty, meaningless accounts based off First/Last name (as you don't yet know an email or any other useful unique identifier).

Success!

global class MyInboundSocialPostHandlerImpl extends
Social.InboundSocialPostHandlerImpl implements Social.InboundSocialPostHandler {
    global override SObject createPersonaParent(SocialPersona persona) {
        String name = persona.Name;
        if (persona.RealName != null && String.isNotBlank(persona.RealName))
        name = persona.RealName;
        String firstName = '';
        String lastName = 'unknown';
        if (name != null && String.isNotBlank(name)) {
            firstName = name.substringBeforeLast(' ');
            lastName = name.substringAfterLast(' ');
            if (lastName == null || String.isBlank(lastName))
            lastName = firstName;
        }

        Account acct = 
            [SELECT Id, Email FROM Account 
            WHERE Email='[email protected]'
            LIMIT 1];

            update acct; 
            return acct;

    }
    global override String getDefaultAccountId() {
    return '<account ID>';
    }

    global override Integer getMaxNumberOfDaysClosedToReopenCase() {
    return 5;
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .