Conditional Custom Object, Lookup a Row or Create new Row

I’m looking to find out how to do my conditions(i think) I have two models 1 is standard Opportunities  and other is a custom object, i’m am displaying data from the Opportunities and by default I am creating a new record for my custom object when saving data. What I am looking/wanting to do is by default with my custom object created a new record BUT if there is a related record that matches the Opportunity then display that row from the custom object with the data contained. Does this make since? FYI is the public force.com page. 

Brandon~

If I understand correctly, you will need 3 models: 1 for the opportunity object and 2 for the custom object.

  • One of the custom object model will show the related record, if there is any. You will need a condition on that model where the opportunity ID equals the opportunity ID from the opportunity model
  • The second custom object model will be to create a new record. 
You would then use conditional rendering to display and hide the appropriate parts of the page.

Hope that helps!
Karen 

Hello Brandon -

Possibly Karen is misunderstanding or I am misunderstanding your situation but you should not need 3 models. Having 3 models for this situation (again, assuming I'm understanding correctly) would create several issues including the fact that you'd have to duplicate every component that uses your custom object with the only difference between each pair being the model used and then use conditional rendering to show an hide the correct one. This would create a maintenance nightmare especially if your component configurations are complex.

In order to accomplish what you are after, the key is using the "Field form Another model" condition and also the "load model data" and "create default row if none" for the custom object model.

Here's a breakdown:

1) Create Opportunity Model as normal 2) Create Custom Object Model applying the following a) Properties Load Model data on page load: true Create default row if Model has none: true b) Conditions FIeld: OpportunityId (or whichever field in your custom object associates it to the Opportunity) Operator: = Value: Field from another model, using Source model of Account, Source Field of Id State: Always On

You did mention that you create the row when you save so if that is the case, things get a little more tricky as you need to use the action framework. Even in this situation, however, the model configuration would be similar, you just wouldn't want "load model data" and instead, in the action framework, you would query the custom object model first, then do the rest of the steps (e.g. set field values, save, etc.)

Here's a sample page that uses Account and Contact replacing your Custom Object for Contact but the process is identical. If you preview this page with an Account that has Contacts, you will see them table on the page. If you preview this page for an account that has no contacts, a new record will automatically be created and you will see that on the page in the table.

Hope this helps!

``` {{Name}} {{Model.label}} Contact ```