0

I'm just starting to learn SalesForce so forgive me if this question has an obvious answer. I've been creating a basic "display data in a table" component in the Developer Console. It catalogues movie posters just based on movie title and how many are in stock (count).

All I want to do is try out my code, but all I see in the "Poster" tab is the list of data I've made and not my component. How can I try out my code?

This is what I see:

Poster list

Here is my Apex controller:

public class PostroApexController {


    @AuraEnabled
    public static List<Poster__c> getPosters(Id PosterID){

        return [Select ID__c, Count__c, Name From Poster__c Where ID = :PosterID];

    }

}

My XML component:

<aura:component controller="PostroApexController" implements="flexipage:availableForRecordHome" access="global">
    Hello World
    <aura:attribute name="Poster" type="Poster__c"/>
    <aura:attribute name="Posters" type="List"/>
    <aura:attribute name="Columns" type="List"/>
    <aura:handler name="init" value="{!this}" action="{!c.performInit}"/>

    <lightning:datatable data="{! v.Poster }" columns="{! v.Columns }" keyField="ID" hideCheckboxColumn="true"/>
</aura:component>

My JS controller:

({
    performInit : function(component, event, helper) {

        component.set("v.Columns", [
            {label:"Poster Title", fieldName:"Name", type:"text"},
            {label:"Count", fieldName:"Count__c"}

        ]);

        var action = component.get("c.getPosters");
        // set the args for getPosters(ID)
        action.setParams({
            PosterID: component.get("v.PosterID")
        });
        action.setCallback(this, function(data) {
           component.set("v.Posters", data.getReturnValue()); 
        });

        $A.enqueueAction(action);
    }
})

I'm looking for something that will let me see the data table I created in the component. Feel free to point out any other issues with my code too, I know it's awful and probably doesn't work.

Thank you!

5

You can create a lightning application to host your component and see if it works. You have to go to File -> New -> Lightning Application to create an app.

if your component name is posterComponent then markup for lightning application will be like

<aura:application extends="force:slds">
    <c:posterComponent />
</aura:application>

Once you create the Lightning Application, developer console even gives you an option to preview it.

enter image description here

I would recommend you to go through the basics here. https://trailhead.salesforce.com/en/modules/lex_dev_lc_basics

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.