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

Trouble saving an Object due to Security Settings on unrelated fields #29

Open
nickturrietta opened this issue Oct 10, 2019 · 6 comments

Comments

@nickturrietta
Copy link
Contributor

Thanks for the great package! One issue I ran into and possible solution.

I tried to update the Description field on a Case object.

I received this error message.
Salesforce response error: Client error: ``PATCH https://******.my.salesforce.com/services/data/v47.0/sobjects/Case/5006C000004ZWUGQA4`` resulted in a ``400 Bad Request`` response: [{"message":"Unable to create/update fields: LastModifiedDate, CreatedDate, ContactEmail. Please check the security settings...

The culprit was that I had specified LastModifiedDate, CreatedDate, and ContactEmail in the $columns property on the Case model.

Even though I did not actively try to modify these properties, it looks they are still being passed to Salesforce as part of the patch request.

I'm not an expert but I think you can replace these 2 lines in Model.php:76

$body = $this->attributes;
unset($body['attributes'], $body['Id']);

with this line in the patch request (to only include the fields that have changed)

$body = $this->getDirty();

Thanks again! This package is helping us a lot.

@roblesterjr04
Copy link
Owner

Sorry for the late reply!!! This should be fixed on the latest release, i encountered it myself last week.

Please upgrade to ^2.3

Thanks!!!!

@nickturrietta
Copy link
Contributor Author

Hey Rob. I'm on v2.5. This is still an issue it seems. I'm trying to change a single field on an object, but the PATCH request is acting like a PUT request and is trying to change a bunch of unrelated fields on the object.

This would be the quick fix as far as I can see...

Change:

public function writeableAttributes($exclude = [])
{
    $fields = array_merge($this->readonly, $exclude);
    return Arr::except($this->attributes, $fields);
}

To:

public function writeableAttributes($exclude = [])
{
    $fields = array_merge($this->readonly, $exclude);
    return Arr::except($this->getDirty(), $fields);
}

For what it's worth.

@roblesterjr04
Copy link
Owner

I’ll take a look and try these suggestions next week. Thank you for raising.

@roblesterjr04 roblesterjr04 reopened this Dec 6, 2019
@roblesterjr04
Copy link
Owner

Hmm, when I do that, it causes problems for the mass update method. I will need to be thoughtful about how to implement this.

@nickturrietta
Copy link
Contributor Author

Aw copy that. I hadn't tested with mass updates. Interesting that it would have an effect on it actually. All good.

@RipleWare
Copy link

Hi there, just wondering if this was ever resolved, as I have now encountered this issue once introducing LastModified into my model.

This package is working very well for me, however, I now need to get around this issue if I can.
Thanks.

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

3 participants