1

I'm declaring the following in my Visualforce page:

<apex:remoteObjects>
    <apex:remoteObjectModel name="Contact" fields="FirstName,LastName,Id">
    </apex:remoteObjectModel>
</apex:remoteObjects>

I'm then attempting to create a simple contact record with the following:

const data = {
    FirstName: 'Clark',
    LastName: 'Kent'
};
console.log({ data });
const contact = new SObjectModel.Contact(
    data,
    (error, results, event) => {
        console.log({ error, results, event });
    }
);
contact.create();
console.log({ contact });

When I load the page, I see the output of the two console logs, with the properties correctly set on the contact object, but the callback function is never called and no record is created. No error occurs.

How can I use the remote object model to create contact (and later, other) records?

1 Answer 1

1

The record is being created, but your callback is in the wrong spot.

const data = {
  FirstName: "Clark",
  LastName: "Kent",
};
console.log({ data });
const contact = new SObjectModel.Contact(data);
// Callback goes here
contact.create((error, results, event) => {
  console.log({ error, results, event });
});
console.log({ contact });
2
  • 1
    I swear, @sfdcfox, sometimes I think you answer all of salesforce.stackexchange.com by yourself. :)
    – Chuck
    Commented Dec 12, 2023 at 21:17
  • @Chuck It seems like, doesn't it? I've answered ~10% of all network questions, so I have yet more ground to cover, lol.
    – sfdcfox
    Commented Dec 12, 2023 at 21:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .