Abort model's query only if all conditions have no rows in source model
Objective: I'd like to use a single table within a single page include that,
1) Account model
Changing the "novaluebehavior” of the conditions on the Opportunity model from “deactivate” to “noquery” doesn’t work either because the query gets aborted if one of the first two models doesn’t have rows, which will always be the case.
XML:
<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
<models>
<model id="Account" limit="1" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Account">
<fields>
<field id="Id"/>
<field id="Name"/>
</fields>
<conditions>
<condition type="param" value="AccountId" field="Id" operator="=" enclosevalueinquotes="true" novaluebehavior="noquery"/>
</conditions>
<actions/>
</model>
<model id="OpportunityContactRoles" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="OpportunityContactRole">
<fields>
<field id="ContactId"/>
<field id="Contact.Name"/>
<field id="OpportunityId"/>
<field id="Opportunity.Name"/>
</fields>
<conditions>
<condition type="param" value="ContactId" field="ContactId" fieldtargetobjects="Contact" operator="=" mergefield="Id" novaluebehavior="noquery" enclosevalueinquotes="true"/>
</conditions>
<actions/>
</model>
<model id="Opportunities" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Opportunity">
<fields>
<field id="AccountId"/>
<field id="Account.Name"/>
<field id="Id"/>
<field id="Name"/>
</fields>
<conditions logic="1 OR 2">
<condition type="modelmerge" value="" field="AccountId" fieldtargetobjects="Account" operator="=" novaluebehavior="deactivate" model="Account" enclosevalueinquotes="true" mergefield="Id" state=""/>
<condition type="modelmerge" value="" field="Id" operator="in" model="OpportunityContactRoles" enclosevalueinquotes="true" mergefield="OpportunityId" novaluebehavior="deactivate" state="" fieldtargetobjects="Opportunity"/>
</conditions>
<actions/>
</model>
</models>
<components>
<skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="Account" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JToFP-649">
<fields>
<field id="Id" hideable="true" uniqueid="fi-1JTyCd-752"/>
<field id="Name" hideable="true" uniqueid="fi-1JTyCd-753"/>
</fields>
<rowactions/>
<massactions usefirstitemasdefault="true"/>
<views>
<view type="standard"/>
</views>
</skootable>
<skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="OpportunityContactRoles" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JTpys-663">
<fields>
<field id="ContactId" hideable="true" uniqueid="fi-1JTztw-762"/>
<field id="OpportunityId" hideable="true" uniqueid="fi-1JTztw-763"/>
</fields>
<rowactions/>
<massactions usefirstitemasdefault="true"/>
<views>
<view type="standard"/>
</views>
</skootable>
<skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="Opportunities" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JTr2b-677">
<fields>
<field id="Id" hideable="true" uniqueid="fi-1JU0Bn-774" valuehalign="" type=""/>
<field id="AccountId" hideable="true" uniqueid="fi-1JU0Bm-772"/>
<field id="Name" hideable="true" uniqueid="fi-1JU0Bn-773"/>
</fields>
<rowactions/>
<massactions usefirstitemasdefault="true"/>
<views>
<view type="standard"/>
</views>
</skootable>
</components>
<resources>
<labels/>
<javascript/>
<css/>
</resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>
- Returns the opportunities for a given account when passed an account Id
- Returns the opportunities for a given contact when passed a contact Id (via OpportunityContactRole)
1) Account model
- Condition: Id = AccountId URL param (novaluebehavior=“noquery")
- Condition: Id = ContactId URL param (novaluebehavior=“noquery")
- Condition logic: 1 OR 2
- Condition 1: AccountId = Id from the Account model (novaluebehavior=“deactivate")
- Condition 2: Id is in the set of OpportunityId values from the OpportunityContactRoles model (novaluebehavior=“deactivate")
Changing the "novaluebehavior” of the conditions on the Opportunity model from “deactivate” to “noquery” doesn’t work either because the query gets aborted if one of the first two models doesn’t have rows, which will always be the case.
XML:
<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
<models>
<model id="Account" limit="1" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Account">
<fields>
<field id="Id"/>
<field id="Name"/>
</fields>
<conditions>
<condition type="param" value="AccountId" field="Id" operator="=" enclosevalueinquotes="true" novaluebehavior="noquery"/>
</conditions>
<actions/>
</model>
<model id="OpportunityContactRoles" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="OpportunityContactRole">
<fields>
<field id="ContactId"/>
<field id="Contact.Name"/>
<field id="OpportunityId"/>
<field id="Opportunity.Name"/>
</fields>
<conditions>
<condition type="param" value="ContactId" field="ContactId" fieldtargetobjects="Contact" operator="=" mergefield="Id" novaluebehavior="noquery" enclosevalueinquotes="true"/>
</conditions>
<actions/>
</model>
<model id="Opportunities" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Opportunity">
<fields>
<field id="AccountId"/>
<field id="Account.Name"/>
<field id="Id"/>
<field id="Name"/>
</fields>
<conditions logic="1 OR 2">
<condition type="modelmerge" value="" field="AccountId" fieldtargetobjects="Account" operator="=" novaluebehavior="deactivate" model="Account" enclosevalueinquotes="true" mergefield="Id" state=""/>
<condition type="modelmerge" value="" field="Id" operator="in" model="OpportunityContactRoles" enclosevalueinquotes="true" mergefield="OpportunityId" novaluebehavior="deactivate" state="" fieldtargetobjects="Opportunity"/>
</conditions>
<actions/>
</model>
</models>
<components>
<skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="Account" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JToFP-649">
<fields>
<field id="Id" hideable="true" uniqueid="fi-1JTyCd-752"/>
<field id="Name" hideable="true" uniqueid="fi-1JTyCd-753"/>
</fields>
<rowactions/>
<massactions usefirstitemasdefault="true"/>
<views>
<view type="standard"/>
</views>
</skootable>
<skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="OpportunityContactRoles" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JTpys-663">
<fields>
<field id="ContactId" hideable="true" uniqueid="fi-1JTztw-762"/>
<field id="OpportunityId" hideable="true" uniqueid="fi-1JTztw-763"/>
</fields>
<rowactions/>
<massactions usefirstitemasdefault="true"/>
<views>
<view type="standard"/>
</views>
</skootable>
<skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="Opportunities" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JTr2b-677">
<fields>
<field id="Id" hideable="true" uniqueid="fi-1JU0Bn-774" valuehalign="" type=""/>
<field id="AccountId" hideable="true" uniqueid="fi-1JU0Bm-772"/>
<field id="Name" hideable="true" uniqueid="fi-1JU0Bn-773"/>
</fields>
<rowactions/>
<massactions usefirstitemasdefault="true"/>
<views>
<view type="standard"/>
</views>
</skootable>
</components>
<resources>
<labels/>
<javascript/>
<css/>
</resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>
Tagged:
2
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
I also don't think that would solve for scenario I described above (i.e. I'd still get a random list of opps).
I think you are going to need to add an 'Inline' snippet to determine when to load the Opportunity model. I don't think there is a declarative solution for this.
Thanks,
Bill
What do you want to happen? Do you want the table to show as blank? Do you want anything else to show instead? You could add rendering conditions on the table to hide it if both the oppcontact model and the account model don't have data rows. That may not be ideal depending on your use case, but at least your users wouldn't see a table of random opportunities. Another option would be to have two opportunity models on the page and two tables, one for each condition. You could render the proper one based on which model has data rows
My assumption is that even if I did hide the table when the other models don't have rows, the query for the table is still executed, which would impact performance.
Having multiple models and tables for the different scenarios is an option I've considered, but I'm attempting to reduce redundancies wherever I can so that my pages load faster and they're easier to maintain.
This will get you started. It needs to be 'Inline' JavaScript so that it runs on page load. Thanks,
Bill