Conditional Custom Object, Lookup a Row or Create new Row

edited March 2, 2017 in Questions
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 page. 


  • Karen WaldschmittKaren Waldschmitt 🛠️ 
    edited March 2, 2017

    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!
  • Barry SchnellBarry Schnell 💎💎
    edited February 25, 2017

    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!

    <skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true" tabtooverride="Account">
            <model id="Account" limit="1" query="true" createrowifnonefound="false" adapter="salesforce" service="salesforce" sobject="Account">
                    <field id="Name"/>
                    <field id="CreatedDate"/>
                    <condition type="param" enclosevalueinquotes="true" operator="=" field="Id" value="id"/>
            <model id="Contact" limit="20" query="true" createrowifnonefound="true" adapter="salesforce" type="" sobject="Contact">
                    <field id="Name"/>
                    <field id="FirstName"/>
                    <field id="LastName"/>
                    <condition type="modelmerge" value="" field="AccountId" operator="=" model="Account" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery" state=""/>
            <pagetitle model="Account" uniqueid="sk-1FwzjQ-76">
                    <action type="savecancel" window="self">
            <basicfieldeditor showsavecancel="false" showheader="true" model="Account" mode="read" uniqueid="sk-1FwzjR-77">
                    <column width="50%">
                            <section title="Basics">
                                    <field id="Name"/>
                    <column width="50%">
                            <section title="System Info">
                                    <field id="CreatedDate"/>
            <skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="false" showexportbuttons="false" pagesize="10" createrecords="true" model="Contact" buttonposition="" mode="edit" uniqueid="sk-1Fxp6l-122" emptysearchbehavior="query">
                    <field id="FirstName" valuehalign="" type=""/>
                    <field id="LastName" valuehalign="" type=""/>
                    <action type="edit"/>
                    <action type="delete"/>
                <massactions usefirstitemasdefault="true">
                    <action type="massupdate"/>
                    <action type="massdelete"/>
                    <view type="standard"/>
            <styleitem type="background" bgtype="none"/>

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!