• Gonzalo Diaz 15
  • NEWBIE
  • 45 Points
  • Member since 2018

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi there

I'm getting an error message on this Trailhead Module and I don't know what I'm doing wrong.  I have been trying for a couple of days and can't work out what my error is.

Here is my Developer Console code:

PROPERTY DIALOG COMPONENT:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="picklistValues" type="Object" />
    <aura:attribute name="propertyRecord" type="Property__c" />
<force:recordData aura:id="forceRecord"
                recordId="{!v.recordId}"
                targetFields="{!v.propertyRecord}"
                fields="Id,Name,Beds__c,Baths__c,Price__c,Status__c"
                mode="EDIT" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<c:PickListValues sObjectName="Property__c" fieldName="Status__c" picklistValues="{!v.picklistValues}" />
    <lightning:input aura:id="propName" name="propName" label="Property Name" required="true" />
<lightning:input aura:id="propBeds" name="propBeds" label="Beds" />
<lightning:input aura:id="propBaths" name="propBaths" label="Baths" />
<lightning:input aura:id="propPrice" name="propPrice" label="Price" />
<lightning:select aura:id="propStatus" name="propStatus" label="Status">
        <aura:iteration items="{!v.picklistValues}" var="item">
    <option value="{!item}">{!item}</option>
</aura:iteration>
</lightning:select>
<lightning:button variant="neutral" label="Cancel" />
<lightning:button variant="brand" label="Submit" onclick="{!c.saveRecord}"/>
</aura:component>

PICKLIST COMPONENT:
<aura:component >
    <aura:attribute name="sObjectName" type="String" />
<aura:attribute name="fieldName" type="String" />
<aura:attribute name="picklistValues" type="Object" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

PICKLIST CONTROLLER:
public class PickListController {

@AuraEnabled        
public static List<String> getPickListValuesIntoList(String objectType, String selectedField){
    List<String> pickListValuesList = new List<String>();
    Schema.SObjectType convertToObj = Schema.getGlobalDescribe().get(objectType);
    Schema.DescribeSObjectResult res = convertToObj.getDescribe();
    Schema.DescribeFieldResult fieldResult = res.fields.getMap().get(selectedField).getDescribe();
    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    for( Schema.PicklistEntry pickListVal : ple){
        pickListValuesList.add(pickListVal.getLabel());
    }     
    return pickListValuesList;
}}

PICKLIST VALUES CONTROLLER:
({
    doInit : function(component) {
        var action = component.get("c.getPickListValuesIntoList");
        action.setParams({
            objectType: component.get("v.sObjectName"),
            selectedField: component.get("v.fieldName")
        });
        action.setCallback(this, function(response) {
            var list = response.getReturnValue();
            component.set("v.picklistValues", list);
        })
        $A.enqueueAction(action);
    }
})

PROPERTY DIALOG CONTROLLER:
({
    doInit : function(component, event, helper) {
        
    component.find("forceRecord").getNewRecord(
        "Property__c",
        null,
        false,
        $A.getCallback(function() {
            var rec = component.get("v.propertyRecord");
            var error = component.get("v.recordError");
            if (error || (rec === null)) {
                console.log("Error initializing record template: " + error);
                return;
            }
        })
    );},
    saveRecord : function(component, event, helper) {
var propBeds = parseInt(component.find('propBeds').get("v.value"), 10);
var propBaths = parseInt(component.find('propBaths').get("v.value"), 10);
var propPrice = parseInt(component.find('propPrice').get("v.value"), 10);

component.set("v.propertyRecord.Name", component.find('propName').get("v.value"));    
component.set("v.propertyRecord.Beds__c", propBeds);
component.set("v.propertyRecord.Baths__c", propBaths);
component.set("v.propertyRecord.Price__c", propPrice);
component.set("v.propertyRecord.Status__c", component.find('propStatus').get("v.value"));

var tempRec = component.find("forceRecord");
tempRec.saveRecord($A.getCallback(function(result) {
    console.log(result.state);
    var resultsToast = $A.get("e.force:showToast");
    if (result.state === "SUCCESS") {
        resultsToast.setParams({
            "title": "Saved",
            "message": "The record was saved."
        });
        resultsToast.fire();                
        var recId = result.recordId;
helper.navigateTo(component, recId);
    } else if (result.state === "ERROR") {
        console.log('Error: ' + JSON.stringify(result.error));
        resultsToast.setParams({
            "title": "Error",
            "message": "There was an error saving the record: " + JSON.stringify(result.error)
        });
        resultsToast.fire();
    } else {
        console.log('Unknown problem, state: ' + result.state + ', error: ' + JSON.stringify(result.error));
    }
}));}
})

PROPERTY DIALOG HELPER:
({
    navigateTo: function(component, recId) {
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": recId
        });
        navEvt.fire();
    }
})

And I'm getting this error message:
Uncaught Unknown controller action 'getPickListValuesIntoList'
Callback failed: serviceComponent://ui.flexipage.components.page.FlexipageControllerV2/ACTION$getPage

With this Stack Trace:
a.H.get()@https://curious-goat-22263-dev-ed.lightning.force.com/auraFW/javascript/cbZO21YQZI1hrYG6dKZGlw/aura_prod.js:288:176
Object.value [as get]()@https://curious-goat-22263-dev-ed.lightning.force.com/auraFW/javascript/cbZO21YQZI1hrYG6dKZGlw/aura_prod.js:720:228
doInit()@https://curious-goat-22263-dev-ed.lightning.force.com/one/components/c/PickListValues.js:10:32

Any help would be greatly appreciated.  I don't use Developer Console work in my role, but thought I'd learn and am just ripping my hair out!!

Cheers, Nat
Hi there

I'm getting an error message on this Trailhead Module and I don't know what I'm doing wrong.  I have been trying for a couple of days and can't work out what my error is.

Here is my Developer Console code:

PROPERTY DIALOG COMPONENT:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="picklistValues" type="Object" />
    <aura:attribute name="propertyRecord" type="Property__c" />
<force:recordData aura:id="forceRecord"
                recordId="{!v.recordId}"
                targetFields="{!v.propertyRecord}"
                fields="Id,Name,Beds__c,Baths__c,Price__c,Status__c"
                mode="EDIT" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<c:PickListValues sObjectName="Property__c" fieldName="Status__c" picklistValues="{!v.picklistValues}" />
    <lightning:input aura:id="propName" name="propName" label="Property Name" required="true" />
<lightning:input aura:id="propBeds" name="propBeds" label="Beds" />
<lightning:input aura:id="propBaths" name="propBaths" label="Baths" />
<lightning:input aura:id="propPrice" name="propPrice" label="Price" />
<lightning:select aura:id="propStatus" name="propStatus" label="Status">
        <aura:iteration items="{!v.picklistValues}" var="item">
    <option value="{!item}">{!item}</option>
</aura:iteration>
</lightning:select>
<lightning:button variant="neutral" label="Cancel" />
<lightning:button variant="brand" label="Submit" onclick="{!c.saveRecord}"/>
</aura:component>

PICKLIST COMPONENT:
<aura:component >
    <aura:attribute name="sObjectName" type="String" />
<aura:attribute name="fieldName" type="String" />
<aura:attribute name="picklistValues" type="Object" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

PICKLIST CONTROLLER:
public class PickListController {

@AuraEnabled        
public static List<String> getPickListValuesIntoList(String objectType, String selectedField){
    List<String> pickListValuesList = new List<String>();
    Schema.SObjectType convertToObj = Schema.getGlobalDescribe().get(objectType);
    Schema.DescribeSObjectResult res = convertToObj.getDescribe();
    Schema.DescribeFieldResult fieldResult = res.fields.getMap().get(selectedField).getDescribe();
    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    for( Schema.PicklistEntry pickListVal : ple){
        pickListValuesList.add(pickListVal.getLabel());
    }     
    return pickListValuesList;
}}

PICKLIST VALUES CONTROLLER:
({
    doInit : function(component) {
        var action = component.get("c.getPickListValuesIntoList");
        action.setParams({
            objectType: component.get("v.sObjectName"),
            selectedField: component.get("v.fieldName")
        });
        action.setCallback(this, function(response) {
            var list = response.getReturnValue();
            component.set("v.picklistValues", list);
        })
        $A.enqueueAction(action);
    }
})

PROPERTY DIALOG CONTROLLER:
({
    doInit : function(component, event, helper) {
        
    component.find("forceRecord").getNewRecord(
        "Property__c",
        null,
        false,
        $A.getCallback(function() {
            var rec = component.get("v.propertyRecord");
            var error = component.get("v.recordError");
            if (error || (rec === null)) {
                console.log("Error initializing record template: " + error);
                return;
            }
        })
    );},
    saveRecord : function(component, event, helper) {
var propBeds = parseInt(component.find('propBeds').get("v.value"), 10);
var propBaths = parseInt(component.find('propBaths').get("v.value"), 10);
var propPrice = parseInt(component.find('propPrice').get("v.value"), 10);

component.set("v.propertyRecord.Name", component.find('propName').get("v.value"));    
component.set("v.propertyRecord.Beds__c", propBeds);
component.set("v.propertyRecord.Baths__c", propBaths);
component.set("v.propertyRecord.Price__c", propPrice);
component.set("v.propertyRecord.Status__c", component.find('propStatus').get("v.value"));

var tempRec = component.find("forceRecord");
tempRec.saveRecord($A.getCallback(function(result) {
    console.log(result.state);
    var resultsToast = $A.get("e.force:showToast");
    if (result.state === "SUCCESS") {
        resultsToast.setParams({
            "title": "Saved",
            "message": "The record was saved."
        });
        resultsToast.fire();                
        var recId = result.recordId;
helper.navigateTo(component, recId);
    } else if (result.state === "ERROR") {
        console.log('Error: ' + JSON.stringify(result.error));
        resultsToast.setParams({
            "title": "Error",
            "message": "There was an error saving the record: " + JSON.stringify(result.error)
        });
        resultsToast.fire();
    } else {
        console.log('Unknown problem, state: ' + result.state + ', error: ' + JSON.stringify(result.error));
    }
}));}
})

PROPERTY DIALOG HELPER:
({
    navigateTo: function(component, recId) {
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": recId
        });
        navEvt.fire();
    }
})

And I'm getting this error message:
Uncaught Unknown controller action 'getPickListValuesIntoList'
Callback failed: serviceComponent://ui.flexipage.components.page.FlexipageControllerV2/ACTION$getPage

With this Stack Trace:
a.H.get()@https://curious-goat-22263-dev-ed.lightning.force.com/auraFW/javascript/cbZO21YQZI1hrYG6dKZGlw/aura_prod.js:288:176
Object.value [as get]()@https://curious-goat-22263-dev-ed.lightning.force.com/auraFW/javascript/cbZO21YQZI1hrYG6dKZGlw/aura_prod.js:720:228
doInit()@https://curious-goat-22263-dev-ed.lightning.force.com/one/components/c/PickListValues.js:10:32

Any help would be greatly appreciated.  I don't use Developer Console work in my role, but thought I'd learn and am just ripping my hair out!!

Cheers, Nat