function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
swain 10swain 10 

Please review my test class ,its failing.

Use Case whenever we will select a particular travel request(through lookup) from expense then data
from that travel request (Name + account, related to that travel request) concatenately should
populate Claim purpose field in expense.


public with sharing class DataPopulate {
 public Travel_Request__c trq {

 private ApexPages.StandardController stdCtrl;

 public DataPopulate(ApexPages.StandardController std) {
  stdCtrl = std;

 public void doInsert() {
  Expense__c exp = (Expense__c) stdCtrl.getRecord();
  if (exp.Travel_Request__c == null) {
  } else {
   trq = [select Name , Proposed_Client_to_Visit__r.Name, Status__c from Travel_Request__c where Id =
: exp.Travel_Request__c LIMIT 1];
    System.debug('The record fetched '+trq);
   //exp.Branch__c = trq.Branch__c;
   //exp.Period_To__c = trq.Travel_Start_Date__c;
  // exp.Period_From__c = trq.Travel_End_Date__c;

   exp.Claim_Purpose__c= trq.Name +''+ ' -- '+''+ trq.Proposed_Client_to_Visit__r.Name ;
   upsert exp;
  System.debug('The record insert '+exp);

test class:

//Test class for DataPopulate

public class DataPopulateTest
 //setup test data for Class
 @testSetup  static void testSetDate()
    Travel_Request__c trq = new Travel_Request__c();
    trq.Name='TestTravel' ;
    insert trq;
    Expense__c expObj = new Expense__c();
   // expObj.Period_To__c=;
    insert expObj;
 @isTest static void testPopulate()
    Travel_Request__c trq = [SELECT id from Travel_Request__c where Name = 'TestTravel' ][0];
     ApexPages.StandardController stdCon = new ApexPages.StandardController(trq);
     DataPopulate dClassObj = new  DataPopulate(stdCon);
    // List<Expense__c> expObj=[SELECT Claim_Purpose__c from Expense__c WHERE Limit 1];
    // Boolean result = expObj.equals('TestTravelT-System');
    // System.assertEquals(result,false);
Andy PutraAndy Putra
is it under 75% or got some error?
swain 10swain 10
No its showing just failed but no error in test class while running getting failed.
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi swain,

May I request you to please check for Test Class Generator App from APP Exchange.Please refer the below link. I hope it will be helpful.

Please mark it as best answer if the information is informative.

Best Regards
Rahul Kumar​
Andy PutraAndy Putra
Can you show the error?