• Lek Lextech
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 5
    Replies
Hi all, I try to use force:recorddata to retrive field data from record Id, it even work well to retrive relationship field value, but not for Record Type Name when I use {!v.recordField.RecordType.Name}, it return NULL value. How can I retrive Record Type Name without using Apex?

This is my component code:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
    <aura:attribute name="record" type="Object" />
    <aura:attribute name="recordField" type="Object" />
    <aura:attribute name="recordError" type="String" />
    <aura:attribute name="recordId" type="Id"  />

<force:recordData aura:id="recordEditor"
    layoutType="FULL"
    recordId="{!v.recordId}"
    targetError="{!v.recordError}"
    targetRecord="{!v.record}"
    targetFields="{!v.recordField}"
    mode="EDIT" />

                {!v.recordField.RecordTypeId} <br/>
                {!v.recordField.RecordType.Name}

</aura:component>

 
Hi All, my class and test class below is just cover for 60%, I found that is not cover on for loop. How can I modify test class to cover for loop?
Many Thanks.

customLookUpController:
public class customLookUpController {
    @AuraEnabled
    public static List < sObject > fetchLookUpValues(List<String> fieldstoShow, String searchKeyWord, String ObjectName, String whereCondition, String limitRecord) {
        system.debug('ObjectName-->' + ObjectName);
        String searchKey = searchKeyWord + '%';
		String moreFields = ','+String.Join(fieldstoShow,',');
            
        List < sObject > returnList = new List < sObject > ();
      
        // Create a Dynamic SOQL Query For Fetch Record List with some LIMIT   
        String sQuery =  'select id, Name'+moreFields+' from '+ObjectName + ' where Name LIKE: searchKey '+whereCondition +' order by createdDate DESC limit '+limitRecord;
        List < sObject > lstOfRecords = Database.query(sQuery);
        
        for (sObject obj: lstOfRecords) {
            returnList.add(obj);
        }
        return returnList;
    }
}

customLookUpTestController:
@isTest(SeeAllData=true)
private class customLookUpTestController {
	@isTest static void testCustomLookup(){
		List <String> fieldstoShow = new List <String>();
        fieldstoShow.add('Id');
        fieldstoShow.add('Name');
        
        List < sObject > returnList = customLookUpController.fetchLookUpValues(fieldstoShow, '', 'Account', '', '5');
        System.assert(returnList != null);
        
    }
}

User-added image
Hi all,

How can I get other fields' value of recordId attribute in Lightning component?
For instance, recordId of Opportunity, want to get AccountId of this opportunity
Hi All,

I try to pass variable for relationship field (relationshipField ) to be default value parameter to create record, but it doesn't work, no default value appear in create record panel (it works when I fix field name instead). Please help.

------------------Component Attribute-------------------------
<aura:component controller="DataTableController" access="public" implements="force:appHostable,flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes,force:hasRecordId">
<aura:attribute access="public" name="object" type="String" default="Account" required="true"/>
<aura:attribute access="public" name="columnfields" type="String" required="true" default="Id, Name"/>
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="remoteRecordId" type="Id" />
<aura:attribute name="relationshipField" type="String" />

<lightning:button variant="brand" label="New" iconName="utility:home" iconPosition="right" onclick="{!c.creatRecord}" />

----------------------JS Controller----------------------------------------
creatRecord : function (component, event, helper) {
    var sObject = component.get("v.object");
    var relationshipField = component.get("v.relationshipField");
    var parentID =  component.get("v.recordId");
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": sObject,
        "defaultFieldValues": {
            relationshipField : parentID,
            }
        });
    createRecordEvent.fire();
    }

creatRecord : function (component, event, helper) {
    var sObject = component.get("v.object");
    var relationshipField = component.get("v.relationshipField");
    var parentID =  component.get("v.recordId");
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": sObject,
        "defaultFieldValues": {
            relationshipField : parentID,
            }
        });
    createRecordEvent.fire();
    }
Hi All,

I try to pass variable for relationship field (relationshipField ) to be default value parameter to create record, but it doesn't work, no default value appear in create record panel (it works when I fix field name instead). Please help.

creatRecord : function (component, event, helper) {
    var sObject = component.get("v.object");
    var relationshipField = component.get("v.relationshipField");
    var parentID =  component.get("v.recordId");
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": sObject,
        "defaultFieldValues": {
            relationshipField : parentID,
            }
        });
    createRecordEvent.fire();
    }
Hi all, I would link to make Lightning Component using in Opportunity page. In this component contains 3 picklists which its value from custom object and dependent ex. Picklist 2 depend on Picklist 1, Picklist 3 depend on Picklist 2. I have some code in Apex/VF below, How can I transform to Lighning component? Thank you in advance:

------------------- APEX -----------------------------
public class MultiSelectController {

    // reference for the standard controller
    private ApexPages.StandardController controller {get; set;}

    // the record that is being edited
    private Opportunity opp;

    // the values of the selected items
    public string selectedLevel1 {get; set;}
    public string selectedLevel2 {get; set;}
    public string selectedLevel3 {get; set;}

    public List<selectOption> level1Items {
        get {
            List<selectOption> options = new List<selectOption>();

                options.add(new SelectOption('','-- Choose a Category --'));
                for (Cat1__c cat : [select Id, Name from Cat1__c Order By Name])
                    options.add(new SelectOption(cat.Id,cat.Name));

            return options;           
        }
        set;
    }

    public List<selectOption> level2Items {
        get {
            List<selectOption> options = new List<selectOption>();

            if (selectedLevel1 != NULL) {
                options.add(new SelectOption('','-- Choose a Category --'));
                for (Cat2__c cat : [select Id, Name from Cat2__c Where Cat1__c = :selectedLevel1 Order By Name])
                    options.add(new SelectOption(cat.Id,cat.Name));
            }

            return options;           
        }
        set;
    }   

    public List<selectOption> level3Items {
        get {
            List<selectOption> options = new List<selectOption>();

            if (selectedLevel2 != NULL) {
                options.add(new SelectOption('','-- Choose a Category --'));
                for (Cat3__c cat : [select Id, Name from Cat3__c Where Cat2__c = :selectedLevel2 Order By Name])
                    options.add(new SelectOption(cat.Id,cat.Name));
            }

            return options;           
        }
        set;
    }       

    public MultiSelectController(ApexPages.StandardController controller) {

        //initialize the stanrdard controller
        this.controller = controller;
        // load the record
        this.opp = (Opportunity)controller.getRecord();

        // preselect the current values for the record
        selectedLevel1 = opp.Cat1__c;
        selectedLevel2 = opp.Cat2__c;
        selectedLevel3 = opp.Cat3__c;

    }          

    public PageReference save() {

        // set the selected values to the record before saving
        opp.Cat1__c = selectedLevel1;
        opp.Cat2__c = selectedLevel2;
        opp.Cat3__c = selectedLevel3;

        try {
            upsert(opp);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        return (new ApexPages.StandardController(opp)).view();
    }        

}

-------------------------- VF ----------------------------------------------
<apex:page standardController="Opportunity" extensions="MultiSelectController">  
     <apex:sectionHeader title="Opportunity" subtitle="{!opportunity.name}"/>
        <apex:form >
            <apex:pageBlock title="Opportunity" mode="edit">
                <apex:outputText value="{!opportunity.Cat1__c}" rendered="false"/>
                <apex:outputText value="{!opportunity.Cat2__c}" rendered="false"/>
                <apex:outputText value="{!opportunity.Cat3__c}" rendered="false"/>

          <apex:pageBlockButtons location="both">
               <apex:commandButton value="Save" action="{!save}" />
               <apex:commandButton value="Cancel" action="{!cancel}" />
          </apex:pageBlockButtons>
          <apex:pageMessages />       

          <apex:pageBlockSection title="Master Categories" columns="1">

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Category 1" for="cbxlevel1"/>
                    <apex:outputPanel styleClass="requiredInput" layout="block">
                    <apex:outputPanel styleClass="requiredBlock" layout="block"/>
                    <apex:selectList value="{!selectedLevel1}" id="cbxlevel1" size="1" required="true">
                        <apex:selectOptions value="{!level1items}"/>
                        <apex:actionSupport event="onchange" rerender="cbxlevel2"/>
                    </apex:selectList>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Category 2" for="cbxlevel2"/>
                    <apex:selectList value="{!selectedLevel2}" id="cbxlevel2" size="1">
                        <apex:selectOptions value="{!level2items}"/>
                        <apex:actionSupport event="onchange" rerender="cbxlevel3"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Category 3" for="cbxlevel3"/>
                    <apex:selectList value="{!selectedLevel3}" id="cbxlevel3" size="1">
                        <apex:selectOptions value="{!level3items}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>

          </apex:pageBlockSection>

     </apex:pageBlock>
     </apex:form>   

</apex:page> 
Hi All, my class and test class below is just cover for 60%, I found that is not cover on for loop. How can I modify test class to cover for loop?
Many Thanks.

customLookUpController:
public class customLookUpController {
    @AuraEnabled
    public static List < sObject > fetchLookUpValues(List<String> fieldstoShow, String searchKeyWord, String ObjectName, String whereCondition, String limitRecord) {
        system.debug('ObjectName-->' + ObjectName);
        String searchKey = searchKeyWord + '%';
		String moreFields = ','+String.Join(fieldstoShow,',');
            
        List < sObject > returnList = new List < sObject > ();
      
        // Create a Dynamic SOQL Query For Fetch Record List with some LIMIT   
        String sQuery =  'select id, Name'+moreFields+' from '+ObjectName + ' where Name LIKE: searchKey '+whereCondition +' order by createdDate DESC limit '+limitRecord;
        List < sObject > lstOfRecords = Database.query(sQuery);
        
        for (sObject obj: lstOfRecords) {
            returnList.add(obj);
        }
        return returnList;
    }
}

customLookUpTestController:
@isTest(SeeAllData=true)
private class customLookUpTestController {
	@isTest static void testCustomLookup(){
		List <String> fieldstoShow = new List <String>();
        fieldstoShow.add('Id');
        fieldstoShow.add('Name');
        
        List < sObject > returnList = customLookUpController.fetchLookUpValues(fieldstoShow, '', 'Account', '', '5');
        System.assert(returnList != null);
        
    }
}

User-added image
Hi all,

How can I get other fields' value of recordId attribute in Lightning component?
For instance, recordId of Opportunity, want to get AccountId of this opportunity
Hi All,

I try to pass variable for relationship field (relationshipField ) to be default value parameter to create record, but it doesn't work, no default value appear in create record panel (it works when I fix field name instead). Please help.

creatRecord : function (component, event, helper) {
    var sObject = component.get("v.object");
    var relationshipField = component.get("v.relationshipField");
    var parentID =  component.get("v.recordId");
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": sObject,
        "defaultFieldValues": {
            relationshipField : parentID,
            }
        });
    createRecordEvent.fire();
    }