• Bruno Araujo 2
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
how to write 100% test class for Calculator CLass. Unit Testing on the Lightning Platform  Write Negative Tests
1)When user open the system can capture the latitude and longitude of gps in the system
2)When next time they log a call system to validate the location 
I seem to be stuck on this trailhead module or write negative tests unit, while I have 93 percent code coverage, I can't seem to get the code coverage to hit 100 percent at the "returnValue" piece doesn't seem to hit.
My code is as follows.

Calculator Class
 
public class Calculator {
 public class CalculatorException extends Exception{}

  public static Integer addition(Integer a, Integer b){
   return a + b;
    }

   public static Integer subtraction(Integer a, Integer b){
    return a - b;
    }

 public static Integer multiply(Integer a, Integer b){
  if(b==0 || a==0){
  throw new CalculatorException('It doesn\'t make sense to multiply by 
   zero');
  }
  return a * b;
  }

 public static Decimal divide(Integer numerator, Integer denominator){
  if(denominator == 0){
  throw new CalculatorException('you still can\'t divide by zero');
   }
 Decimal returnValue = numerator / denominator;
  if(returnValue < 0){
    throw new CalculatorException('Division returned a negative value.' + 
 returnValue);
 }
   return returnValue;
  }


 }

And my test class as follows
 
@isTest
   public class Calculator_Tests {

@isTest
 public static void addition() {
    Calculator.addition(1, 0);
   }
@isTest
  public static void subtraction() {
    Calculator.subtraction(1, 0);
   }

@isTest
 public static void divide_throws_exception_for_division_by_zero() {
 Boolean caught = false;
 try {
    Calculator.divide(1, 0);
  } catch (Calculator.CalculatorException e) {
    System.assertEquals('you still can\'t divide by zero', e.getMessage(), 
  'caught the right exception');
    caught = true;
   }
   System.assert(caught, 'threw expected exception');
   }

  @isTest
 public static void divide_throws_exception_for_division_by_two() {
 Boolean caught = true;
 try {
    Calculator.divide(1, 2);
 } catch (Calculator.CalculatorException e) {
    System.assertEquals('you still can\'t divide by zero', e.getMessage(), 
  'caught the right exception');
    caught = true;
   }
   System.assert(caught, 'threw expected exception');
 }


@isTest
public static void multiply_by_one() {
  Boolean caught = false;
  try {
    Calculator.multiply(1, 0);
    } catch (Calculator.CalculatorException e) {
    System.assertEquals('It doesn\'t make sense to multiply by zero', 
    e.getMessage(), 'caught the right exception');
     caught = true;
    }
    System.assert(caught, 'threw expected exception');
  }

@isTest
 public static void multiply_by_two() {
  Boolean caught = true;
  try {
     Calculator.multiply(1, 2);
   } catch (Calculator.CalculatorException e) {
    System.assertEquals('It doesn\'t make sense to multiply by zero', 
  e.getMessage(), 'caught the right exception');
    caught = true;
   }
   System.assert(caught, 'threw expected exception');
}   
}

 
I have setup a lightning detail page in the lightning app builder and made it my org wide default page.  On the opportunity object setup page for button and links, there is a Visualforce page on the View that is set as the override page. In the screenshot bvelow you can see my setup.   When i go to my iPhone app and navigate to an opportunity it still shows the visualforce page?  I thought the Lightning Experience Override would allow me to see the Lightning page on my mobile device? I

Is there anyway to remove the visualforce page from the View override and give certain users access to that visualforce page via apex, etc? 

User-added image
  • November 08, 2018
  • Like
  • 0
Need Ideas for my college project on Restaurant Point of Sale..I mean my intention is to use salesforce lightning,Apex programming to achieve below features in my dev org.

Can anyone suggest me what should be my approach to achieve below functionalities namely A),B) and C) below,if you can go detailed steps,would be really grateful.Want to keep this thread a living document for others who wish to develop such project in future.

A) Inventory management:
-->Here i want to manage ingredient level inventory in real-time and start restocking at the right levels

B) Online Ordering:
-->Here i want customer can send order tickets straight to the kitchen

C) Table Management:
-->Here i want on-table ordering that allows restaurant customers to order food from android phone
-->Give feedback right from the table without having to wait for restaurant staff
 
I have forgotten my trail-head password and also the answer for the security question. I can still login using my salesforce account but I need that trailhead password to login from soap UI so i can complete the challenge . Can someone please help me to reset the password.
Its asking me to contact system administrator but i am the admin so i dont know whom to contact.
Learning Salesforce DX, have downloaded the DreamHouse project from gitHub site, made a new branch of my own.  Then, in the Unit of "Create and Test Our Scratch Org", at the beginning, it says "Enter cat config/project-scratch-def.json" to see some of the options available. When I did this in the command line, I got "cat not recognized as an internal or external command".  Online articles say that "cat" is a Unix code, can't be used in Windows system.  Now, my question is what should I use in Windows?

Thanks!
Hello,

Test coverage at 80% and I cant figure out why. Red highlight on Line 11 "return result;" GET request is working fine in workbench.

Account manager class:
 
@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {

    @HttpGet
    global static Account getAccount() {
        RestRequest request = RestContext.request;
        // grab the accountId from the end of the URL
        String accountId = request.requestURI.substringBetween('Accounts/', '/contacts');
        Account result = [SELECT ID,Name,(SELECT ID,Name FROM Contacts) FROM Account WHERE Id = :accountId ];
        system.debug(result);
        return result;
        
    }
}
Test Class:
 
@IsTest
private class AccountManagerTest {

    @isTest static void testGetAccount() {
        Id recordId = createTestRecord();
        // Set up a test request
        RestRequest request = new RestRequest();
        request.requestUri =
            'https://na1.salesforce.com/services/apexrest/Accounts/'+ recordId+'/Contacts';
        request.httpMethod = 'GET';
        RestContext.request = request;
        // Call the method to test
        Account thisAccount = AccountManager.getAccount();
        // Verify results
        System.assert(thisAccount != null);
        System.assertEquals('Test record', thisAccount.Name);
    }

   

    // Helper method
    static Id createTestRecord() {
        // Create test record
        Account accountTest = new Account(
        Name='Test record');
        insert accountTest;
       
        Contact con1 = new Contact(
        AccountId = accountTest.Id,
        firstName = 'test',
        lastName  =  'tester');
        insert con1;
        return accountTest.Id;
    }          

}


 
I am working with the Agile Accelerator applicatin with Salesforce. Is there any way for me to customize the sprint page such as making the categories: Sprint Backlog, In Progress, Internal Testing, External Testing, Approved. I am only wanting to customize the Sprinti page.

Still learning the ropes here and probably have some very ill formed code - so, any help/advice is greatly appreciated.

 

Here is the scenario of what I am trying to accomplish:

 

We have two custom objects (related via lookup field on Essay object):  Applications & Essays.  I have created a custom field on the Applications object called XEssays_On_File.  When an Essay record is added/updated, I would like the XEssays_On_File field to get updated with the number of related Essay Records. (Can't use rollup fields as this is not a master-detail relationship)

 

I have drafted the following code - which works for single situations - but fails mercilessly in bulk update:

 

trigger CountRelatedEssays on TargetX_SRMb__Essay__c (after insert, after update) {

        TargetX_SRMb__Essay__c [] ess = Trigger.new;
        String appid = null;
        appid = ess[0].TargetX_SRMb__Application__c;
       
        Integer i = [select count() from TargetX_SRMb__Essay__c where TargetX_SRMb__Application__c =     :appid];
       
        TargetX_SRMb__Application__c [] app =[select id, XEssays_On_File__c from TargetX_SRMb__Application__c where id = :appid];

        app[0].XEssays_On_File__c = i;   
       
        update app[0];
       

}

 

I would also like this to fire and update on Delete as well.

 

Thanks in advance for any help you can provide!