I am working on a Lightning Component and I am trying to refactor my code. I have four combo boxes set up to query junction objects. The selection for object one determines what fills the list for Object Two, and two's selection determines what fills three, etc.
I currently have four versions of a method call used to make an SOQL query against three different custom junction objects. I would like to make it more generic and pass the customObject__c type as a parameter so I can use the same method, but tell it which object in the call, rather than hard code my query.
In my component I am using lightning combo boxes to display each list result:
<aura:attribute name="objOne" type="List" default="[]"/>
<lightning:combobox name="objOneSelect" label="Object One" placeholder="Select a Object" options="{! v.objOnes}" onchange="{! c.handleObjOne }"/>
and three more for objects 2 - 4.
In the controller I have a call to the helper:
handleObjOne: function (component, event, helper) {
var selectedOptionValue = event.getParam("value");
var params = ({mySelection : selectedOptionValue});
helper.callServer(component,
"c.getObjTwoList",
"v.objTwos",
params);
},
The helper uses the following:
callServer : function(component,method,attributeName,params) {
var action = component.get(method);
if (params) {
action.setParams(params);
}
action.setCallback(this,function(response){
var state = response.getState();
if (state === "SUCCESS") { "logic to fill value and label in option list"}
Currently, the call only takes the selectOptionValue and uses it in the query on my getList class. I can pass the necessary object__c and object___r info as strings then build a query string, but I am stuck at how to get the actual 'Type' passed. My query is:
List<objTwo__c> objectList = [SELECT Name FROM objTwo__c WHERE Id IN (SELECT objTwo__c FROM oneTwoJunction__c WHERE objOne__r.Name LIKE :mySelection)];
List<String> objTwoNames = new List<String>();
for(objTwo__c two : objectList ){
objTwoNames.add(two.Name);
}
The first line makes the query, and I tried using List but I get an error: Invalid loop variable type expected SObject was objTwo__c. The loop is used to parse out the name from the object list, but it doesn't accept sObject, either.
I've tried using the Schema, and getGlobalType, but it seems I must cast the newObject as the type I need, which defeats my purpose.
Is there a way to pass type as a parameter?