Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwing a SaveException does not allow access to success results #22

Open
oniric85 opened this issue Jun 12, 2015 · 1 comment
Open

Comments

@oniric85
Copy link

The method Client::checkResults checks the array of results returned by the Salesforce APIs and throws a SaveException when at least one of the results is not a Success. However in a catch block one can only retrieve from the exception the results that were indeed a failure but there is no way to handle those that weren't. Wouldn't it better if the SaveException had a way to get all the results of a call?

I'm not sure what's the best way here, I can only think of adding all the results in the exception no matter what (the error message of the exception is still only bound to those results that has an error).

@rmnanney
Copy link

rmnanney commented Mar 21, 2017

We are unfortunately using this (apparently dead) library. To fix this we are commenting out the block that throws the exceptions. We will as you expect, iterate the results and deal with success/failure from there. Throwing an exception here seems silly.

I'd do a pull request for this but there are three open PR's going back as far as 2013...

Hopefully this helps someone else out in the future!

`protected function checkResult(array $results, array $params)
{
$exceptions = new Exception\SaveException();

    for ($i = 0; $i < count($results); $i++) {

        // If the param was an (s)object, set it’s Id field
        if (is_object($params[$i])
            && (!isset($params[$i]->Id) || null === $params[$i]->Id)
            && $results[$i] instanceof Result\SaveResult) {
            $params[$i]->Id = $results[$i]->getId();
        }

        if (!$results[$i]->isSuccess()) {
            $results[$i]->setParam($params[$i]);
            $exceptions->add($results[$i]);
        }
    }

    //if ($exceptions->count() > 0) {
    //    throw $exceptions;
    //}

    return $results;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants