0

I have a requirement to build a custom component for Customer Community to create a new case. On the form I have a lookup field to a custom object that doesn't want to work. Are lookups to custom objects suppose to work in communities? Here's a simplified version of my code.

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="Case" type="Case"  />
<aura:attribute name="newCase" type="Object"  />
<aura:attribute name="simpleNewCase" type="Object" />
<aura:attribute name="newCaseError" type="String" />
<force:recordData aura:id="caseRecordCreator"
                  fields="Location__c,LocationTest__c,Number_of_Required_Extensions__c,Primary_Use_for_Numbers__c,Extension_End_Range__c"
                  targetRecord="{!v.newCase}"
                  targetFields="{!v.simpleNewCase}"
                  targetError="{!v.newCaseError}" />

<!-- First we initialize the form -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />

<lightning:recordEditForm objectApiName="Case"
                          onsubmit="{!c.handleSaveCase}" >
                        <lightning:inputField fieldName="Location__c" />
                        <lightning:inputField fieldName="OwnerId" />
                        <lightning:inputField fieldName="LocationTest__c" />
                        <lightning:inputField fieldName="ContactId" />
                        <lightning:input label="Input" value="{!v.case.LocationTest__c}"/>
</lightning:recordEditForm> 

</aura:component>


({
doInit : function(component, event, helper) {
    //Standard way to load a record template using Lightning Data Service
    component.find("caseRecordCreator").getNewRecord(
        "Case",
        "0122a0000008c9lAAA",
        false,
        $A.getCallback(function(){
            var rec = component.get("v.newCase");
            var error = component.get("v.newCaseError");
            if(error || (rec === null)){
                console.log("Error initializing record template: " + error);
            }else{
                console.log("Record template initialized" + rec.sobjectType);
            }
        })
    );
},

    handleSaveCase : function(component, event, helper){
    //This is how we link the new Contact with the actual Account Id
    //component.set("v.simpleNewCase.AccountId", component.get("v.simpleUser.AccountId"));        
    //alert("{!v.simpleUser.AccountId}");
    //component.set("v.simpleNewCase.ContactId", component.get("v.simpleUser.ContactId"));

    //Standard way to save a record using Lightning Data Service
    component.find("caseRecordCreator").saveRecord(function(saveResult){
        if(saveResult.state === "SUCCESS" || saveResult.state === "DRAFT"){
            //resultToast is a pop-up window that show messages.
            var resultsToast = $A.get("e.force:showToast");
            resultsToast.setParams({
                "title" : "Case saved",
                "message" : "The new case was created",
                "type" : "success"
            });

            $A.get("e.force:closeQuickAction").fire();
            resultsToast.fire();
            $A.get("e.force:refreshView").fire();
        }else if(saveResult.state === "INCOMPLETE"){
            console.log("User is offline, device doesn't support drafts.");
        }else if(saveResult.state === "ERROR"){
            console.log("Problem saving case, error" + JSON.stringify(saveResult.error));
        }else{
            console.log("Unknown problem, state: " + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
        }
    });
}})

Why isn't the Location lookup showing any values?

2
  • which field is the lookup? and what do you mean by doesnt work? when you search on it for existing records, none populate? – glls Mar 23 '19 at 17:03
  • Location__c and LocationTest__c don't even show up on the UI as if that code was commented out or something. – Laura Bejjani Mar 23 '19 at 17:25
0

I fixed the issue by giving the community user profile read/edit rights to the Location Object

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.