+ Start a Discussion
santhosh konathala 17santhosh konathala 17 

I am new to Apex coding plz help me how to write a Test class for below Trigger?

trigger AccountAvoidDuplicate on account(before insert,before update)
{

set<string> set1=new set<string>();
for(account acc:[select id,name from account])
{

set1.add(acc.name);
}

for(account var:Trigger.new)
{
if(var.name!=null)
{
if(set1.contains(var.name))
{
var.adderror('plz insert unique values');
}

}
}
}
Best Answer chosen by santhosh konathala 17
Amit Chaudhary 8Amit Chaudhary 8
Hi Santhosh,

I found some issue in your trigger

You are fetching All Account record that is not good as per best pratice your code will fail if you have more then 10K record in Account object.
Try to change your code like below
trigger AccountAvoidDuplicate on account(before insert,before update)
{
	Set<String> setName = new Set<String>();
	Set<String> setID = new Set<String>();
	
	for(Account acc :  Trigger.New)
	{
		setName.add(acc.Name);
		setID.add(acc.id);
	}
	
	Map<String,Account> mapAccount = new Map<String,Account>();
	
	for( Account acc:[select id,name from account where name in :setName and id not in :setID ] )
	{
		mapAccount.put(acc.name , acc );
	}

	for(account var:Trigger.new)
	{
		if(var.name!=null)
		{
			if( mapAccount.containsKey(var.name) )
			{
				var.adderror('plz insert unique values');
			}
		}
	}
}

Your test class should be  like below
@isTest 
public class testClass 
{
    static testMethod void insertNewAccount() 
	{
       
		account acc = new account();
			acc.name = 'test';
		insert acc;
		
		Test.startTest();
		
			account accc = new account();
			accc.Name = 'test';
			
			try
			{
				insert accc;
			}
			Catch(Exception ee)
			{
				Boolean expectedExceptionThrown =  e.getMessage().contains('plz insert unique values')) ? true : false;
				System.AssertEquals(expectedExceptionThrown, true);
			}
			
		Test.stopTest();
    }
}
Please check below post to learn about test classes
1) http://amitsalesforce.blogspot.com/search/label/Test%20Class
2) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html


Please follow below salesforce Best Practice for Test Classes :-

1. Test class must start with @isTest annotation if class class version is more than 25
2. Test environment support @testVisible , @testSetUp as well
3. Unit test is to test particular piece of code working properly or not .
4. Unit test method takes no argument ,commit no data to database ,send no email ,flagged with testMethod keyword .
5. To deploy to production at-least 75% code coverage is required 
6. System.debug statement are not counted as a part of apex code limit.
7. Test method and test classes are not counted as a part of code limit
9. We should not focus on the  percentage of code coverage ,we should make sure that every use case should covered including positive, negative,bulk and single record .
Single Action -To verify that the the single record produces the correct an expected result .
Bulk action -Any apex record trigger ,class or extension must be invoked for 1-200 records .
Positive behavior : Test every expected behavior occurs through every expected permutation , i,e user filled out every correctly data and not go past the limit .
Negative Testcase :-Not to add future date , Not to specify negative amount.
Restricted User :-Test whether a user with restricted access used in your code .
10. Test class should be annotated with @isTest .
11 . @isTest annotation with test method  is equivalent to testMethod keyword .
12. Test method should static and no void return type .
13. Test class and method default access is private ,no matter to add access specifier .
14. classes with @isTest annotation can't be a interface or enum .
15. Test method code can't be invoked by non test request .
16. Stating with salesforce API 28.0 test method can not reside inside non test classes .
17. @Testvisible annotation to make visible private methods inside test classes.
18. Test method can not be used to test web-service call out . Please use call out mock .
19. You can't  send email from test method.
20.User, profile, organization, AsyncApexjob, Corntrigger, RecordType, ApexClass, ApexComponent ,ApexPage we can access without (seeAllData=true) .
21. SeeAllData=true will not work for API 23 version eailer .
22. Accessing static resource test records in test class e,g List<Account> accList=Test.loadData(Account,SobjectType,'ResourceName').
23. Create TestFactory class with @isTest annotation to exclude from organization code size limit .
24. @testSetup to create test records once in a method  and use in every test method in the test class .
25. We can run unit test by using Salesforce Standard UI,Force.com IDE ,Console ,API.
26. Maximum number of test classes run per 24 hour of period is  not grater of 500 or 10 multiplication of test classes of your organization.
27. As apex runs in system mode so the permission and record sharing are not taken into account . So we need to use system.runAs to enforce record sharing .
28. System.runAs will not enforce user permission or field level permission .
29. Every test to runAs count against the total number of DML issued in the process .


Please let us know if this post will help you
 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi santosh
try this for 100% code cover
@isTest 
public class testClass {
    static testMethod void insertNewAccount() {
       
       account acc = new account();
       // Do you recognize these fields?
        acc.name = 'test';
       insert acc;
        account accc = new account();
        accc.Name = 'test';
        insert accc;
        
    }
}
Thanks
 
sfdcMonkey.comsfdcMonkey.com
Please let me inform if any issue with it or it helps you Mark it best asnwer :)
santhosh konathala 17santhosh konathala 17
Hi Soni,

Your Test class covered 100% code coverage.I have a small doubt,In tha above test class we have not used Test.starttest()&test.stoptest() methods and also we have not used atleast one assert statement.then how it possible to get 100% code coverage.
sfdcMonkey.comsfdcMonkey.com
hi santhosha its a very basic trigger so we have no need to use these statements
if you are new to learn test class here is a link for beginners that how to write a test class
and when you run this test class first insert a account with name test again we insert a account with same name test(duplicate) so it giveing error on real time when trigger is fire . so your trigger code cover succesully 
http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
i hop its helps you :)
Thanks
santhosh konathala 17santhosh konathala 17
Hi Soni,

Thanks a lot for the reply..
Amit Chaudhary 8Amit Chaudhary 8
Hi Santhosh,

I found some issue in your trigger

You are fetching All Account record that is not good as per best pratice your code will fail if you have more then 10K record in Account object.
Try to change your code like below
trigger AccountAvoidDuplicate on account(before insert,before update)
{
	Set<String> setName = new Set<String>();
	Set<String> setID = new Set<String>();
	
	for(Account acc :  Trigger.New)
	{
		setName.add(acc.Name);
		setID.add(acc.id);
	}
	
	Map<String,Account> mapAccount = new Map<String,Account>();
	
	for( Account acc:[select id,name from account where name in :setName and id not in :setID ] )
	{
		mapAccount.put(acc.name , acc );
	}

	for(account var:Trigger.new)
	{
		if(var.name!=null)
		{
			if( mapAccount.containsKey(var.name) )
			{
				var.adderror('plz insert unique values');
			}
		}
	}
}

Your test class should be  like below
@isTest 
public class testClass 
{
    static testMethod void insertNewAccount() 
	{
       
		account acc = new account();
			acc.name = 'test';
		insert acc;
		
		Test.startTest();
		
			account accc = new account();
			accc.Name = 'test';
			
			try
			{
				insert accc;
			}
			Catch(Exception ee)
			{
				Boolean expectedExceptionThrown =  e.getMessage().contains('plz insert unique values')) ? true : false;
				System.AssertEquals(expectedExceptionThrown, true);
			}
			
		Test.stopTest();
    }
}
Please check below post to learn about test classes
1) http://amitsalesforce.blogspot.com/search/label/Test%20Class
2) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html


Please follow below salesforce Best Practice for Test Classes :-

1. Test class must start with @isTest annotation if class class version is more than 25
2. Test environment support @testVisible , @testSetUp as well
3. Unit test is to test particular piece of code working properly or not .
4. Unit test method takes no argument ,commit no data to database ,send no email ,flagged with testMethod keyword .
5. To deploy to production at-least 75% code coverage is required 
6. System.debug statement are not counted as a part of apex code limit.
7. Test method and test classes are not counted as a part of code limit
9. We should not focus on the  percentage of code coverage ,we should make sure that every use case should covered including positive, negative,bulk and single record .
Single Action -To verify that the the single record produces the correct an expected result .
Bulk action -Any apex record trigger ,class or extension must be invoked for 1-200 records .
Positive behavior : Test every expected behavior occurs through every expected permutation , i,e user filled out every correctly data and not go past the limit .
Negative Testcase :-Not to add future date , Not to specify negative amount.
Restricted User :-Test whether a user with restricted access used in your code .
10. Test class should be annotated with @isTest .
11 . @isTest annotation with test method  is equivalent to testMethod keyword .
12. Test method should static and no void return type .
13. Test class and method default access is private ,no matter to add access specifier .
14. classes with @isTest annotation can't be a interface or enum .
15. Test method code can't be invoked by non test request .
16. Stating with salesforce API 28.0 test method can not reside inside non test classes .
17. @Testvisible annotation to make visible private methods inside test classes.
18. Test method can not be used to test web-service call out . Please use call out mock .
19. You can't  send email from test method.
20.User, profile, organization, AsyncApexjob, Corntrigger, RecordType, ApexClass, ApexComponent ,ApexPage we can access without (seeAllData=true) .
21. SeeAllData=true will not work for API 23 version eailer .
22. Accessing static resource test records in test class e,g List<Account> accList=Test.loadData(Account,SobjectType,'ResourceName').
23. Create TestFactory class with @isTest annotation to exclude from organization code size limit .
24. @testSetup to create test records once in a method  and use in every test method in the test class .
25. We can run unit test by using Salesforce Standard UI,Force.com IDE ,Console ,API.
26. Maximum number of test classes run per 24 hour of period is  not grater of 500 or 10 multiplication of test classes of your organization.
27. As apex runs in system mode so the permission and record sharing are not taken into account . So we need to use system.runAs to enforce record sharing .
28. System.runAs will not enforce user permission or field level permission .
29. Every test to runAs count against the total number of DML issued in the process .


Please let us know if this post will help you
 
This was selected as the best answer
santhosh konathala 17santhosh konathala 17
Hi Soni, 
very Good morning..! I need an help from your side.I am not  much aware on writting Test classes.Below is my Lightning class.Could you help over to write a Test class for the below class.Plz help me I need to submit it very urgent .

public class MTX_EHSInspectionReportController {
    static Integer totalPercentage ;
    
    @AuraEnabled
    public static List<MTX_InspectionReportTemplateHeader__c> getHeader(String headerId){
        String header;
        MTX_InspectionReportHeader__c inspectionReportHeader= [select Name from MTX_InspectionReportHeader__c where Id=:headerId];
        List<MTX_InspectionReportTemplateHeader__c> inspectionReportTemplateHeader = [select Name, InspectionReportType__c, InspectionReportRegion__c, InspectionReportCategoryGroup__c,InspectionReportDepartmentType__c from MTX_InspectionReportTemplateHeader__c where Name =:inspectionReportHeader.Name];
        return inspectionReportTemplateHeader;
    }
    
    @AuraEnabled
    public static List<MTX_InspectionReportTemplateSection__c> getSections(String headerName){
        List<MTX_InspectionReportTemplateSection__c> sections = [select Id, Name, InspectionReportSectionSequence__c, InspectionReportTemplateHeader__r.Name, InspectionReportTemplateHeader__r.Id, (select Id,InpsectionReportQuestionSequence__c, Inspection_Report_Question__c, InspectionReportQuestionGuidanceNote__c, InspectionReportResponseType__c from Inspection_Report_Template_Questions__r order by InpsectionReportQuestionSequence__c) from MTX_InspectionReportTemplateSection__c where InspectionReportTemplateHeader__r.Name =: headerName order by InspectionReportSectionSequence__c];
        return sections; 
    }
    //can remove 
    @AuraEnabled
    public static List<MTX_InspectionReportTemplateSection__c> getQuestions( String section){
        List<MTX_InspectionReportTemplateSection__c> secques = new List<MTX_InspectionReportTemplateSection__c>();
        secques =[select Id, Name, 
                  (select InpsectionReportQuestionSequence__c, Inspection_Report_Question__c,
                   InspectionReportQuestionGuidanceNote__c, InspectionReportResponseType__c
                   from Inspection_Report_Template_Questions__r)
                  from MTX_InspectionReportTemplateSection__c
                  where Name = :section];
        return secques;
    }
    // can remove
    @AuraEnabled
    public static map<String, List<MTX_InspectionReportTemplateQuestion__c>> getSecQuestion(String header) {
        List<String> sectionList = new List<String>();
        Map<String, List<MTX_InspectionReportTemplateQuestion__c>> secquestion = new Map<String,List<MTX_InspectionReportTemplateQuestion__c>>();
        List<MTX_InspectionReportTemplateSection__c> sections = [select Name,InspectionReportTemplateHeader__r.Name from MTX_InspectionReportTemplateSection__c where 
             InspectionReportTemplateHeader__r.Name =: header];
        for(MTX_InspectionReportTemplateSection__c ehs : sections){
            sectionList.add(ehs.Name);
        }
        List<String> questionList = new List<String>();
        List<MTX_InspectionReportTemplateQuestion__c> questions = 
            [select InpsectionReportQuestionSequence__c, Inspection_Report_Question__c,
             InspectionReportQuestionGuidanceNote__c, InspectionReportResponseType__c,
             InspectionReportTemplateSection__r.Name
             from MTX_InspectionReportTemplateQuestion__c 
             where InspectionReportTemplateSection__r.Name in : sectionList];
        for(MTX_InspectionReportTemplateQuestion__c qs : questions){
            secquestion.put(qs.InspectionReportTemplateSection__r.Name,questions);
            questionList.add(qs.Inspection_Report_Question__c);
        }
        set<String> sectioname =secquestion.keySet();
        return secquestion;
    }
    
    @AuraEnabled
    public static String statusBar(List<MTX_InspectionReportTemplateHeader__c> headerListValues, List<String> optionsValues) {
        List<MTX_InspectionReportTemplateSection__c> sectionInfo = getSections(headerListValues[0].Name);
        List<MTX_InspectionReportTemplateQuestion__c> questionList;
        Map<Id,List<MTX_InspectionReportTemplateQuestion__c>> sectionMap
            = new Map<Id, List<MTX_InspectionReportTemplateQuestion__c>>();
        Double percentage;
        Double status=0;
        String sectionId;
        for(MTX_InspectionReportTemplateSection__c eachsection: sectionInfo){
            questionList  = new List<MTX_InspectionReportTemplateQuestion__c>();
            for(MTX_InspectionReportTemplateQuestion__c question : 
                eachsection.Inspection_Report_Template_Questions__r) {
                    questionList.add(question);
                }  
            
            sectionMap.put(eachsection.Id,questionList); 
        }
       
        for(Id key : sectionMap.keySet() ){
            Integer i=0;
            
            List<MTX_InspectionReportTemplateQuestion__c> qList=sectionMap.get(key);
            
            for(MTX_InspectionReportTemplateQuestion__c eachQuestion : qList){
                for(String opt : optionsValues){
                    String [] st1 = opt.split('_');
                    if(eachQuestion.Id == st1[1]){
                        i++;
                        sectionId = key;
                    }
                } 
                
            }
            Integer j= qList.size();
            percentage = (i*100)/j;
            if(percentage>0){
                status =percentage;
                sectionId = status+'_'+sectionId;
            }
        }
        
        return sectionId;
    }
    @AuraEnabled
    public static Integer getPercentage(List<MTX_InspectionReportTemplateHeader__c> headerListValues, List<String> optionsValues){
        
        List<MTX_InspectionReportTemplateSection__c> sectionInfo = getSections(headerListValues[0].Name);
        List<MTX_InspectionReportTemplateQuestion__c> sectionList = new List<MTX_InspectionReportTemplateQuestion__c>();
        for(MTX_InspectionReportTemplateSection__c eachsection: sectionInfo){
            
            // questionsList.addAll(sectionresponse.Inspection_Report_Template_Questions__r);
            for(MTX_InspectionReportTemplateQuestion__c eachquestion : 
                eachsection.Inspection_Report_Template_Questions__r) {
                    sectionList.add(eachquestion);
                }  
        }
        
        Integer totalQ = sectionList.size(); 
        Integer answeredQ = optionsValues.size();                            
        Integer totalPercentage1 = (answeredQ*100)/totalQ;
        system.debug('totalPercentage1'+totalPercentage1);
        return totalPercentage1;
    }
    
    @AuraEnabled
    public static List<MTX_InspectionReportResponse__c> setResponse(List<MTX_InspectionReportTemplateHeader__c> headerList, List<String> options, List<MTX_InspectionFinding__c> ehsFindings, String headerID) {
        List<MTX_InspectionReportResponse__c> insertOptions = new List<MTX_InspectionReportResponse__c>();
        List<MTX_InspectionFinding__c> ehsFind = new List<MTX_InspectionFinding__c>();
        List<MTX_InspectionReportTemplateSection__c> sectionsList = getSections(headerList[0].Name);
        Map<Id,MTX_InspectionReportTemplateQuestion__c> questionsMap = new Map<Id, MTX_InspectionReportTemplateQuestion__c>();
        Map<Id,String> optionmap = new Map<Id, String>();
        List<MTX_InspectionReportTemplateQuestion__c> questionsList = new List<MTX_InspectionReportTemplateQuestion__c>();
        MTX_InspectionReportResponse__c response  = new MTX_InspectionReportResponse__c();
        for(MTX_InspectionReportTemplateSection__c section : sectionsList){                
            questionsList.addAll(section.Inspection_Report_Template_Questions__r);
            for(MTX_InspectionReportTemplateQuestion__c question :
                section.Inspection_Report_Template_Questions__r){
                }  
        }
        if (questionsList.size() >0) {
            system.debug('questionsList.size'+questionsList.size());
            for (MTX_InspectionReportTemplateQuestion__c eachQuestion : questionsList) {
                MTX_InspectionReportResponse__c newOption = new MTX_InspectionReportResponse__c();
                newOption.InspectionQuestion__c = eachQuestion.Inspection_Report_Question__c;
                newOption.InspectionResponseType__c = eachQuestion.InspectionReportResponseType__c;
                newOption.InspectionReportHeader__c = headerId;
                newOption.InspectionResponse__c = '';
                newOption.Inspection_Report_Template_Question__c = eachQuestion.Id;
                for(String opt : options){
                    String [] st1 = opt.split('_');
                    if(eachQuestion.Id == st1[1]){
                        newOption.InspectionResponse__c = st1[0];
                    }
                }
                insertOptions.add(newOption);
            }
        }   
        if(insertOptions !=null && insertOptions.size() >0) {
            insert insertOptions;
        }
        
        return insertOptions;
    }
    
    @AuraEnabled
    public static String setAnswers(List<String> options) {
        system.debug('No of options selected'+options.size());
        return 'Success';
    }
    
    @AuraEnabled
    public static List<MTX_InspectionFinding__c> getInspectionFinding(Id recordId) {
        return [SELECT id,ActionDescription__c,FindingDescription__c,InspectionReportResponse__c FROM MTX_InspectionFinding__c WHERE Question__c=:recordId];
    }
    
    @AuraEnabled
    public static Map<Id, List<MTX_InspectionReportTemplateQuestion__c>> getQuestionswithAnswers(List<MTX_InspectionReportTemplateSection__c> sections, string headerId){
        Map<Id, MTX_InspectionReportTemplateSection__c> sectionsMap = new Map<Id, MTX_InspectionReportTemplateSection__c>(sections);
        List<MTX_InspectionReportTemplateQuestion__c> questionsList = [SELECT 
                                                                   Id,
                                                                   InpsectionReportQuestionSequence__c, 
                                                                   InspectionReportTemplateSection__c, 
                                                                   Inspection_Report_Question__c, 
                                                                   InspectionReportQuestionGuidanceNote__c, 
                                                                   InspectionReportResponseType__c,
                                                                   (SELECT Id, InspectionResponse__c, InspectionReportHeader__c,InspectionQuestion__c, InspectionResponseType__c, Inspection_Report_Template_Question__c FROM Inspection_Report_Responses__r WHERE InspectionReportHeader__c=:headerId),
                                                                   (SELECT Id, FindingDescription__c, ActionDescription__c FROM InspectionFindings__r WHERE HeaderId__c =:headerId)
                                                                  FROM MTX_InspectionReportTemplateQuestion__c 
                                                                  WHERE 
                                                                   InspectionReportTemplateSection__c =: sectionsMap.keySet() 
                                                                  ORDER BY 
                                                                   InpsectionReportQuestionSequence__c ];
        List<MTX_InspectionReportResponse__c> responseList = new List<MTX_InspectionReportResponse__c>();
        for (MTX_InspectionReportTemplateQuestion__c eachQuestion : questionsList) {
            if(eachQuestion.Inspection_Report_Responses__r.size() == 0 || eachQuestion.Inspection_Report_Responses__r == null){
                MTX_InspectionReportResponse__c newResponse = new MTX_InspectionReportResponse__c();
                newResponse.InspectionResponse__c ='';
                newResponse.InspectionReportHeader__c = headerId;
                newResponse.InspectionQuestion__c = eachQuestion.Inspection_Report_Question__c;
                newResponse.InspectionResponseType__c = eachQuestion.InspectionReportResponseType__c;
                newResponse.Inspection_Report_Template_Question__c = eachQuestion.Id;
                responseList.add(newResponse);
            }
        }
        if(responseList != null && responseList.size() >0) {
            insert responseList;
            questionsList = [SELECT 
                             Id,
                             InpsectionReportQuestionSequence__c, 
                             InspectionReportTemplateSection__c, 
                             Inspection_Report_Question__c, 
                             InspectionReportQuestionGuidanceNote__c, 
                             InspectionReportResponseType__c,
                             (SELECT Id, InspectionResponse__c, InspectionReportHeader__c,InspectionQuestion__c, InspectionResponseType__c, Inspection_Report_Template_Question__c FROM Inspection_Report_Responses__r WHERE InspectionReportHeader__c=:headerId),
                             (SELECT Id, FindingDescription__c, ActionDescription__c FROM InspectionFindings__r WHERE HeaderId__c =:headerId)
                             FROM MTX_InspectionReportTemplateQuestion__c 
                             WHERE 
                             InspectionReportTemplateSection__c =: sectionsMap.keySet() 
                             ORDER BY 
                             InpsectionReportQuestionSequence__c ];
        }
        Map<Id, List<MTX_InspectionReportTemplateQuestion__c>> questionsMap = new Map<Id, List<MTX_InspectionReportTemplateQuestion__c>>();
        for (MTX_InspectionReportTemplateQuestion__c eachQuestion :questionsList) {
            if (questionsMap.containsKey(eachQuestion.InspectionReportTemplateSection__c)){
                questionsMap.get(eachQuestion.InspectionReportTemplateSection__c).add(eachQuestion);
            } else {
                questionsMap.put(eachQuestion.InspectionReportTemplateSection__c, new List<MTX_InspectionReportTemplateQuestion__c>{eachQuestion});
            }
        }
        
        return questionsMap;
    }
    @AuraEnabled
    public static Integer saveResponses(List<MTX_InspectionReportResponse__c> responses, List<MTX_InspectionFinding__c> findings){
        system.debug(responses);
         integer answeredQ=0;
        List<MTX_InspectionReportResponse__c> responseList = new List<MTX_InspectionReportResponse__c>();
        Map<string, MTX_InspectionReportResponse__c> responseMap = new Map<String, MTX_InspectionReportResponse__c>();
        List<MTX_InspectionFinding__c> findingsList = new List<MTX_InspectionFinding__c>();
        List<MTX_InspectionFinding__c> delFindingsList = new List<MTX_InspectionFinding__c>();
        for (MTX_InspectionReportResponse__c eachResponse: responses) { 
            responseMap.put(eachResponse.Inspection_Report_Template_Question__c, eachResponse);
            responseList.add(eachResponse);
            if(eachResponse.InspectionResponse__c != '' && eachResponse.InspectionResponse__c != null){
                answeredQ ++;
            }
        }
        system.debug('ans ***'+answeredQ); 
        Integer totalQ =responseList.size();
        system.debug('total ***'+totalQ); 
        totalPercentage = (answeredQ*100)/totalQ;  
        if (responseList.size() >0 && responseList != null) {
            upsert responseList;
        }
        List<MTX_InspectionFinding__c> deletableFindings = new List<MTX_InspectionFinding__c>();
        List<MTX_InspectionFinding__c> updatableFindings = new List<MTX_InspectionFinding__c>();
        if(findings.size() >0 && findings != null){
            for (MTX_InspectionFinding__c eachFind : findings){
                if(responseMap.containsKey(eachFind.Question__c)){
                    MTX_InspectionReportResponse__c currentResponse= responseMap.get(eachFind.Question__c);
                    if(currentResponse.InspectionResponse__c != 'NO'){
                        if(eachFind.Id != null){
                            deletableFindings.add(eachFind);
                        }
                    }else {
                        eachFind.InspectionReportResponse__c = currentResponse.Id;
                        updatableFindings.add(eachFind);
                    }
                }else {
                    deletableFindings.add(eachFind);
                }
            }
        }
        
        
        delete deletableFindings;
        upsert updatableFindings;
        return totalPercentage;
        
    }
    
    
     @AuraEnabled
    public static Integer showPercentage(){
        system.debug('in show####'+totalPercentage);
        return totalPercentage;
    }
   
}