0

Custom Lightning Component work ok in Lightning experience standard UI. When I add it to a community page layout, it shrinks and gives 'internal error'. Contacted Salesforce weeks ago but still no reply.

<aura:component description="ContactSearch" controller="ContactSearchCtrl" implements=" forceCommunity:availableForAllPageTypes" access="global" >

<aura:attribute name="contactList" type="Object[]"/>
<aura:attribute name="contactName" type="String" />
<aura:attribute name="birthdate" type="String" />
<aura:handler name="change" value="{!v.birthdate}" action="{!c.doInit}"/>

<lightning:card class="white">
    <div class="slds-grid slds-wrap">
        <div class="slds-size_1-of-7">
        </div>
        <div class="slds-size_2-of-7">
            <lightning:helptext content="Start typing to Filter Contacts by Last Name" />
            <ui:inputText placeholder="Search Name" value="{!v.contactName}" label="Surname" aura:id="contact" keyup="{!c.doInit}"/>
        </div>
        <div class="slds-size_1-of-7">
        </div>
        <div class="slds-size_2-of-7">
            <lightning:helptext content="Start typing to Filter Contacts by Birth Date" />
            <ui:inputDate aura:id="date" label="Birth Date" value="{!v.birthdate}" displayDatePicker="true" keyup="{!c.doInit}"/>
        </div>
        <div class="slds-size_1-of-7">
        </div>
    </div>
</lightning:card>
<table >
    <aura:iteration items="{!v.contactList}" var="cont">
        <tr>
            <td>
                    {!cont.Name}
            </td>
            <!--<td>
                    {!cont.FirstName}
            </td>
            <td>
                    {!cont.LastName}
            </td>-->

            <td>
                    {!cont.Birthdate}
            </td>
        </tr>
    </aura:iteration>
</table>

js controller

({
  doInit: function (component, event, helper)
  {
    helper.loadContacts(component);
  }
})

js helper

({
 loadContacts : function(component, event, helper) {
    var name = component.get("v.contactName");
    var date = component.get("v.birthdate");
    var action = component.get("c.searchForContacts");
    action.setParams({searchText : name, searchDate : date});
    console.log(action);
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            component.set("v.contactList", response.getReturnValue());
        }
        /*var toastEvent = $A.get("e.force:showToast");
        if (state === 'SUCCESS'){
            toastEvent.setParams({
                "title": "Success!",
                "message": " Your contacts have been loaded successfully."
            });
        }
        else {
            toastEvent.setParams({
                "title": "Error!",
                "message": " Something has gone wrong."
            });
        }
        toastEvent.fire();*/
    });
    $A.enqueueAction(action);
 },

})

This is before drop the component to the layout page: enter image description here

This is after dropping it, it shrinks in one line and show nothing.

enter image description here

public with sharing class ContactSearchCtrl {

@AuraEnabled
public static List<Contact> searchForContacts(String searchText, String searchDate) {
    Date newDate;
    system.debug(searchDate);
    system.debug(searchText);
    /*String newSearchDate = searchDate.format();*/
    List<Contact> contactList = new List<Contact>();
    String query1 = 'SELECT Account.Name, Name, firstName, lastName, Age__c, Gender__c, Birthdate FROM Contact WHERE Name LIKE \'%'+ searchText + '%\' AND RecordType.DeveloperName = \'Consult_Patient\' ORDER by lastName ASC LIMIT 10 ';
    String query2 = 'SELECT Account.Name, Name, firstName, lastName, Age__c, Gender__c, Birthdate FROM Contact WHERE Birthdate = '+newDate+' AND RecordType.DeveloperName = \'Consult_Patient\' ORDER by BirthDate ASC LIMIT 10 ';
    String query3 = 'SELECT Account.Name, Name, firstName, lastName, Age__c, Gender__c, Birthdate FROM Contact WHERE Name LIKE \'%'+ searchText + '%\' AND Birthdate = '+newDate+' AND RecordType.DeveloperName = \'Consult_Patient\' ORDER by lastName ASC LIMIT 10 ';
    contactList = [SELECT Account.Name, Name, firstName, lastName, Age__c, Gender__c, Birthdate FROM Contact WHERE RecordType.DeveloperName = 'Consult_Patient' LIMIT 10];
    if(searchText!=NULL && searchDate == NULL){
        return contactList = Database.query(query1);
    }else if(searchText==NULL && searchDate!=NULL){
        newDate = Date.valueOf(searchDate);
        return contactList = Database.query(query2);
    }else if(searchText!=NULL && searchDate!=NULL){
        newDate = Date.valueOf(searchDate);
        return contactList = Database.query(query3);
    }else{
        return contactList;
    }
}

}

enter image description here

  • Please provide the complete error message – glls Dec 30 '17 at 18:09
  • Updated with a screenshot, I don't know how much this can help. – Adelchi Dec 30 '17 at 18:15
  • Try narrowing down your code to a minimum and reach to a point where your component gets displayed - after that add code step by step, then you will find your problem – Itai Shmida Dec 31 '17 at 8:17
  • One source of "An internal server error has occurred" in Lightning is a problem with your Apex. So, try loading your community page with the developer console open and look at the Apex logs from when your controller runs. Or, wrap all of your apex in try {...} catch(Exception e) { throw new AuraHandledException(e.getMessage()); } then output the details in your Lightning JS somewhere. Hopefully, this will give you more info to work with. – Aidan Jan 2 '18 at 9:32
-1

I removed <lightning:card> tag and now is working in community as well.

| improve this answer | |
  • Are you saying that lightning:card is not supported in communities? – Mahmood Jan 3 '18 at 10:09

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.