• Julio Asenjo 16
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

I want my lightning component to display the Brand records which is in related list of the Sports Player Object. My component is displaying the header of the table but not the records and from the lightning component, I want the user to be able to delete a record.
Help will be appreciated.

Thanks in Advance!

Apex Class:

public class SportsApexClass {

     @AuraEnabled
    public static List<Brand__c> getBrandDetails(string recordId) 
    {
        List<Sports_Players__c> SportsPlayersList  =[SELECT id, Name, Last_Name__c, Email__c, Age__c, Speciality__c, Has_the_player_played_internationally__c from Sports_Players__c where id =: recordId ];
        Set<Id> setToQuery = new Set<Id>();
        for(Sports_Players__c bl:SportsPlayersList ){
            setToQuery.add(bl.Id);
        }
        system.debug(SportsPlayersList);
         List<Brand__c> BrandList =[SELECT id, Name, Status__c, Contract_Start_Date__c,Contract_Tenure__c,Contract_Amount__c,Contract_Currency__c,Contract_End_Date__c from Brand__c WHERE id IN : setToQuery];
        
        return BrandList;
        
    }       
}
Component:
<aura:component controller="SportsApexClass"  implements="force:appHostable,force:hasRecordId,flexipage:availableForAllPageTypes" access="global">
    
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute type="Brand__c" name="BrandList"/>
    <aura:attribute name="mycolumns" type="List[]"/>
    <aura:attribute name="data" type="List[]"/>
    <aura:attribute name="recordError" type="String" access="private"/>

    
        <aura:handler name="init" value="{!this}" action="{!c.brandlist}"/>

        <lightning:layoutItem padding="horizontal-small">
        <div class="page-section page-header">
            <h1 class="slds-text-heading--label">Brand Endrosment for players</h1>
        </div>
    </lightning:layoutItem>
    
     <force:recordData aura:id="recordHandler"
        recordId="{!v.recordId}"
        fields="Id"
        targetError="{!v.recordError}"
        recordUpdated="{!c.handleRecordUpdated}" />
    
    <div class="slds-box">
        <div class="slds-grid">
            <div class="slds-col">
                <lightning:datatable data="{! v.data }"
                                     columns="{! v.mycolumns }"
                                     keyField="id"
                                     hideCheckboxColumn="true"/>
                
            </div>
        </div>
    </div>
     
  <div class="Delete Record">
        <lightning:card iconName="action:delete" title="Delete Record">
            <div class="slds-p-horizontal--small">
                <lightning:button label="Delete Record" variant="destructive" onclick="{!c.handleDeleteRecord}"/>
            </div>
        </lightning:card>
    </div>
        
    
    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            {!v.recordError}</div>
     </aura:if>  

    
</aura:component>

Controller:
({
    brandlist : function(component, event, helper) {
        var rid = component.get("v.recordId");
        
        helper.fetchBrandHelper(component, event, helper);
        debugger;
        helper.BrandHelper(component, event, helper);
    },
    handleDeleteRecord: function(component, event, helper) {
        component.find("recordHandler").deleteRecord($A.getCallback(function(deleteResult) {
        }
                                                                   ))},
    
     handleRecordUpdated: function(component, event, helper) {
        var eventParams = event.getParams();
}
                                                                    
                                                                   
})

Helper:
({
    fetchBrandHelper : function(component, event, helper) {
        debugger; 
        component.set('v.mycolumns', [
            {label: 'Brand Name', fieldName: 'Name'},
            {label: 'Status', fieldName: 'Status__c'},
            {label: 'Contract Start Date', fieldName: 'Contract_Start_Date__c'},
            {label: 'Contract Tenure', fieldName: 'Contract_Tenure__c', type: 'number', cellAttributes: { alignment: 'left' }},
            {label: 'Contract Amount', fieldName: 'Contract_Amount__c', type: 'number', cellAttributes: { alignment: 'left' }},
            {label: 'Contract Currency', fieldName: 'Contract_Currency__c', type: 'currency'},
            {label: 'Contract End Date', fieldName: 'Contract_End_Date__c'},
            
            
        ]);
    },
            BrandHelper : function(component, event, helper) {
            var action=component.get('c.getBrandDetails');
             var rec = component.get("v.recordId");
        action.setParams({
            "recordId": rec
        });
            action.setParams({
            });
            action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
            component.set("v.data", response.rec());
            
            }
            });
            $A.enqueueAction(action);
            }
            
            })

            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
 
 
  • October 23, 2020
  • Like
  • 0
Hello,

 I am creating after insert trigger in obj : CMS_Rule__c which checks certain attributes and creates a record for another object MC_Cycle_vod__c . This part is working fine, but I need to map newly created MC_Cycle_vod__c record ID into same object CMS_Rule__c lookup field as CMS_Rule__c  object has a lookup relationship with MC_Cycle_vod__c object. I am stuck here and unable to correctly map newly record ID to correct CMS_Rule__c. Any help would be really apreciated as I can move forward with the code! Please find my code below:

trigger CMS_Create_MC_Cycle on CMS_Rule__c (after Insert) {
List<MC_Cycle_vod__c> cycleList = new List<MC_Cycle_vod__c>();
Map<id,MC_Cycle_vod__c> updatepoaList = new Map<id,MC_Cycle_vod__c>();
List<CMS_Rule__c> poaList = [Select id,CMS_Cycle_Name__c,CMS_Country_Code__c,CMS_MC_Cycle__c,CMS_Cycle_Start_Date__c,CMS_Cycle_End_Date__c FROM CMS_Rule__c WHERE id in: trigger.new and CMS_Status__c='Draft' and CMS_Is_Processed__c=false];
for(CMS_Rule__c rulerec:poaList){
MC_Cycle_vod__c cyclerec = new MC_Cycle_vod__c();
cyclerec.Name=rulerec.CMS_Cycle_Name__c;
cyclerec.CMS_Country_Code__c = rulerec.CMS_Country_Code__c;
cyclerec.Start_Date_vod__c = rulerec.CMS_Cycle_Start_Date__c;
cyclerec.End_Date_vod__c = rulerec.CMS_Cycle_End_Date__c;
cyclerec.Status_vod__c='Planned_vod';
cycleList.add(cyclerec);
}
insert cycleList;
Set<id> mccycleId=new Set<id>();
for(MC_Cycle_vod__c mccycleRec: cycleList){
mccycleId.add(mccycleRec.id); //newly inserted ID i need to map to correct record which is running in for loop
}
}
A developer is creating an enhancement to an application that will allow people to be related to their employer. Which data model provides the simplest solution to meet the requirements?
1. Create a Lookup relationship to indicate that a person has an employer
2. create Master-detail relationship to indicate that a person has an employer