0

I am learning how to use Aura to create lightning components for record pages inside of salesforce. All I am trying to do at this point is to print the name of the Record (I'm testing with account records). However, whenever I try to save the helper file I get this error:

FIELD_INTEGITY_EXCEPTION Failed to save Pic2Helper.js: null: Source

Here is the code I am using:

Pic2.cmp (main component):

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" controller = "LightTest" >
    <aura:handler name="init" action="{!c.doInit}" value ="{!this}"/>
    <aura:attribute name="thisAccount" type="Account"/>
    Here it is: {!v.thisAccount.Name} 
</aura:component>

Pic2Controller.js:

({
    doInit : function(component, event, helper) {
        component.get("v.recordId");
        helper.getOb(component);
    }
})

Pic2Helper.js (the file that won't save):

({
    getOb : function(component) {
        var action = component.get("c.getAccount");
        action.setParams("inID" : component.get("v.recordId"));
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.thisAccount", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
        $A.enqueueAction(action);
    } ,

})

LightTest.apxc (Controller):

public with sharing class LightTest {
    @AuraEnabled
    
    public static String getAccount(String inId){
        List<Account> boi = [select Name from Account where id = :inId];
        Account it = boi.get(0);
        return it.Name;
    }
    
}

I am really lost and don't know where to even start to see what I did wrong. Any help on why that error is happening or anything else I have inevitably messed up would be much appreciated.

Thanks!

1 Answer 1

0

update your helper, the line where you are setting the action parameters from this:

action.setParams("inID" : component.get("v.recordId"));

to this:

action.setParams({ "inID": component.get("v.recordId") });

remember you need to pass an object as parameter (which follows the { property: "value" } syntax)

Hope it helps.

NB: Also, I can see your apex method is returning a String, and your aura attribute (thisAccount) type is Account, so you either change your apex return type, or your aura attribute type. so they match and you don't get unexpected results.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .