PHP code example of php-arsenal / salesforce-mapper-bundle

1. Go to this page and download the library: Download php-arsenal/salesforce-mapper-bundle 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/ */

    

php-arsenal / salesforce-mapper-bundle example snippets




use PhpArsenal\SalesforceMapperBundle\Mapper;
use PhpArsenal\SalesforceMapperBundle\Model\Opportunity;

class MyService {
    private $mapper;
    
    public function __construct(Mapper $mapper) {
      $fetchedObjects = $mapper->findBy(new Opportunity(), [
          'Name'  => 'Just an opportunity',
      ]);
    }
}

...
$opportunity = $fetchedObjects[0];
echo 'The opportunity belongs to: ' . $opportunity->getAccount()->getName();
...

...
$fetchedObjects = $mapper->findAll(Opportunity::class);
...

...
$opportunity = new Opportunity();
$opportunity->setName('Some name');
echo $opportunity->getId(); // Returns null

$mapper->save($account);
echo $account->getId(); // Returns the new ID, e.g. `001D000000h0Jod`
...

...
use PhpArsenal\SalesforceMapperBundle\Annotation as Salesforce;
...
    /**
     * @var string
     * @Salesforce\Field(name="AccountId")
     */
    protected $accountId;
...