• Yuki Tan
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hi.
I have a report to sum sales group by month. And i have a formula column which is current month total sales divide by last month sales.
Now i wanna sum they. How can i do that? 

This is my report.
User-added imageMy formula column is :
Case2__c.price__c:SUM/PREVGROUPVAL(Case2__c.price__c:SUM, Case2__c.Complete_Date__c,1)
Hi guys. I have some error with update record in apex class.
I write a datatable and a button in cmp. I wanna select some rows in datatable, and change the field of selected records when i click the button.
My datatable is show a custom object called Case2__c. I wanna change a checkbox field called approvalStatus__c from false to true.
Now, when i click the button, the page haven't response. I write an alert in callback when SUCCESS, page is no alert. When i delete "update cs", page have alert.
There is my code.

Cmp:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="shipClass">
	<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
	<aura:attribute name="columns" type="List"/>
	<aura:attribute name="data" type="Object"/>
	<aura:attribute name="errors" type="Object" default="[]"/>
	<aura:attribute name="selectedCase" type="List"/>

	<lightning:card title="Ship">
	<lightning:layout  multipleRows="true">
		<lightning:layoutItem padding="around-small">
			<lightning:button name="shipButton" label="ship" onclick="{!c.ship}"/>
		</lightning:layoutItem>
	</lightning:layout>
		
		<lightning:datatable
			columns="{! v.columns }"
			data="{! v.data }"
			keyField="Id"
			errors="{! v.errors}"
			onrowselection="{!c.handleSelect}"
			hideCheckboxColumn="false"/>
	</lightning:card>
</aura:component>

 Controller:
({
    doInit : function(component, event, helper) {
    	component.set('v.columns', [
            { label: 'Case No.', fieldName: 'Name', type: 'text',editable:false},
            { label: 'Product', fieldName: 'ProductName', type: 'text',editable:false},
            { label: 'Type', fieldName: 'Customer_Type__c', type: 'text',editable:false},
            { label: 'Account', fieldName: 'AccountName', type: 'text',editable:false},
            { label: 'Amount', fieldName: 'Amount__c', type: 'number',editable:false}]);
    	helper.getShipRecord(component,event,helper); 
    },
    ship : function(component, event, helper){
      var records = component.get("v.selectedCase");
      var action = component.get("c.pass");
      action.setParam("shipList", records);
      action.setCallback(this, function(response){
        var state = response.getState();
        // call back success
        if (state == "SUCCESS"){
          alert('2');

          var a = component.get('c.doInit');
          $A.enqueueAction(a);
        }
        // call back failed
        else {
          var a = component.get('c.doInit');
          $A.enqueueAction(a);
        }
      });
      $A.enqueueAction(action);
    },
    handleSelect : function(component, event, helper){
      var selectedRows = event.getParam('selectedRows');
      var setRows = [];
      for ( var i = 0; i < selectedRows.length; i++ ) {
        setRows.push(selectedRows[i]);
      }
      component.set("v.selectedCase", setRows);
    }
})
Helper:
({
	getShipRecord : function(component, event, helper) {
		var action = component.get("c.query");
        // call back
        action.setCallback(this, function(response){
            var state = response.getState(); 
            // call back success
            if (state == "SUCCESS"){
                var rows = response.getReturnValue();
                for(var i = 0; i < rows.length; i++){
                    var row = rows[i];
                    if(row.Product__r) row.ProductName = row.Product__r.Name;
                    if(row.Account__r) row.AccountName = row.Account__r.Name;
                }
                component.set('v.data', rows);
            }
            // call back failed
            else {
                var toastEvent=$A.get("e.force:showToast");
                toastEvent.setParams({
                    "title":'Error!',
                    "message":'Get Record Failed!',
                    "duration":5000,
                    "type":ERROR
                });
                toastEvent.fire();
            }
        });
        $A.enqueueAction(action);
	}
})

Apex class:
public class shipClass {
    @AuraEnabled
    public static List<Case2__c> query() {
        List<Case2__c> ship = new List<Case2__c>();
        ship = [SELECT Name,Product__r.Name,Account__r.Name,Customer_Type__c,Amount__c FROM Case2__c 
        		WHERE Type__c = 'ship' AND ApprovalStatus__c = false 
        		ORDER BY Account__r.Name ASC];
        return ship;
    }
    @AuraEnabled
    public static void pass(List<Case2__c> shipList) {
    	for(Case2__c a : shipList){
    		List<Case2__c> csList = [SELECT Id,Name,ApprovalStatus__c FROM Case2__c WHERE Name = :a.Name];
    		if(csList.size() > 0){
    			Case2__c cs = csList[0];
    			cs.ApprovalStatus__c = true;
    			update cs;
    		}
    		
    	}
    }
}

How can i fix that. Pls help me. Tanks very much.
 
Hi, i write a code about datatable and apex, but  the result is null.
I have a custome object called Warehouse.It have a relationship field, related to Product object. And a number filed called Amount.
 want to show they in datatable. Now page show null but amount of records is right. And i try to show Name,Type__c , they will show. Just Product__r.Name and Amount__c is null.
Im sure that my SOQL is right.because i run it in develope consle query editor.

This is my code.
cmp:
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
	<aura:attribute name="columns" type="List"/>
	<aura:attribute name="data" type="Object"/>
	<aura:attribute name="errors" type="Object" default="[]"/>

	<lightning:card title="Pending QA">
		<lightning:datatable
			columns="{! v.columns }"
			data="{! v.data }"
			keyField="Id"
			errors="{! v.errors}"
			hideCheckboxColumn="true"/>
	</lightning:card>
controller:
doInit : function(component, event, helper) {
    	component.set('v.columns', [
            { label: 'Product', fieldName: 'Product__r.Name', type: 'text',editable:false},
            { label: 'Amount', fieldName: 'Amount__c', type: 'text',editable:false}]);
    	helper.getPendingRecord(component,event,helper);
    }
Helper:
getPendingRecord : function(component, event, helper) {
		var action = component.get("c.query");
        // call back
        action.setCallback(this, function(response){
            var state = response.getState();
            // call back success
            if (state == "SUCCESS"){
                var result = response.getReturnValue();
                component.set('v.data', result);
            }
            // call back failed
            else {
                var toastEvent=$A.get("e.force:showToast");
                toastEvent.setParams({
                    "title":'Error!',
                    "message":'Get Record Failed!',
                    "duration":5000,
                    "type":ERROR
                });
                toastEvent.fire();
            }
        });
        $A.enqueueAction(action);
	}
class:
public static List<Warehouse__c> query() {
    	List<Warehouse__c> pending = new List<Warehouse__c>();
        pending = [SELECT Product__r.Name,Amount__c FROM Warehouse__c WHERE Type__c = 'pendingArea'];
        return pending;
    }
Pls help me. Thanks!


 
Hi guys. I have some error with update record in apex class.
I write a datatable and a button in cmp. I wanna select some rows in datatable, and change the field of selected records when i click the button.
My datatable is show a custom object called Case2__c. I wanna change a checkbox field called approvalStatus__c from false to true.
Now, when i click the button, the page haven't response. I write an alert in callback when SUCCESS, page is no alert. When i delete "update cs", page have alert.
There is my code.

Cmp:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="shipClass">
	<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
	<aura:attribute name="columns" type="List"/>
	<aura:attribute name="data" type="Object"/>
	<aura:attribute name="errors" type="Object" default="[]"/>
	<aura:attribute name="selectedCase" type="List"/>

	<lightning:card title="Ship">
	<lightning:layout  multipleRows="true">
		<lightning:layoutItem padding="around-small">
			<lightning:button name="shipButton" label="ship" onclick="{!c.ship}"/>
		</lightning:layoutItem>
	</lightning:layout>
		
		<lightning:datatable
			columns="{! v.columns }"
			data="{! v.data }"
			keyField="Id"
			errors="{! v.errors}"
			onrowselection="{!c.handleSelect}"
			hideCheckboxColumn="false"/>
	</lightning:card>
</aura:component>

 Controller:
({
    doInit : function(component, event, helper) {
    	component.set('v.columns', [
            { label: 'Case No.', fieldName: 'Name', type: 'text',editable:false},
            { label: 'Product', fieldName: 'ProductName', type: 'text',editable:false},
            { label: 'Type', fieldName: 'Customer_Type__c', type: 'text',editable:false},
            { label: 'Account', fieldName: 'AccountName', type: 'text',editable:false},
            { label: 'Amount', fieldName: 'Amount__c', type: 'number',editable:false}]);
    	helper.getShipRecord(component,event,helper); 
    },
    ship : function(component, event, helper){
      var records = component.get("v.selectedCase");
      var action = component.get("c.pass");
      action.setParam("shipList", records);
      action.setCallback(this, function(response){
        var state = response.getState();
        // call back success
        if (state == "SUCCESS"){
          alert('2');

          var a = component.get('c.doInit');
          $A.enqueueAction(a);
        }
        // call back failed
        else {
          var a = component.get('c.doInit');
          $A.enqueueAction(a);
        }
      });
      $A.enqueueAction(action);
    },
    handleSelect : function(component, event, helper){
      var selectedRows = event.getParam('selectedRows');
      var setRows = [];
      for ( var i = 0; i < selectedRows.length; i++ ) {
        setRows.push(selectedRows[i]);
      }
      component.set("v.selectedCase", setRows);
    }
})
Helper:
({
	getShipRecord : function(component, event, helper) {
		var action = component.get("c.query");
        // call back
        action.setCallback(this, function(response){
            var state = response.getState(); 
            // call back success
            if (state == "SUCCESS"){
                var rows = response.getReturnValue();
                for(var i = 0; i < rows.length; i++){
                    var row = rows[i];
                    if(row.Product__r) row.ProductName = row.Product__r.Name;
                    if(row.Account__r) row.AccountName = row.Account__r.Name;
                }
                component.set('v.data', rows);
            }
            // call back failed
            else {
                var toastEvent=$A.get("e.force:showToast");
                toastEvent.setParams({
                    "title":'Error!',
                    "message":'Get Record Failed!',
                    "duration":5000,
                    "type":ERROR
                });
                toastEvent.fire();
            }
        });
        $A.enqueueAction(action);
	}
})

Apex class:
public class shipClass {
    @AuraEnabled
    public static List<Case2__c> query() {
        List<Case2__c> ship = new List<Case2__c>();
        ship = [SELECT Name,Product__r.Name,Account__r.Name,Customer_Type__c,Amount__c FROM Case2__c 
        		WHERE Type__c = 'ship' AND ApprovalStatus__c = false 
        		ORDER BY Account__r.Name ASC];
        return ship;
    }
    @AuraEnabled
    public static void pass(List<Case2__c> shipList) {
    	for(Case2__c a : shipList){
    		List<Case2__c> csList = [SELECT Id,Name,ApprovalStatus__c FROM Case2__c WHERE Name = :a.Name];
    		if(csList.size() > 0){
    			Case2__c cs = csList[0];
    			cs.ApprovalStatus__c = true;
    			update cs;
    		}
    		
    	}
    }
}

How can i fix that. Pls help me. Tanks very much.
 
Hi, i write a code about datatable and apex, but  the result is null.
I have a custome object called Warehouse.It have a relationship field, related to Product object. And a number filed called Amount.
 want to show they in datatable. Now page show null but amount of records is right. And i try to show Name,Type__c , they will show. Just Product__r.Name and Amount__c is null.
Im sure that my SOQL is right.because i run it in develope consle query editor.

This is my code.
cmp:
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
	<aura:attribute name="columns" type="List"/>
	<aura:attribute name="data" type="Object"/>
	<aura:attribute name="errors" type="Object" default="[]"/>

	<lightning:card title="Pending QA">
		<lightning:datatable
			columns="{! v.columns }"
			data="{! v.data }"
			keyField="Id"
			errors="{! v.errors}"
			hideCheckboxColumn="true"/>
	</lightning:card>
controller:
doInit : function(component, event, helper) {
    	component.set('v.columns', [
            { label: 'Product', fieldName: 'Product__r.Name', type: 'text',editable:false},
            { label: 'Amount', fieldName: 'Amount__c', type: 'text',editable:false}]);
    	helper.getPendingRecord(component,event,helper);
    }
Helper:
getPendingRecord : function(component, event, helper) {
		var action = component.get("c.query");
        // call back
        action.setCallback(this, function(response){
            var state = response.getState();
            // call back success
            if (state == "SUCCESS"){
                var result = response.getReturnValue();
                component.set('v.data', result);
            }
            // call back failed
            else {
                var toastEvent=$A.get("e.force:showToast");
                toastEvent.setParams({
                    "title":'Error!',
                    "message":'Get Record Failed!',
                    "duration":5000,
                    "type":ERROR
                });
                toastEvent.fire();
            }
        });
        $A.enqueueAction(action);
	}
class:
public static List<Warehouse__c> query() {
    	List<Warehouse__c> pending = new List<Warehouse__c>();
        pending = [SELECT Product__r.Name,Amount__c FROM Warehouse__c WHERE Type__c = 'pendingArea'];
        return pending;
    }
Pls help me. Thanks!


 
Hi, guys

When I did the project named "Build a Discount Approval Process", I could not pass the verification of the step "Prepare Your Org". Then the information I got is "Step not yet complete in My Trailhead Playground 1, Couldn’t find Allison Wheeler with the correct information. Please double check the instructions."

I knew this question probably is not very hard, but I tried to follow that step instruction 3 times, and I got the same error. So I confuse that why what I did is not correct.

Please help me or give me some suggestions about that and I appreciate for your guys help.

Thank you so much. 
  • January 06, 2019
  • Like
  • 0