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

Updating a record throws an exception #86

Open
stzahi opened this issue Jun 27, 2022 · 4 comments
Open

Updating a record throws an exception #86

stzahi opened this issue Jun 27, 2022 · 4 comments

Comments

@stzahi
Copy link

stzahi commented Jun 27, 2022

Using
Elsf v2.14.4
Forrest v2.14.1
~
Running from within a command, that's why the trace is short.

Omniphx\Forrest\Exceptions\SalesforceException 

  [
    {
        "errorCode": "METHOD_NOT_ALLOWED",
        "message": "HTTP Method 'PATCH' not allowed. Allowed are HEAD,GET,POST"
    }
]

at vendor/omniphx/forrest/src/Omniphx/Forrest/Client.php:857
    853▕         } elseif ($ex->hasResponse()) {
    854▕             $error = json_decode($ex->getResponse()->getBody()->getContents(), true);
    855▕             $ex->getResponse()->getBody()->rewind();
    856▕             $jsonError = json_encode($error,JSON_PRETTY_PRINT);
  ➜ 857▕             throw new SalesforceException($jsonError, $ex);
    858▕         } else {
    859▕             throw new SalesforceException(sprintf('Invalid request: %s', $ex->getMessage()), $ex);
    860▕         }
    861▕     }

New project, new Salesforce, can't find out why 😩

Thanks a lot :)

@roblesterjr04
Copy link
Owner

Please provide the code you're trying to execute.

@IdrisN
Copy link

IdrisN commented Jan 5, 2023

I think i am experiencing a similar problem:

I want to update a record like this:

$account = Account::find('a017Q00001E2xxxxxx');

$account->update(['Description__c' => 'Hello World']);

but i get the following Error:

{
    "errorCode": "METHOD_NOT_ALLOWED",
    "message": "HTTP Method 'PATCH' not allowed. Allowed are HEAD,GET,POST"
}

The following Forrest method worked though:

Forrest::sobjects('Mandat__c/a017Q00001E2xxxxxx',[
    'method' => 'patch',
    'body'   => [
        'Description__c'  => 'Hello World',
    ]
]);

Any idea what the problem could be?

@stzahi
Copy link
Author

stzahi commented Jan 10, 2023

@IdrisN , for me it was not an update method, I've tried to UPSERT records.
My problem was I didn't define a $primaryKey variable in the model of the object I wanted to Upsert.
For you I can see that you're trying to update, so I guess it is a different problem, but maybe the direction I write here might be helpful for you.

Good luck.

@roblesterjr04
Copy link
Owner

@IdrisN could you provide the code for your Account model? Maybe in this instance, Id isn't getting returned automatically in the columns, and you might benefit by defining the $columns attribute on your model. Specifically making sure that the Id field is present. Example:

public $columns = [
        'Custom_Text_Field__c',
        'Email',
        'FirstName',
        'LastName',
        'Company',
        'Custom_Date_Field__c',
        'Id',
        'CreatedDate',
        'LastModifiedDate',
        'IsDeleted',
    ];

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