• Nilesh C Rathod
  • NEWBIE
  • 30 Points
  • Member since 2015
  • Altimetrik

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I am having  a problem  , i am showing record to the lightning component with checkboxes using the following apex code
public with sharing class bOQrenewClass {
    @AuraEnabled
    public static List<WrapperClass> getproducts() {
        List<WrapperClass> wrapperList = new List<WrapperClass>();
		Map<String, List<SelectedRecordsModel>> stageMap = new Map<String, List<SelectedRecordsModel>>();
       
        
        for(productRenew__c obj: [SELECT Id, Name, Quantity__c, Price__c, Stage__c FROM productRenew__c]){
            stageMap.put(obj.Stage__c, null);           
        }
        
        for(productRenew__c obj: [SELECT Id, Name, Quantity__c, Price__c, Stage__c FROM productRenew__c ORDER BY Stage__c ASC, Name ASC]) {                      
            List<SelectedRecordsModel> prodList = new List<SelectedRecordsModel>();
            
            if (stageMap.get(obj.Stage__c) != null) {
                prodList = stageMap.get(obj.Stage__c);
            }
            
            prodList.add(new SelectedRecordsModel(obj));      
            stageMap.put(obj.Stage__c, prodList);
        }
                    
        for(String obj: stageMap.keyset()){
            WrapperClass wrapperObj = new WrapperClass();
            wrapperObj.Stage = obj;
            wrapperObj.productRenewList = stageMap.get(obj);
            wrapperList.add(wrapperObj);
        }
        
        return wrapperList;
    }
    
   @AuraEnabled
    public static void performAction(List<WrapperClass> positionRecords) {       
       for(WrapperClass obj:positionRecords)
            {
                for(SelectedRecordsModel obj1: obj.productRenewList)
                if(obj1.isSelected)
                {
                    //Play with selected Records here                   
                    system.debug('Selected Record :'+obj1);
                }
            }      
    }
    public class WrapperClass {
        @AuraEnabled String Stage{get; set;}
        @AuraEnabled List<SelectedRecordsModel> productRenewList {get; set;}
        
    }
    public class SelectedRecordsModel {
        @AuraEnabled Boolean isSelected {get;set;}
        @AuraEnabled productRenew__c prd {get;set;}
        
        public SelectedRecordsModel(ProductRenew__c prd){
            this.prd = prd;
            isSelected = false;
        }
    }
}

and here is the component code
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="bOQrenewClass">
    
    <aura:attribute name="wrapperList" type="object[]"/>
    
    
    <aura:handler name="init" value="{! this }" action="{! c.doInit }"/>
    
    <lightning:card  title="xyz">
        <table class="slds-table slds-table_bordered slds-max-medium-table_stacked-horizontal ">
            <thead>
                <tr class="slds-text-title--caps">
                    <th scope="col">
                        <div class="slds-truncate " title="Account Name">SELECT</div>
                    </th>
                    <th scope="col">
                        <div class="slds-truncate  " title="FIRsT Name">PRODUCT</div>
                    </th>
                    <th scope="col">
                        <div class="slds-truncate " title="Account Name">PRICE</div>
                    </th>
                    <th scope="col">
                        <div class="slds-truncate " title="Close Date">QUANTITY</div>
                    </th>
                    <th scope="col">
                        <div class="slds-truncate " title="Stage">TOTAL</div>
                    </th>      
                </tr>
            </thead>
            
            <aura:iteration items="{!v.wrapperList}" var="obj">
                
                <tr class="slds-box slds-theme_shade ">
                    <td colspan="5">{!obj.Stage}</td>
                   
                </tr>
                <tbody>
                <aura:iteration items="{!obj.productRenewList}" var="iobj">
                    <tr class="slds_line_height-small" >
                       <!-- <td><lightning:input type="checkbox"/></td>-->
                        <td><ui:inputCheckbox value="{!iobj.isSelected}"/></td>
                        <td> <ui:outputText value="{!iobj.prd.Name}" /> </td>
                       <!-- <td>{!iobj.prd.Name}</td>
                        <td>{!iobj.prd.Price__c}</td>-->
                         <td> <ui:outputText value="{!iobj.prd.Price__c}" /> </td>
                        <td><lightning:input type="Number" value="{!iobj.Quantity__c}" /></td>
                        <td><ui:outputText value="{!iobj.prd.Price__c * (iobj.prd.Quantity__c !=null ? iobj.prd.Quantity__c : 0)}" /> </td>
                    </tr>
                </aura:iteration>
                </tbody>
            </aura:iteration>
        </table>
         
            
            <lightning:button class="slds-theme_inverse slds-p-horizontal_xx-large"
                              aura:id="expenseform2" label="  SAVE  "
                              name="Mobile"
                              onclick="{!c.searchitems1}"/>    
                  	
    </lightning:card>
    
</aura:component>

here is the jscontroller
({
	
    searchitems1 : function(component, event, helper) {
        
       var selectedRecords = component.get("v.productRenewList");
        console.log(JSON.stringify(selectedRecords));
            var action = component.get("c.performAction");           
            action.setParams({
                positionRecords : selectedRecords
            });
            
           
            action.setCallback(this,function(a){                
                var state = a.getState();                
                if(state == "SUCCESS"){                                       
                    alert('Success in calling server side action');                    
                } else if(state == "ERROR"){
                    alert('Error in calling server side action');
                }
            });
            $A.enqueueAction(action);            
        },
  
    doInit : function(cmp,event,helper){
        //alert('hello');
        
        var action = cmp.get("c.getproducts");
        action.setCallback(this,function(response){
            var state = response.getState();
			//alert(JSON.stringify(response.getReturnValue()));
            if(state == "SUCCESS"){
                cmp.set("v.wrapperList", response.getReturnValue());
            }
            
        });
        $A.enqueueAction(action);
        
       
    }
})

the data is displaying properly on the component but when i select some checkbox and click on save i am not abeling to get those selected records to the debug of the apex method i am getting internal salesforce error for this

what changes should  i make to the code please help
  • September 07, 2018
  • Like
  • 0
I have an Issue with this component. When every Try to submit a new OpportunityLineItem
The component sends the following error messages. 
 
An error occurred while trying to update the record. Please try again.
    ProdConfigCreateOppItem.js:59 undefined
    ProdConfigCreateOppItem.js:60 REQUIRED_FIELD_MISSING
    ProdConfigCreateOppItem.js:61 Required fields are missing: [OpportunityId]
The problem is that I'm actually sending the required fields, also, I've tried Intercepting the request, and adding the fields manually in an `onsubmit` function.
I read the component documentation and no hint about this. 

Any Idea what It's wrong?  
<lightning:recordEditForm
            onload="{!c.handleLoad}"
            onsuccess="{!c.handleSuccess}"
            onerror="{!c.getError}"
            objectApiName="OpportunityLineItem"
            aura:id="createOppItem">
            <lightning:messages />

            <lightning:inputField fieldName="Product2Id" /> 
            <lightning:inputField fieldName="UnitPrice" />
            <lightning:inputField fieldName="Quantity" />
            <lightning:inputField fieldName="ServiceDate" /> 
            <lightning:inputField fieldName="Description" /> 
            <lightning:inputField fieldName="OpportunityId" value="{!v.oppId}"/>
            <div class="slds-m-top_medium">
                <lightning:button variant="brand" type="submit" name="save" label="Add" />
            </div>
    </lightning:recordEditForm>


 
I am having  a problem  , i am showing record to the lightning component with checkboxes using the following apex code
public with sharing class bOQrenewClass {
    @AuraEnabled
    public static List<WrapperClass> getproducts() {
        List<WrapperClass> wrapperList = new List<WrapperClass>();
		Map<String, List<SelectedRecordsModel>> stageMap = new Map<String, List<SelectedRecordsModel>>();
       
        
        for(productRenew__c obj: [SELECT Id, Name, Quantity__c, Price__c, Stage__c FROM productRenew__c]){
            stageMap.put(obj.Stage__c, null);           
        }
        
        for(productRenew__c obj: [SELECT Id, Name, Quantity__c, Price__c, Stage__c FROM productRenew__c ORDER BY Stage__c ASC, Name ASC]) {                      
            List<SelectedRecordsModel> prodList = new List<SelectedRecordsModel>();
            
            if (stageMap.get(obj.Stage__c) != null) {
                prodList = stageMap.get(obj.Stage__c);
            }
            
            prodList.add(new SelectedRecordsModel(obj));      
            stageMap.put(obj.Stage__c, prodList);
        }
                    
        for(String obj: stageMap.keyset()){
            WrapperClass wrapperObj = new WrapperClass();
            wrapperObj.Stage = obj;
            wrapperObj.productRenewList = stageMap.get(obj);
            wrapperList.add(wrapperObj);
        }
        
        return wrapperList;
    }
    
   @AuraEnabled
    public static void performAction(List<WrapperClass> positionRecords) {       
       for(WrapperClass obj:positionRecords)
            {
                for(SelectedRecordsModel obj1: obj.productRenewList)
                if(obj1.isSelected)
                {
                    //Play with selected Records here                   
                    system.debug('Selected Record :'+obj1);
                }
            }      
    }
    public class WrapperClass {
        @AuraEnabled String Stage{get; set;}
        @AuraEnabled List<SelectedRecordsModel> productRenewList {get; set;}
        
    }
    public class SelectedRecordsModel {
        @AuraEnabled Boolean isSelected {get;set;}
        @AuraEnabled productRenew__c prd {get;set;}
        
        public SelectedRecordsModel(ProductRenew__c prd){
            this.prd = prd;
            isSelected = false;
        }
    }
}

and here is the component code
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="bOQrenewClass">
    
    <aura:attribute name="wrapperList" type="object[]"/>
    
    
    <aura:handler name="init" value="{! this }" action="{! c.doInit }"/>
    
    <lightning:card  title="xyz">
        <table class="slds-table slds-table_bordered slds-max-medium-table_stacked-horizontal ">
            <thead>
                <tr class="slds-text-title--caps">
                    <th scope="col">
                        <div class="slds-truncate " title="Account Name">SELECT</div>
                    </th>
                    <th scope="col">
                        <div class="slds-truncate  " title="FIRsT Name">PRODUCT</div>
                    </th>
                    <th scope="col">
                        <div class="slds-truncate " title="Account Name">PRICE</div>
                    </th>
                    <th scope="col">
                        <div class="slds-truncate " title="Close Date">QUANTITY</div>
                    </th>
                    <th scope="col">
                        <div class="slds-truncate " title="Stage">TOTAL</div>
                    </th>      
                </tr>
            </thead>
            
            <aura:iteration items="{!v.wrapperList}" var="obj">
                
                <tr class="slds-box slds-theme_shade ">
                    <td colspan="5">{!obj.Stage}</td>
                   
                </tr>
                <tbody>
                <aura:iteration items="{!obj.productRenewList}" var="iobj">
                    <tr class="slds_line_height-small" >
                       <!-- <td><lightning:input type="checkbox"/></td>-->
                        <td><ui:inputCheckbox value="{!iobj.isSelected}"/></td>
                        <td> <ui:outputText value="{!iobj.prd.Name}" /> </td>
                       <!-- <td>{!iobj.prd.Name}</td>
                        <td>{!iobj.prd.Price__c}</td>-->
                         <td> <ui:outputText value="{!iobj.prd.Price__c}" /> </td>
                        <td><lightning:input type="Number" value="{!iobj.Quantity__c}" /></td>
                        <td><ui:outputText value="{!iobj.prd.Price__c * (iobj.prd.Quantity__c !=null ? iobj.prd.Quantity__c : 0)}" /> </td>
                    </tr>
                </aura:iteration>
                </tbody>
            </aura:iteration>
        </table>
         
            
            <lightning:button class="slds-theme_inverse slds-p-horizontal_xx-large"
                              aura:id="expenseform2" label="  SAVE  "
                              name="Mobile"
                              onclick="{!c.searchitems1}"/>    
                  	
    </lightning:card>
    
</aura:component>

here is the jscontroller
({
	
    searchitems1 : function(component, event, helper) {
        
       var selectedRecords = component.get("v.productRenewList");
        console.log(JSON.stringify(selectedRecords));
            var action = component.get("c.performAction");           
            action.setParams({
                positionRecords : selectedRecords
            });
            
           
            action.setCallback(this,function(a){                
                var state = a.getState();                
                if(state == "SUCCESS"){                                       
                    alert('Success in calling server side action');                    
                } else if(state == "ERROR"){
                    alert('Error in calling server side action');
                }
            });
            $A.enqueueAction(action);            
        },
  
    doInit : function(cmp,event,helper){
        //alert('hello');
        
        var action = cmp.get("c.getproducts");
        action.setCallback(this,function(response){
            var state = response.getState();
			//alert(JSON.stringify(response.getReturnValue()));
            if(state == "SUCCESS"){
                cmp.set("v.wrapperList", response.getReturnValue());
            }
            
        });
        $A.enqueueAction(action);
        
       
    }
})

the data is displaying properly on the component but when i select some checkbox and click on save i am not abeling to get those selected records to the debug of the apex method i am getting internal salesforce error for this

what changes should  i make to the code please help
  • September 07, 2018
  • Like
  • 0