I have a field that's called AccountName and it's a LookUp field. When i try to update it with plain text, i get an error:

id value of incorrect type, errorCode:MALFORMED_ID

How can i upsert a LookUp field?


I just send a request to the REST API (using patch) with a JSON object with the following field: AccoutName: "someName"

  • can you add your code here Jan 19 '18 at 15:03
  • Done. Nothing out of the ordinary - the normal request with a JSON object. Jan 19 '18 at 15:08

Since it is a lookup field so you need to pass the AccountId instead of name.

AccoutName: "001........."

Update based on comments

Upsert works based on Id value.

If you need to check if Account with name already exists then you have to write a separate logic to find the accounts and then pass those accountId.

SOQL logic will be like this:

FROM Account
WHERE Name =:<AccountName>
  • Got it, but what if i want to do an upsert by AccountName? What if i want to say "if an account with this name doesn't exist, create it. if it does, do nothing" Jan 19 '18 at 15:16
  • Ok thanks for your answer! Can a LookUp field be an external ID? Because i know you could do upsert that way too right? Jan 19 '18 at 15:33
  • External Id cannot be a lookup field Jan 19 '18 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.