Skip to main content 欢迎参加 3 月 5 日至 6 日在旧金山举行的 TDX AI 代理时代开发者大会,或通过 Salesforce+ 参与。立即注册
错误

出错了。请重试。

Hello All,

<!-- NewAccount -->

<aura:component implements="force:appHostable" controller="AccountController">

    <aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', }" access="public"/>

    <div >

        <center>

            <form>

                Name <force:inputField aura:id="Name" value="{!v.newAccount.Name}"/>

                Note <force:inputField aura:id="Note" value="{!v.newAccount.Description}"/>

                Categories<force:inputField aura:id="Categories" value="{!v.newAccount.Categories_del__c}"/>

                SubCategories<force:inputField aura:id="SubCategories" value="{!v.newAccount.Sub_Categories__c    }"/>

                Assign to<force:inputField aura:id="Assign To " value="{!v.newAccount.Assigned_To__c}"/>

                Billing Street <force:inputField aura:id="Street " value="{!v.newAccount.BillingStreet}"/>

                Billing City <force:inputField aura:id="City " value="{!v.newAccount.BillingCity}"/>

                Billing State <force:inputField aura:id="State " value="{!v.newAccount.BillingState}"/>

                Billing Country <force:inputField aura:id="Country " value="{!v.newAccount.BillingCountry}"/>

                Billing Postal Code<force:inputField aura:id="Postal Code " value="{!v.newAccount.BillingPostalCode}"/>

                <lightning:button label="Save" onclick="{!c.createAccount}" />

                

            </form>

        </center>

    </div>

</aura:component>

This is my sample code to save Account Record using Lightning Component. "Assign To"  is custom field of "User Lookup" ,  but it gives the following error. Check screen shot as well. I also enabled Lightning component checkbox.

"This page has an error. You might just need to refresh it.

Access Check Failed! AttributeSet.get(): attribute 'inContextOfRecordId' of component 'markup://c:NewAccount {3:0}' is not visible to 'markup://c:NewAccount {3:0}'.

Failing descriptor: {markup://c:NewAccount}"

User-added image
4 个回答
  1. 2017年9月4日 13:04
    Hi Puja,

    Implement this code, I have tested this and it is working.

    <!--Component-->

    <aura:component implements="force:appHostable" controller="AccountController">

    <aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', }" access="public"/>

    <aura:attribute name="AssignId" type="string" default=""/>

    <aura:handler name="change" value="{!v.newAccount.Assigned_To__c}" action="{!c.GetId}"/>

    <div >

    <center>

    <table>

    <tr>

    <td> Name </td>

    <td><force:inputField aura:id="Name" value="{!v.newAccount.Name}"/></td>

    </tr>

    <tr>

    <td> Note </td><td><force:inputField aura:id="Note" value="{!v.newAccount.Description}"/></td>

    </tr>

    <tr>

    <td> Categories</td><td><force:inputField aura:id="Categories" value="{!v.newAccount.Categories_del__c}"/></td>

    </tr>

    <tr>

    <td>SubCategories</td><td><force:inputField aura:id="SubCategories" value="{!v.newAccount.Sub_Categories__c }"/></td>

    </tr>

    <tr>

    <td>Assign to</td><td> <force:inputField aura:id="kbid" required="true" value="{!v.newAccount.Assigned_To__c}" change="{!c.GetId}" class="LkField"/></td>

    </tr>

    <tr>

    <td> Billing Street </td><td><force:inputField aura:id="Street " value="{!v.newAccount.BillingStreet}"/></td>

    </tr>

    <tr>

    <td> Billing City </td><td><force:inputField aura:id="City" value="{!v.newAccount.BillingCity}"/></td>

    </tr>

    <tr>

    <td>Billing State </td><td><force:inputField aura:id="State" value="{!v.newAccount.BillingState}"/></td>

    </tr>

    <tr>

    <td> Billing Country </td><td><force:inputField aura:id="Country" value="{!v.newAccount.BillingCountry}"/></td>

    </tr>

    <tr>

    <td> Billing Postal Code</td><td><force:inputField aura:id="Postal Code" value="{!v.newAccount.BillingPostalCode}"/></td>

    </tr>

    <tr>

    <td><lightning:button label="Save" onclick="{!c.createAccount}" /></td>

    </tr>

    </table>

    </center>

    </div>

    </aura:component>

    <--Js Controller-->

    ({

    createAccount : function(component, event) {

    var newAcc = component.get("v.newAccount");

    var assignId=component.get("v.AssignId");

    var action = component.get("c.saveAccount");

    action.setParams({

    "acc": newAcc,

    "aid":assignId

    });

    action.setCallback(this, function(a) {

    var state = a.getState();

    if (state === "SUCCESS") {

    var name = a.getReturnValue();

    alert("Account inserted: "+name);

    }

    });

    $A.enqueueAction(action);

    },

    GetId:function(component,event,helper)

    {

    var AssignId = event.getParam("value");

    console.log("current value: " +AssignId);

    component.set("v.AssignId",AssignId);

    }

    })

    <!--Apex Controller-->

    public class AccountController {

    @AuraEnabled

    public static Account saveAccount (Account acc,Id aid) {

    acc.Assigned_To__r = null;

    acc.Assigned_To__c = aid;

    insert acc;

    return acc;

    }

    }

    If it helps, Please mark it as BEST Answer and mark this thread as SOLVED
0/9000