Trouble with a Object Sync for Salesforce hook on Sage 9

Hello,

I’m working with Object Sync for Salesforce plugin with my Sage 9 instance and I’m attempting to utilize this hook:

function find_sf_object_match( $salesforce_id, $wordpress_object, $mapping = array(), $action ) {
    if ( $action === 'push' && $mapping['wordpress_object'] === 'user' ) {
        if ( is_object( $this->salesforce ) ) {
            $salesforce_api = $this->salesforce->salesforce['sfapi'];
        } else {
            $salesforce = $this->salesforce();
            $salesforce_api = $salesforce->salesforce['sfapi'];
        }

        if ( is_object( $salesforce_api ) ) {

            // we want to see if the user's email address exists as a primary on any contact and use that contact if so
            $mail = $wordpress_object['user_email'];
            $query = "SELECT Primary_Contact__c FROM Email__c WHERE Email_Address__c = '$mail'";
            $result = $salesforce_api->query( $query );

            if ( $result['data']['totalSize'] === 1 ) {
                $salesforce_id = $result['data']['records'][0]['Primary_Contact__c'];
            }
        }
    }

    return $salesforce_id;
}
add_filter( 'object_sync_for_salesforce_find_sf_object_match', 'find_sf_object_match', 10, 4 );

This currently results in the following error:

**Fatal error** : Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Illuminate\View\Engines\CompilerEngine::salesforce()

I assume this is some sort of namespace issue, can anyone shed some light on how I might resolve this?

Many thanks,
Dan

Where is this code in your theme?

You’re referencing $this a number of times (i.e. $salesforce_api = $this->salesforce->salesforce['sfapi'];) but this code doesn’t indicate what context you’re doing that in. It looks like you’re just running it as a normal function, not as a method on an object. Based on the error, it looks like that’s what you’re doing, and PHP has decided that in that context $this resolves to the instance of CompilerEngine that’s rendering your blades. It tries to called salesforce on CompilerEngine which obviously doesn’t exist so it throws that error. If that is the problem, then you probably need to be running this in a object context, or you need to redefine $this as an instance of whatever Class provides that functionality (by which I mean a) use a different variable name and b) instantiate a class into that variable).

Thanks for the insightful response @alwaysblank, very much appreciated.

Replacing:

if ( is_object( $this->salesforce ) ) {
    $salesforce_api = $this->salesforce->salesforce['sfapi'];
} else {
    $salesforce = $this->salesforce();
    $salesforce_api = $salesforce->salesforce['sfapi'];
}

with the following did the trick:

$salesforce = Object_Sync_Salesforce::get_instance();
$salesforce_api = $salesforce->salesforce['sfapi']; 

Cheers! :beers:

-Dan

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.