PHP code example of flinty916 / laravel-salesforce

1. Go to this page and download the library: Download flinty916/laravel-salesforce library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flinty916 / laravel-salesforce example snippets


$contact = Contact::create([
    'Name' => 'Test Contact'
]); // $contact will be type Contact, with the Id field populated only.

Contact::fields(['Id', 'Email', 'Name__c',]) // Use fields() to specify limited field sets for queries
    ->where('Email', 'LIKE', 'maurice%')
    ->orWhere('Id', '=', '003D000002TND2QIAX')
    ->all() // Fetches ALL records, 

Contact::fields(['Id', 'Email', 'Name__c',]) // Use fields() to specify limited field sets for queries
    ->where('Email', 'LIKE', 'maurice%')
    ->orWhere('Id', '=', '003D000002TND2QIAX')
    ->limit(20) // Set a hard limit. orderBy methods available as well.
    ->get() // Fetches without handling pages.
    ->records() // Returns collection of Contact;

Contact::find('MyId'); // Returns an instance of Contact, runs FIELDS(ALL) behind the scenes.

$contact = Contact::find('MyId');
$contact->update([
    'Name__c' => 'New Name'
]); // Returns no new data. Suggest a refetch/find operation afterwards to update state.

$contact = Contact::find('MyId');
$contact->delete(); // Returns null

$description = Contact::describe(); // Returns SalesforceDescription
$myPicklistValues = $description->fields->where('name', 'myField')->first()->picklistValues; // returns Collection of SalesforcePicklistValue

$opportunity = Opportunity::find('0068d00000ABC123');

$feed = $opportunity->chatter()->all();

// Returns a collection of feed elements (posts, comments, files, etc.)
foreach ($feed as $element) {
    echo $element['actor']['displayName'] . ': ' . $element['body']['text'];
}

$opportunity->chatter()->post('We should increase the deal size to £200k.');

$opportunity->chatter()->update('0D5xx00000ABCDe', 'Updated deal size to £250k.');

$opportunity->chatter()->comment('0D5xx00000ABCDe', 'Agreed — let’s go for it.');

$opportunity = Opportunity::find('0068d00000ABC123');

// Post a message
$post = $opportunity->chatter()->post('Initial quote sent to client.');

// Add a follow-up comment
$opportunity->chatter()->comment($post['id'], 'Client requested updated pricing.');

// Retrieve all feed items
$feed = $opportunity->chatter()->all();
bash
php artisan salesforce:generate-objects
bash
php artisan salesforce:generate-objects --objects=Account,Contact,Opportunity