Error: Call to a member function id() on null in /ebsvol/www/savant/web/modules/contrib/salesforce/modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedIDs.php on line 75
I am syncing (one-direction) from Drupal into SalesForce a number of custom ECK entities. One is what we call a "load" and it references both a "spec" (through field_spec) and a room (through field_room). Both room and spec entities are also synced into SalesForce.
During salesforce_push cron run, I started getting this shortly after going live. What I'm seeing is that $field->getValue() (line 67) works and returns an array of one with a target_id set, so it's not blank. However, in the line 75 sub-call it's trying to do $field->entity->id() and $field->entity is null. However, field->target_id works... if we only need the id, should we be calling target_id directly instead? Or, is there some other reason entity doesn't work? I'm not sure what the right thing is here.

| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3007055-5-member_function_id.patch | 740 bytes | chrisfromredfin |
| Screen Shot 2018-10-16 at 9.28.09 AM.png | 389.02 KB | chrisfromredfin |
Comments
Comment #2
aaronbaumanif $field->entity->id() doesn't work but $field->target_id does, is it possible that the entity was deleted but the reference did not get updated?
either way, it's probably fine to switch to $field->getValue() - this is preferable over $field->target_id, since different implementations my not use the same property. do you want to roll that patch?
Comment #3
chrisfromredfinSo actually digging, the first scenario is actually what happened. How the reference wasn't updated, I'm not sure - may be a bug in ECK or perhaps it not something that happens when entities are deleted with the REST API or something?
Would you accept another patch where I check for a null $field->entity and return also in that case? Something like...
Comment #4
aaronbaumanYes, adding a type check is a good idea.
Comment #5
chrisfromredfinK let's see where this lands!
Comment #7
aaronbaumanLooks great - thanks for the patch