Updating related objects with existing model?

  • 1
  • Question
  • Updated 2 years ago
  • In Progress
  • (Edited)
We have a junction object called OpportunityAccounts that is a many-to-many relationship between an Account and Opportunity. We have a table of these objects that includes a custom mass action snippet, that I'm using to update a field called "PrimaryAddress__c" on the Account.

However, can't figure out save my Account objects with the OpportunityAccountModel:
var addressId = getAddressId();
var selectedItems = arguments[0].list.getSelectedItems();
var model = arguments[0].model;
var rowsToUpdate = {};
selectedItems.map(function(item) {
    rowsToUpdate[item.row.Account__c] = { PrimaryAddress__c: addressId };
});
model.updateRows(rowsToUpdate);
model.save();
After saving the model, the accounts are not updated. I'm guessing this is because the model is referencing the junction object (OpportunityAccount).

So what do I need to do to update these records? I tried initializing a new model as well as creating a dummy one through the UI. Neither option worked for me.

Kinda at a loss for what else to try, anyone have a solution?
Photo of Matt Mitchener

Matt Mitchener

  • 150 Points 100 badge 2x thumb
  • confused

Posted 2 years ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Matt,

I think you are trying to update the Account using the OpportunityAccount object.  This is not supported.

You would need to load another model on Account using the Account Ids from OpportunityAccount and update this model using your script.

Does that make sense?

Thanks,

Bill