• FreddyS
  • NEWBIE
  • 45 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 6
    Replies
Hello, can someone point me in the right direction on writing a test class for this apex controller (for a lightning component DataTable). Below is my controller and test class so far. My test class is covering 55% and covers the getRecords soql method but I cannot get the test class to cover the update list method (database.update).

The objects parent, child, and grandchild are in masterdetil relationships and require lookups to one another so there will always be a parent, child, and grandchild in the data model. 

Thanks so much!
 
Controller: 

public class LightningDataTableCtrl {
    @AuraEnabled    
    public static List <grandchild__c> getRecords (String parentId) {   
        List <grandchild__c> updatedObjList = 
            [SELECT Id,
             Name,
             Text_Formula__c,
             Status_Picklist__c,
             Hours_Number_Field__c,
             Custom_Lookup__c,
             Number_Field__c,
             Number_Field_2__c,
             Custom_Picklist__c
             FROM grandchild__c
             WHERE child__r.parent__c = :parentId
             ORDER BY Name ASC];
        return updatedObjList;
    }    
    @AuraEnabled    
    public static void updateRecords( List <grandchild__c> updatedObjList ) {    
        try {  
            Database.update (updatedObjList); 
            
        } catch(Exception e) {  
            
        }  
    }  
}

Test Class: 

@isTest
public class LightningDataTableCtrlTest {
    @isTest (SeeAllData = 'true') static void testGetRecords() {
       
        parent__c parent = new parent__c(Name = 'Lightning Data Table Apex Test', 
                                                                          parent_type_picklist__c = 'Duration');
        insert parent;
        
        child__c child = new child__c(Name = 'Apex Test Phase', 
                                                                                    parent__c = parent.Id);
        insert phase;
        
        grandchild__c grandchild = new grandchild__c(Name = 'Apex Test Task',
                                                                                 child__c = child.Id,
                                                                                 Number_field__c = 1, 
                                                                                 Date_field__c = Date.newInstance(2018, 4, 27),
                                                                                 Number_Field_2__c = 1);
        insert task;
        // List covers the soql and 'getRecords' method of the class.
        List <grandchild__c> getRecords = LightningDataTableCtrl.getRecords(granchild.id);
        
        // Test method to cover update method in controller        
    }
}

 
Hey! can someone help point me in the right direction onn how to pre-populate this custom lookup component based on the account record page its on? If I put this component on account lightning pages, I would like the component to be populated with the account name from the current record! Thanks everyone!
http://sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/
Hi all!
Im stuck on this problem with a custom lightning lookup component. I used the link below as a guide to create a custom lookup component where I can search for records with any object. 

Using the blog below, how can I prepopulate the lookup component based on the current record its on? For example, if i make this component code for code from the link below and the lookup is for the Account object, how can I prepopulate the lookup if I put this component on the account lightning page? This is tricky for me and I'm sure someone out there can help me as they know more about how lightning components work!

Thanks in advance to those who are willing to point me in the right direction!! 

http://sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/
Hi,

Im trying to create a visualforce email template that shows a parent object's sum of hours from child records. I have a parent and a child in a lookup relationship where the child has a field Hours__c number field. How do I get the sum of total hours and group by the parent records? I.E. show total hours by Task and then the grand total of hours for all tasks?

Thanks in advance!
Hello all,
I have a tricky situation that I am stuck on. Ill try to explain this al best I can. So to start, I have 4 custom objects that I'm working with. 1. Task, 2. Allocation Summary, 3.Allocation Group,and  4.Allocation. Allocation is in a master detail with Allocation Group. Allocation Group has a master detail with Allocation Summary and Allocation Summary is in a lookup with Task. So in order from parent to child (Top to bottom) the objects go like this: Task is the very top, then Allocation Summary then Allocation Group and finally Allocation. 

Here is the scenario:
I have a formula on Allocation that pull the Task ID from Allocation Summary. (Text formula field)
Allocation looks up to User. 
1. I need to get a list of Task records based on Allocation and what user is on that Allocation record. So If I have two Allocation records one with bob and Task ID "xxxxxxxxxxxxx" and another with Joe with task ID "yyyyyyyyyyyyyy", have an apex controller (for visualforce page) to get the list of Tasks grouped by the user on the Allocation record. 

My overall goal is to create a visualforce page with a controller that shows a list of Tasks by the current logged in user so they can see the Tasks they are allocated to and no one elses. My thought was to somehow find all task records that match the text formula returning task ID's and get the task record infomation from there. 

(((((Does anyone know how to use an Apex controller to get a list of records that match a text formula returning ID's. )))))
So I am trying to validate time entrys in quarter hour increments. Ex, 1, 1.25 = 1:15, 1.5 = 1:30, 1.75 = 1:45.
I have everything figured out, but when I try to enter a whole number like 1 or 2 or 3, I get an error. Below is my VR and its the fourth line that needs fixing in order to allow me to enter in a whole number. 


AND( 
IF(VALUE(RIGHT(TEXT(project_cloud__Hours__c), 3)) <> 0.25, True, False), 
IF(VALUE(RIGHT(TEXT(project_cloud__Hours__c), 2)) <> 0.50, True, False), 
IF(VALUE(RIGHT(TEXT(project_cloud__Hours__c), 3)) <> 0.75, True, False), 
IF(VALUE(RIGHT(TEXT(project_cloud__Hours__c), 3)) <> 0.00, True, False) 
)
Today I built this pretty basic stopwatch visualforce page. I made it in a dev org and then once I was finished, I wanted to put it into a sandbox for a clients org. The code ran perfectly fine in my dev org, but when I put it in the sandbox, i went to preview it and the page went blank and the URL was "Not secure". Why am I getting this? How can I get around "unsecure" script? Does this page just not work in sandboxes?

here is my code: 
Visualforce Page:
<apex:page lightningStylesheets="false">
    <html>
  <head>
    <title>Timecard Stopwatch</title>
      <apex:slds />
      <meta name="viewport" content="width=device-width"/>
    <script src="http://fb.me/react-0.13.1.js"></script>
    <script src="http://fb.me/JSXTransformer-0.13.1.js"></script>
  </head>
                 
  <body style="background-color:white;">
  <script type="text/jsx">
    var StopWatch = React.createClass({
      getInitialState: function() {
        return {
          isStart: false,
          elapsed: 0,
          diff: 0,
          laps: [],
        };
      },
      componentWillUnmount: function() { // clear timer
        clearInterval(this.state.timer);
        this.setState({timer: undefined});
      },
      tick: function() {
        var elapsed = Date.now() - this.state.start + this.state.diff;
        this.setState({elapsed: elapsed});
      },
      getTimeSpan: function(elapsed) { // 754567(ms) -> "12:34.567"
        var m = String(Math.floor(elapsed/1000/60)+100).substring(1);
        var s = String(Math.floor((elapsed%(1000*60))/1000)+100).substring(1);
        var ms = String(elapsed % 1000 + 1000).substring(1);
        return m+":"+s+"."+ms;
      },
      onClick: function() {
        if(!this.state.isStart) { // start
          var timer = setInterval(this.tick, 33);
          this.setState({
            isStart: true,
            timer: timer,
            start: new Date(),
          });
        } else { // pause
          clearInterval(this.state.timer);
          this.setState({
            timer: undefined,
            isStart: false,
            diff: this.state.elapsed,
          });
        }
      },
      setLap: function() {
        var lapElapsed = this.state.laps.length ? this.state.laps[0].elapsed : 0;
        var lapTitle = "Lap"+(this.state.laps.length+1);
        var lapTime = lapTitle+": "+this.getTimeSpan(this.state.elapsed - lapElapsed)
        var lapElem = { label: lapTime, elapsed: this.state.elapsed };
        this.setState({laps: [lapElem].concat(this.state.laps)});
      },
      reset: function() {
        clearInterval(this.state.timer);
        this.setState({
          timer: undefined,
          isStart: false,
          elapsed: 0,
          diff: 0,
          laps: [],
        });
      },
      render: function() {
        return (
          <div class="slds-scope">
            <h1>{this.getTimeSpan(this.state.elapsed)}</h1>
            <button onClick={this.onClick} style={style.button}>
              {this.state.isStart ? "pause" : "start"}
            </button>
            <button onClick={this.setLap} style={style.button}>lap</button>
            <button onClick={this.reset} style={style.button}>reset</button>
            <ul style={style.lap}>
              {this.state.laps.map(function(lap) {
                return <li key={lap.id}>{lap.label}</li>;
              })}
            </ul>
          </div>
        );
      }
    });
 
    var style = {
      button: {
        fontSize: 15,
        height: 40,
        width: 60,
        margin: 10,
        background: "#F7941D",
        border: "3px",
         
      },
      lap: {
        fontSize: 20,
        padding: 10,
        listStyleType: 'circle',
      },
    
    };
 
    React.render( <StopWatch />, document.body );
  </script>
  </body>
</html>
</apex:page>
So I am trying to validate time entrys in quarter hour increments. Ex, 1, 1.25 = 1:15, 1.5 = 1:30, 1.75 = 1:45.
I have everything figured out, but when I try to enter a whole number like 1 or 2 or 3, I get an error. Below is my VR and its the fourth line that needs fixing in order to allow me to enter in a whole number. 


AND( 
IF(VALUE(RIGHT(TEXT(project_cloud__Hours__c), 3)) <> 0.25, True, False), 
IF(VALUE(RIGHT(TEXT(project_cloud__Hours__c), 2)) <> 0.50, True, False), 
IF(VALUE(RIGHT(TEXT(project_cloud__Hours__c), 3)) <> 0.75, True, False), 
IF(VALUE(RIGHT(TEXT(project_cloud__Hours__c), 3)) <> 0.00, True, False) 
)
Hello, can someone point me in the right direction on writing a test class for this apex controller (for a lightning component DataTable). Below is my controller and test class so far. My test class is covering 55% and covers the getRecords soql method but I cannot get the test class to cover the update list method (database.update).

The objects parent, child, and grandchild are in masterdetil relationships and require lookups to one another so there will always be a parent, child, and grandchild in the data model. 

Thanks so much!
 
Controller: 

public class LightningDataTableCtrl {
    @AuraEnabled    
    public static List <grandchild__c> getRecords (String parentId) {   
        List <grandchild__c> updatedObjList = 
            [SELECT Id,
             Name,
             Text_Formula__c,
             Status_Picklist__c,
             Hours_Number_Field__c,
             Custom_Lookup__c,
             Number_Field__c,
             Number_Field_2__c,
             Custom_Picklist__c
             FROM grandchild__c
             WHERE child__r.parent__c = :parentId
             ORDER BY Name ASC];
        return updatedObjList;
    }    
    @AuraEnabled    
    public static void updateRecords( List <grandchild__c> updatedObjList ) {    
        try {  
            Database.update (updatedObjList); 
            
        } catch(Exception e) {  
            
        }  
    }  
}

Test Class: 

@isTest
public class LightningDataTableCtrlTest {
    @isTest (SeeAllData = 'true') static void testGetRecords() {
       
        parent__c parent = new parent__c(Name = 'Lightning Data Table Apex Test', 
                                                                          parent_type_picklist__c = 'Duration');
        insert parent;
        
        child__c child = new child__c(Name = 'Apex Test Phase', 
                                                                                    parent__c = parent.Id);
        insert phase;
        
        grandchild__c grandchild = new grandchild__c(Name = 'Apex Test Task',
                                                                                 child__c = child.Id,
                                                                                 Number_field__c = 1, 
                                                                                 Date_field__c = Date.newInstance(2018, 4, 27),
                                                                                 Number_Field_2__c = 1);
        insert task;
        // List covers the soql and 'getRecords' method of the class.
        List <grandchild__c> getRecords = LightningDataTableCtrl.getRecords(granchild.id);
        
        // Test method to cover update method in controller        
    }
}

 
Hey! can someone help point me in the right direction onn how to pre-populate this custom lookup component based on the account record page its on? If I put this component on account lightning pages, I would like the component to be populated with the account name from the current record! Thanks everyone!
http://sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/
Hi all!
Im stuck on this problem with a custom lightning lookup component. I used the link below as a guide to create a custom lookup component where I can search for records with any object. 

Using the blog below, how can I prepopulate the lookup component based on the current record its on? For example, if i make this component code for code from the link below and the lookup is for the Account object, how can I prepopulate the lookup if I put this component on the account lightning page? This is tricky for me and I'm sure someone out there can help me as they know more about how lightning components work!

Thanks in advance to those who are willing to point me in the right direction!! 

http://sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/
Hi,

Im trying to create a visualforce email template that shows a parent object's sum of hours from child records. I have a parent and a child in a lookup relationship where the child has a field Hours__c number field. How do I get the sum of total hours and group by the parent records? I.E. show total hours by Task and then the grand total of hours for all tasks?

Thanks in advance!
Today I built this pretty basic stopwatch visualforce page. I made it in a dev org and then once I was finished, I wanted to put it into a sandbox for a clients org. The code ran perfectly fine in my dev org, but when I put it in the sandbox, i went to preview it and the page went blank and the URL was "Not secure". Why am I getting this? How can I get around "unsecure" script? Does this page just not work in sandboxes?

here is my code: 
Visualforce Page:
<apex:page lightningStylesheets="false">
    <html>
  <head>
    <title>Timecard Stopwatch</title>
      <apex:slds />
      <meta name="viewport" content="width=device-width"/>
    <script src="http://fb.me/react-0.13.1.js"></script>
    <script src="http://fb.me/JSXTransformer-0.13.1.js"></script>
  </head>
                 
  <body style="background-color:white;">
  <script type="text/jsx">
    var StopWatch = React.createClass({
      getInitialState: function() {
        return {
          isStart: false,
          elapsed: 0,
          diff: 0,
          laps: [],
        };
      },
      componentWillUnmount: function() { // clear timer
        clearInterval(this.state.timer);
        this.setState({timer: undefined});
      },
      tick: function() {
        var elapsed = Date.now() - this.state.start + this.state.diff;
        this.setState({elapsed: elapsed});
      },
      getTimeSpan: function(elapsed) { // 754567(ms) -> "12:34.567"
        var m = String(Math.floor(elapsed/1000/60)+100).substring(1);
        var s = String(Math.floor((elapsed%(1000*60))/1000)+100).substring(1);
        var ms = String(elapsed % 1000 + 1000).substring(1);
        return m+":"+s+"."+ms;
      },
      onClick: function() {
        if(!this.state.isStart) { // start
          var timer = setInterval(this.tick, 33);
          this.setState({
            isStart: true,
            timer: timer,
            start: new Date(),
          });
        } else { // pause
          clearInterval(this.state.timer);
          this.setState({
            timer: undefined,
            isStart: false,
            diff: this.state.elapsed,
          });
        }
      },
      setLap: function() {
        var lapElapsed = this.state.laps.length ? this.state.laps[0].elapsed : 0;
        var lapTitle = "Lap"+(this.state.laps.length+1);
        var lapTime = lapTitle+": "+this.getTimeSpan(this.state.elapsed - lapElapsed)
        var lapElem = { label: lapTime, elapsed: this.state.elapsed };
        this.setState({laps: [lapElem].concat(this.state.laps)});
      },
      reset: function() {
        clearInterval(this.state.timer);
        this.setState({
          timer: undefined,
          isStart: false,
          elapsed: 0,
          diff: 0,
          laps: [],
        });
      },
      render: function() {
        return (
          <div class="slds-scope">
            <h1>{this.getTimeSpan(this.state.elapsed)}</h1>
            <button onClick={this.onClick} style={style.button}>
              {this.state.isStart ? "pause" : "start"}
            </button>
            <button onClick={this.setLap} style={style.button}>lap</button>
            <button onClick={this.reset} style={style.button}>reset</button>
            <ul style={style.lap}>
              {this.state.laps.map(function(lap) {
                return <li key={lap.id}>{lap.label}</li>;
              })}
            </ul>
          </div>
        );
      }
    });
 
    var style = {
      button: {
        fontSize: 15,
        height: 40,
        width: 60,
        margin: 10,
        background: "#F7941D",
        border: "3px",
         
      },
      lap: {
        fontSize: 20,
        padding: 10,
        listStyleType: 'circle',
      },
    
    };
 
    React.render( <StopWatch />, document.body );
  </script>
  </body>
</html>
</apex:page>