• Kaylee Gray
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
I am attempting to create a lightning component, that is to be used on the quote record page. It's purpose is to calculate a margin percentage ((Total Sales Price - Total Cost)/Total Sales Price)*100. The component should pull in total cost and sales price, but allow the user to adjust the total sales price and/add an amount to the cost (in the case of special order items which do not have a set cost). I have completed the Lightning Comonents and Quick Start: Lightning Component trailheads; I attempted to use pieces I thought I understood from each to create a simple solution that could be used while I apply better-practice/functionality/formatting over-time. My main issue that's got me stumped at this point, is the button doesn't seem to be successfully calling the handler/controller at all, I'm not even getting logs when clicking . As far as getting the values, I know an apex controller can be used to pull data from records, but thought force:recordData would work for what I'm attempting to do (take values, do a calculation, and display from and on current quote record). I also tried assigning my "Margin" a static value via the handler, just to make sure the button was firing, with no success. Clicking the button does nothing regardless of my handler/controller, as far as I can see anyway. Am I missing something or do I just have to take the long road now with the apex controller and more complex setup in the handler/helper etc.?
I have custom fields rolling up the amounts from the line items for Total Sales and Cost.
Code below
MarginCalc.cmp Code
<aura:component implements="force:hasRecordId,force:hasSObjectName,flexipage:availableForRecordHome">
   <!-- <aura:handler name="init" action="{!c.getValues}" value="{!this}"/> -->
    <aura:attribute name="currentQuote" type="Quote"/>
    <aura:attribute name="totalCost" type="Integer" default="{! v.currentQuote.Item_Cost_Total__c}"/>
    <aura:attribute name="margin" type="Integer"/>
    <aura:attribute name="totalCustomerPrice" type="Integer" default="{! v.currentQuote.TotalPrice_Rollup_no_FRT_INS__c}"/>
    <force:recordData aura:id="quoteRecord"
                  recordId="{!v.recordId}"
                  targetFields="{!v.currentQuote}"
                  layoutType="FULL"
                  />

    
    <lightning:card iconName="custom:custom90" title="Margin Calculator" class="slds-text-title_caps">
        <div class="slds-p-left--medium slds-p-right--medium">
        <lightning:layout verticalAlign="stretch" horizontalAlign="start" multipleRows="true" pullToBoundary="small">
            
                <lightning:layoutItem size="11" padding="horizontal-small">
                   <form class="slds-form--stacked">  
                   		<lightning:input aura:id="nsspCostInput" label="Total of Special Order Items Cost"
                             name="nsspCost"
                             value="0"
                             required="false"/> 
                    	<lightning:input aura:id="custPriceTotal" label="Customer's Price Total - Products Only"
                             name="custTotal"
                             value="{! v.currentQuote.TotalPrice_Rollup_no_FRT_INS__c}"/> 
                    </form>
                       
                 <lightning:layoutItem size="11" padding="horizontal-small">
                      <div> 
                          <p>
                            Total Cost: {! v.totalCost}
                           </p>
                      </div>
                  </lightning:layoutItem>
                  <lightning:layoutItem size="11" padding="horizontal-small">
                      <div>
                          <p>
                              Margin: {! v.margin}%
                    	  </p> 
                      </div>
                   </lightning:layoutItem>
                  <lightning:button label="Calculate" onClick="{! c.calculateMargin}"/>
                    
                 </lightning:layoutItem>
            
        </lightning:layout>
        </div>
    </lightning:card>
</aura:component>

Controller/Handler
({    
    calculateMargin : function(component,event,helper){
        var cost = component.get("v.custTotal");
        var addedCost = component.get("v.nsspCost");
        var totalCost = cost+addedCost;
        var price = component.get("v.custPriceTotal");
        var margin = ((price-totalCost)/price)*100;
        component.set("v.totalCost", totalCost);
        component.set("v.margin", margin);
        console.log(cost);
    }
})
Thank you
I am trying to transfer ownership of some 294k account records  to new owners based on the Billing Zip of the account and the owner's store location. We have geolocation setup, it was being used to assign incoming leads similarly (but into queues). My plan was to have a custom field on the accounts populated with the store number of the closest store, then assign owners from there. In order to do this I attempted to utilize the code from the trigger that was assigning leads to the queues, but quickly realized whoever designed it was using a DML statement in a for loop. Below is my new trigger code with the DML still in the loop, I have been trying for a a day or 2 to come up with a way to get the DML out of the for loop and still find the closest store to populate the ReAssignStore__c field, with no luck. Any help is so much appreciated.
Trigger Code:

trigger ReAssignJennTrig on Account (Before insert, Before Update) {
    ApexTrigger testTrigger= [SELECT id, Status, Name FROM ApexTrigger WHERE Name =: 'ReAssignJennTrig'];
         If( testTrigger.Status=='Inactive'){
             return;
         }else
         {
    List<Account> accounts = new List<Account>();
    
    Map<String, ZipToLatLong__c> zipToLatLongMap = new Map<String, ZipToLatLong__c>(); 
    User jenn = [SELECT id FROM User WHERE Name =:'Jenn Morrison'];
             
    for(Account ac : trigger.new){
        if(ac.OwnerID==jenn.id){
            
            accounts.add(ac);
        }
    }
System.debug(accounts.size()+'accounts List size after insert');
    if (accounts.size() > 0){
			// update ziptoLatlong map
			zipToLatLongMap = ZipToLatLong__c.getAll(); 
				
		}
             
    For(Account acct : accounts){
    if (!String.isBlank(String.valueOf(acct.BillingPostalCode)) && // ensure postalcode is not blank
					zipToLatLongMap.containsKey(String.valueOf((acct.BillingPostalCode))) // ensure zip is not missing from the zipToLatLongMap 
				){ 
				Decimal dLat = zipToLatLongMap.get(String.valueOf((acct.BillingPostalCode))).Latitude__c; system.debug(dLat);
				Decimal dLon = zipToLatLongMap.get(String.valueOf((acct.BillingPostalCode))).Longitude__c; system.debug(dLon);
				Store__c[] sList = [SELECT id, name FROM Store__c WHERE DISTANCE(Location__c, GEOLOCATION(:dLat,:dLon),'mi') < 5000 ORDER BY DISTANCE(Location__c, GEOLOCATION(:dLat,:dLon),'mi') LIMIT 1];	
                    
					if (sList.size() == 1){ // Check to see whether a store was returned
	
					acct.ReAssignStore__c = sList[0].name;  // assign lead to store queue
					
				} else { // Assign to generic queue if no store is matched
					acct.ReAssignStore__c = 'none';
				}
                }else {acct.ReAssignStore__c = 'none';} 	
                  
 
		}
	
    }}


Test Code:
@isTest (seeAllData=true)

public class ReAssignJennTEST {
	
       static testMethod void ReAssignTestGoodZip(){
        User jenn = [SELECT id FROM User WHERE Name = 'Jenn Morrison'];
           Account testAct = new Account();
   			String name ='name';
    		String CID = 'TESTCIDNUMB';
        	String Zip ='32202';
        	testAct.Name=name;
       		testAct.Customer_ID__c=CID;
        	testAct.BillingPostalCode=zip;
           testAct.OwnerId = Jenn.id;
        
        test.startTest();
        	insert testAct;
        	Account act = [SELECT id,ReAssignStore__c,CUstomer_id__c,billingpostalcode,Longitude__c,Latitude__c FROM Account WHERE customer_id__c =:'TESTCIDNUMB'];
           System.assertEquals('029',act.ReAssignStore__c);
           
           test.stopTest();
    }
        
     static testMethod void ReAssignTestBadZip(){
        User jenn = [SELECT id FROM User WHERE Name = 'Jenn Morrison'];
           Account testAct = new Account();
   			String name ='name';
    		String CID = 'TESTCIDNUMB';
        	String Zip ='322';
        	testAct.Name=name;
       		testAct.Customer_ID__c=CID;
        	testAct.BillingPostalCode=zip;
        	testAct.OwnerId = Jenn.id;
         
        test.startTest();
        	insert testAct;
        	Account act = [SELECT id,ReAssignStore__c,CUstomer_id__c,billingpostalcode FROM Account WHERE customer_id__c =:'TESTCIDNUMB'];
           System.assertEquals('none',act.ReAssignStore__c);
           test.stopTest();
    }
    
    /*static testMethod void ReAssignTest200(){
        User jenn = [SELECT id FROM User WHERE Name = 'Jenn Morrison'];
           
   			String name ='name';
    		String CID = 'TESTCIDNUMB';
        	String Zip ='32202';
        List<account> accounts200=new List<Account>();
        for(integer i=0;i<100;i++){
            Account testAct = new Account();
        	testAct.Name=name+i;
       		testAct.Customer_ID__c=CID+i;
        	testAct.BillingPostalCode=zip;
        	testAct.OwnerId = Jenn.id;
            accounts200.add(testAct);
        }
        test.startTest();
        	insert accounts200;
        	List<Account> accts = [SELECT id,ReAssignStore__c,CUstomer_id__c,billingpostalcode FROM Account WHERE ReAssignStore__c =:'029'];
           System.assertEquals(100,accts.size());
           test.stopTest();
    }*/
     static testMethod void ReAssignTestNoZip(){
        User jenn = [SELECT id FROM User WHERE Name = 'Jenn Morrison'];
           Account testAct = new Account();
   			String name ='name';
    		String CID = 'TESTCIDNUMB';
        	String Zip ='';
        	testAct.Name=name;
       		testAct.Customer_ID__c=CID;
        	testAct.BillingPostalCode=zip;
        	testAct.OwnerId = Jenn.id;
         
        test.startTest();
        	insert testAct;
        	Account act = [SELECT id,ReAssignStore__c, CUstomer_id__c,billingpostalcode FROM Account WHERE customer_id__c =:'TESTCIDNUMB'];
           System.assertEquals('none',act.ReAssignStore__c);
           test.stopTest();
    }
}
This is for the Apex Specialist Challenge 4. All my tests pass and code coverage is 100%.
I'm getting the error when I check the challenge.
In the debug logs they are checking the following " SOQL_EXECUTE_BEGIN [35]|Aggregations:0|SELECT COUNT() FROM Case WHERE Equipment__c = :tmpVar1" which is giving me  Assertion Failed: Expected: 402, Actual: 602. 

I've read through the log and just can't figure out what's going wrong.

Helper Code:
public class MaintenanceRequestHelper {
    
    public static void updateWorkOrders(List<case>ClosedCaseList){
        // update workorders
        
        list<case> insertCaseList = new list<case>();
        
        for(Case c : ClosedCaseList)
            
            {
                
                Case newCase = new Case();
                integer days = (integer)c.Equipment__r.Maintenance_Cycle__c;
                newCase.Type = 'Routine Maintenance';
                newCase.Status = 'New';
                newCase.Subject =  c.Subject;
                newCase.Date_Reported__c = Date.today();
                if(days != null){
                newCase.Vehicle__c = c.Vehicle__c;
                newCase.Date_Due__c = Date.today().addDays(days);
                newCase.Equipment__c = c.Equipment__c;
                }
                
                insertCaseList.add(newCase);
            }
        
        if(insertCaseList.size()>0){
        insert insertCaseList;
        }
    }
        
}

Trigger:

trigger MaintenanceRequest on Case ( after update) {
    
     List<case>ClosedCaseList = [SELECT Id, Type, Subject, Vehicle__c, Equipment__c, Equipment__r.Maintenance_Cycle__c FROM Case WHERE status = 'Closed'];
  
     List<Case> casesToUpdate = new List<case>();
    
    if(Trigger.isAfter && Trigger.isUpdate){
     for(case c : ClosedCaseList){
        
        if(c.type == 'Repair' || c.type =='Routine Maintenance'){
            
            casesToUpdate.add(c);
        }
    }
    }
    MaintenanceRequestHelper.updateWorkOrders(casesToUpdate);
}


Thanks in advance for any help.
I am attempting to create a lightning component, that is to be used on the quote record page. It's purpose is to calculate a margin percentage ((Total Sales Price - Total Cost)/Total Sales Price)*100. The component should pull in total cost and sales price, but allow the user to adjust the total sales price and/add an amount to the cost (in the case of special order items which do not have a set cost). I have completed the Lightning Comonents and Quick Start: Lightning Component trailheads; I attempted to use pieces I thought I understood from each to create a simple solution that could be used while I apply better-practice/functionality/formatting over-time. My main issue that's got me stumped at this point, is the button doesn't seem to be successfully calling the handler/controller at all, I'm not even getting logs when clicking . As far as getting the values, I know an apex controller can be used to pull data from records, but thought force:recordData would work for what I'm attempting to do (take values, do a calculation, and display from and on current quote record). I also tried assigning my "Margin" a static value via the handler, just to make sure the button was firing, with no success. Clicking the button does nothing regardless of my handler/controller, as far as I can see anyway. Am I missing something or do I just have to take the long road now with the apex controller and more complex setup in the handler/helper etc.?
I have custom fields rolling up the amounts from the line items for Total Sales and Cost.
Code below
MarginCalc.cmp Code
<aura:component implements="force:hasRecordId,force:hasSObjectName,flexipage:availableForRecordHome">
   <!-- <aura:handler name="init" action="{!c.getValues}" value="{!this}"/> -->
    <aura:attribute name="currentQuote" type="Quote"/>
    <aura:attribute name="totalCost" type="Integer" default="{! v.currentQuote.Item_Cost_Total__c}"/>
    <aura:attribute name="margin" type="Integer"/>
    <aura:attribute name="totalCustomerPrice" type="Integer" default="{! v.currentQuote.TotalPrice_Rollup_no_FRT_INS__c}"/>
    <force:recordData aura:id="quoteRecord"
                  recordId="{!v.recordId}"
                  targetFields="{!v.currentQuote}"
                  layoutType="FULL"
                  />

    
    <lightning:card iconName="custom:custom90" title="Margin Calculator" class="slds-text-title_caps">
        <div class="slds-p-left--medium slds-p-right--medium">
        <lightning:layout verticalAlign="stretch" horizontalAlign="start" multipleRows="true" pullToBoundary="small">
            
                <lightning:layoutItem size="11" padding="horizontal-small">
                   <form class="slds-form--stacked">  
                   		<lightning:input aura:id="nsspCostInput" label="Total of Special Order Items Cost"
                             name="nsspCost"
                             value="0"
                             required="false"/> 
                    	<lightning:input aura:id="custPriceTotal" label="Customer's Price Total - Products Only"
                             name="custTotal"
                             value="{! v.currentQuote.TotalPrice_Rollup_no_FRT_INS__c}"/> 
                    </form>
                       
                 <lightning:layoutItem size="11" padding="horizontal-small">
                      <div> 
                          <p>
                            Total Cost: {! v.totalCost}
                           </p>
                      </div>
                  </lightning:layoutItem>
                  <lightning:layoutItem size="11" padding="horizontal-small">
                      <div>
                          <p>
                              Margin: {! v.margin}%
                    	  </p> 
                      </div>
                   </lightning:layoutItem>
                  <lightning:button label="Calculate" onClick="{! c.calculateMargin}"/>
                    
                 </lightning:layoutItem>
            
        </lightning:layout>
        </div>
    </lightning:card>
</aura:component>

Controller/Handler
({    
    calculateMargin : function(component,event,helper){
        var cost = component.get("v.custTotal");
        var addedCost = component.get("v.nsspCost");
        var totalCost = cost+addedCost;
        var price = component.get("v.custPriceTotal");
        var margin = ((price-totalCost)/price)*100;
        component.set("v.totalCost", totalCost);
        component.set("v.margin", margin);
        console.log(cost);
    }
})
Thank you
This is for the Apex Specialist Challenge 4. All my tests pass and code coverage is 100%.
I'm getting the error when I check the challenge.
In the debug logs they are checking the following " SOQL_EXECUTE_BEGIN [35]|Aggregations:0|SELECT COUNT() FROM Case WHERE Equipment__c = :tmpVar1" which is giving me  Assertion Failed: Expected: 402, Actual: 602. 

I've read through the log and just can't figure out what's going wrong.

Helper Code:
public class MaintenanceRequestHelper {
    
    public static void updateWorkOrders(List<case>ClosedCaseList){
        // update workorders
        
        list<case> insertCaseList = new list<case>();
        
        for(Case c : ClosedCaseList)
            
            {
                
                Case newCase = new Case();
                integer days = (integer)c.Equipment__r.Maintenance_Cycle__c;
                newCase.Type = 'Routine Maintenance';
                newCase.Status = 'New';
                newCase.Subject =  c.Subject;
                newCase.Date_Reported__c = Date.today();
                if(days != null){
                newCase.Vehicle__c = c.Vehicle__c;
                newCase.Date_Due__c = Date.today().addDays(days);
                newCase.Equipment__c = c.Equipment__c;
                }
                
                insertCaseList.add(newCase);
            }
        
        if(insertCaseList.size()>0){
        insert insertCaseList;
        }
    }
        
}

Trigger:

trigger MaintenanceRequest on Case ( after update) {
    
     List<case>ClosedCaseList = [SELECT Id, Type, Subject, Vehicle__c, Equipment__c, Equipment__r.Maintenance_Cycle__c FROM Case WHERE status = 'Closed'];
  
     List<Case> casesToUpdate = new List<case>();
    
    if(Trigger.isAfter && Trigger.isUpdate){
     for(case c : ClosedCaseList){
        
        if(c.type == 'Repair' || c.type =='Routine Maintenance'){
            
            casesToUpdate.add(c);
        }
    }
    }
    MaintenanceRequestHelper.updateWorkOrders(casesToUpdate);
}


Thanks in advance for any help.