Background Search Trigger

About Background Search Trigger:

    Background Search object contains "BackgroundSearchTrigger" trigger. We perform insert, update and delete operation with a trigger.

How to reach Background Search Trigger:

    We can see the Background Search trigger by using given below two ways:

    1. With the help of "Setup".

    2. With the help of "Side menu button" of Background Search object.

    1. With the help of "Setup":

      Step 1: Click on the user name(Right corner of the screen).

      Step 2: Go to Setup.

      Step 3: In "App Setup", click on "Develop" >> click on "Apex Triggers".

      Step 4: And find "BackgroundSearchTrigger" in list of trigger.

    2. With the help of "Side menu button" of Background Search object:

      Step 1: Click on all tab button on the home page of salesforce.

      Step 2: Find "Background Searches" tab in all tabs and click on "Background Searches" tab.

      Step 3 : Click on right side menu button.

      Step 4 : Open a menu list and click on "View Object".

      Step 5 : On "Custom Object Definition Detail" page, find "Triggers" section and "BackgroundSearchTrigger" trigger.

Working of Background Search trigger:

  1. Define Background_Search__c object on the top of trigger and this object contain new value of Background Search record.
    Background_Search__c[] bs = Trigger.new;

  2. Initialize all the variable and list in trigger.

  3. There are using context variable in four conditions and three method:

    1. Trigger.isBefore and Trigger.isInsert
    2. Trigger.isBefore and Trigger.isUpdate
    3. Trigger.isAfter and Trigger.isUpdate
    4. Trigger.isAfter and Trigger.isInsert
    5. AddStateWiseSearch
    6. getIsSpclTaxResearch
    7. setSubjectOfSearchCall

      I. Trigger.isBefore and Trigger.isInsert

      1. Update Archived_Alternate_Name_ID__c field of Background_Search__c object:

        Logic:

        1. Alternate_Name__c should not be equal to null.
        2. Archived_Alternate_Name_ID__c should be equal to null.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on Alternate_Names__c object and fetch the value of Name field based on Alternate_Name__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query in lstAlternetName list of Alternate_Names__c object.
        2. Set the value of Archived_Alternate_Name_ID__c field of Background_Search__c object from Name field of Alternate_Names__c object, if the size of lstAlternetName list is greater than zero.

      2. Update Archived_Additional_Address_ID__c field of Background_Search__c object:

        Logic:

        1. Additional_Address__c should not be equal to null.
        2. Archived_Additional_Address_ID__c should be equal to null.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on Additional_Address__c object and fetch the value of Name field based on Additional_Address__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query in lstAdditionalAddress list of Additional_Address__c object.
        2. Set the value of Archived_Additional_Address_ID__c field of Background_Search__c object from Name field of Additional_Address__c object, if the size of lstAdditionalAddress list is greater than zero.

      3. Update Background Check Case record:

        Logic:

        1. PreEmploy_Case__c should not be equal to null.
        2. Search_Complete__c should be false.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on PreEmploy_Case__c object and fetch the value of Report_Case_Closed__c field based on PreEmploy_Case__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query in oPreEmployCase object variable of PreEmploy_Case__c object.
        2. Call "UpdateCaseRecordType" method of "BackgroundSearchTriggercl" class and pass value of PreEmploy_Case__c field of Background_Search__c object as a parameter, if oPreEmployCase variable is not null and the value of oPreEmployCase.Report_Case_Closed__c is true.
        3. Assign the value of oPreEmployCase.Subject_of_background__c to Subject_of_Search__c field of Background_Search__c object, if oPreEmployCase variable is not null and the value of Subject_of_Search__c field of Background_Search__c is equal to null.

      4. Query on BGC_List_of_Services__c object:

        Logic:

        1. Jurisdiction__c should be equal to null.

        If above condition are matched then script fetch following fields:

        Query:

        1. Query on BGC_List_of_Services__c object and fetch the value of id, Name, Location_Based__c, Location_Based_Type__c, Run_AKA_s__c and Specialty_Texas_Research__c fields based on SearchType__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query in listblos list of BGC_List_of_Services__c object.

      5. Update zipcode and state variable:

        Logic:

        1. Jurisdiction__c should be equal to null.
        2. Additional_Address__c should not be equal to null.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on Additional_Address__c object and fetch the value of Zip_Code__c and State_Providence__c fields based on Additional_Address__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query in listaa list of Additional_Address__c object.
        2. Set the value of zipcode variable from Zip_Code__c field of Additional_Address__c object, if the size of listaa list is greater than zero.
        3. Set the value of state variable from State_Providence__c field of Additional_Address__c object, if the size of listaa list is greater than zero.

      6. Again update zipcode and state variable:

        Logic:

        1. Jurisdiction__c should be equal to null.
        2. state or zipcode should be equal to null.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set the value of zipcode variable from Applicant_Zip_Code__c field of Background_Search__c object.
        2. Set the value of state variable from Applicant_State_Providence__c field of Background_Search__c object.

      7. Update County__c field:

        Logic:

        1. Jurisdiction__c and County__c should be equal to null.
        2. Applicant_Zip_Code__c or zipcode should not be equal to null.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on Zip_Code__c object and fetch the value of County__c and AssociatedCounty__c fields based on Applicant_Zip_Code__c field of Background_Search__c object OR zipcode variable.

        Value assignment:

        1. Assign the value of above query in listzip list of Zip_Code__c object.
        2. Set the value of County__c field of Background_Search__c object from AssociatedCounty__c field of Zip_Code__c object, if size of listzip list is greater than zero and listzip list is not equal to null.

      8. Update Location_Based_Type__c field, bSpclTaxResearch variable and assign the value of listblos list to singleblos object type variable:

        Logic:

        1. Jurisdiction__c should be equal to null.
        2. Size of listblos list of BGC_List_of_Services__c object should be greater than zero.

        If above condition are matched then script update following fields and list:

        Value assignment:

        1. Assign the value of listblos list to singleblos variable of BGC_List_of_Services__c object.
        2. Set the value of Location_Based_Type__c field of Background_Search__c object from Location_Based_Type__c field of singleblos object type variable.
        3. Set the value of bSpclTaxResearch variable from Specialty_Texas_Research__c field of BGC_List_of_Services__c object.

      9. Query on State_Providence__c object:

        Logic:

        1. Merge the logic of point 8.
        2. singleblos variable of BGC_List_of_Services__c object and Applicant_State_Providence__c should not be equal to null.
        3. Name should not be equal to null.
        4. Name should be contain 'statewide'.

        If above condition are matched then script fetch following fields:

        Query:

        1. Query on State_Providence__c object and fetch the value of Statewide_Available__c and Name fields based on Applicant_State_Providence__c field of Background_Search__c object.

        Value assignment:

        1. Set "('Background Search not Created. Statewide is not available for this state : '+ LstState.get(0).Name +'.')" value to addError field of Background_Search__c object if Statewide_Available__c field of State_Providence__c should be false.

      10. Update Notes_Technical_Troubleshooting__c field of Background_Search__c object:

        Logic:

        1. Merge the logic of point 8.
        2. singleblos variable of BGC_List_of_Services__c object should not be equal to null.
        3. Location_Based__c of BGC_List_of_Services__c object should be true.

        If above condition are matched then script update following field:

        Value assignment:

        1. Set "('BEFORE LOOKING JURIS Search subject state: ' + b.Applicant_State__c + ' List of Services: ' +singleblos.Name + ' state order: ' + b.Applicant_State_Providence__c + ' OR ' + state + ' zip order: ' + b.Applicant_Zip_Code__c + ' or ' + zipcode)" value to Notes_Technical_Troubleshooting__c field of Background_Search__c object.

      11. Get Jurisdiction by County and get BGS owner:

        Logic:

        1. Merge the logic of point 8 and point 10.
        2. Value of Location_Based_Type__c field of BGC_List_of_Services__c object should be equal to 'County'.
        3. County__c of Background_Search__c object should not be equal to null.

        If above condition are matched then script fetch and update following fields:

        Value assignment:

        1. Call "GetJurisListByCounty" method from "BackgroundSearchTriggercl" class and assign value from "GetJurisListByCounty" method to listjuris list.
        2. Assign the value of "GetJurisListByCounty" method to listjuris list of Jurisdiction__c object.
        3. Set value of listjuris list to singlejuris variable of Jurisdiction__c object, if the size of listjuris list should be greater than zero.
        4. Call "GetBGSOwner" method from "BackgroundSearchTriggercl" class and assign value from "GetBGSOwner" method to "b" the object of Background_Search__c object, if the size of listjuris list should be greater than zero.

      12. Get Jurisdiction by State and get BGS owner:

        Logic:

        1. Merge the logic of point 8 and point 10.
        2. Value of Location_Based_Type__c field of BGC_List_of_Services__c object should not be equal to 'County'.
        3. Value of Location_Based_Type__c field of BGC_List_of_Services__c object should be equal to 'Statewide' or 'International'.

        If above condition are matched then script fetch and update following fields:

        Value assignment:

        1. Update the value of Notes_Technical_Troubleshooting__c field of Background_Search__c object.
        2. Call "GetJurisListByState" method from "BackgroundSearchTriggercl" class and assign value from "GetJurisListByState" method to listjuris list of Jurisdiction__c object.
        3. Set value of listjuris list to singlejuris object of Jurisdiction__c object, if size of listjuris list is greater than zero.
        4. Call "GetBGSOwner" method from "BackgroundSearchTriggercl" class and assign value from "GetBGSOwner" method to "b" the object of Background_Search__c object, if the size of listjuris list is greater than zero.
        5. Call "GetJurisListByState" method from "BackgroundSearchTriggercl" class and assign value from "GetJurisListByState" method to listjuris list of Jurisdiction__c object, if size of listjuris list is equal to zero.
        6. Set value of listjuris list to singlejuris object of Jurisdiction__c object, if size of listjuris list is greater than zero.
        7. Call "GetBGSOwner" method from "BackgroundSearchTriggercl" class and assign value from "GetBGSOwner" method to "b" the object of Background_Search__c object, if the size of listjuris list is greater than zero.

      13. Check duplicate Background Search record:

        Logic:

        1. Merge the logic of point 8 and point 10.
        2. Location_Based_Type__c of BGC_List_of_Services__c object should not be equal to null and blank.
        3. County__c or Applicant_State_Providence__c field of Background_Search__c object should not be equal to null.
        4. Jurisdiction__c, Name_to_Search_First__c and Name_to_Search_Last__c field of Background_Search__c object should not be equal to null.
        5. Status_Standard__c of Background_Search__c object should not be equal to 'Cancelled/Not Requested'.

        If above condition are matched then script fetch and update following fields:

        Value assignment:

        1. Call "FillListBackGroundSearch" method from "BackgroundSearchTriggercl" class and assign value from "FillListBackGroundSearch" method to listbs list of Background_Search__c object.

      13.1. Check duplicate Background Search record:

        Logic:

        1. Size of listbs list should be greater than zero.
        2. Service_Ordered__c of listbs list should not be equal to null.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on BGC_S_O_Individual__c object and get the value of Id and BGC_Package_Item__c based on value of Service_Ordered__c field of listbs list.

        Value assignment:

        1. Value of above query assign to oBGCSOIndividual object of BGC_S_O_Individual__c object.

        If above condition are not matched then script update following field:

        Value assignment:

        1. Set "'Background Search not created: Search of this type, jurisdiction and name already exists [Search Number:['+listbs.get(0).Name+']].'" value to addError field of Background_Search__c object.

      13.1.1. Check duplicate Background Search record:

        Logic:

        1. Id of BGC_S_O_Individual__c object should not be equal to null.
        2. BGC_Package_Item__c of BGC_S_O_Individual__c object should not be equal to null.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on BGC_Package_Items__c object and fetch the value of Id, Jurisdiction_Specific__c, Specific_Jurisdiction__c, Specific_Jurisdiction__r.State_Providence__c fields based on value of BGC_Package_Item__c field of BGC_S_O_Individual__c object.

        Value assignment:

        1. Assign the value of above query in oBGCPackageItem object of BGC_Package_Items__c object.

        If above condition are not matched then script update following field:

        Value assignment:

        1. Set "'Background Search not created: Search of this type, jurisdiction and name already exists [Search Number:['+listbs.get(0).Name+']].'" value to addError field of Background_Search__c object.

      13.1.1.1. Check duplicate Background Search record:

        Logic:

        1. Value of Id, Specific_Jurisdiction__c and Specific_Jurisdiction__r.State_Providence__c field of BGC_Package_Items__c object should be equal to null.
        2. Value of Jurisdiction_Specific__c field of BGC_Package_Items__c object should not be true.
        3. Value of Specific_Jurisdiction__r.State_Providence__c field of BGC_Package_Items__c object should be equal to value of Applicant_State_Providence__c field of Background_Search__c object.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set "'Background Search not created: Search of this type, jurisdiction and name already exists [Search Number:['+listbs.get(0).Name+']].'" value to addError field of Background_Search__c object.

      14. Update Notes_Technical_Troubleshooting__c field of Background_Search__c object:

        Logic:

        1. Merge the logic of point 8.
        2. value of Location_Based__c field of BGC_List_of_Services__c object should be false.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set "'NOT Location Based=True, if not here Search Type not defined in Juris or no Active - BEFORE LOOKING JURIS Search subject state: ' + b.Applicant_State__c + ' List of Services Named: ' + singleblos.Name" value to Notes_Technical_Troubleshooting__c field of Background_Search__c object.

      14.1. Get Jurisdiction List By State:

        Logic:

        1. value of Name field of BGC_List_of_Services__c object should be equal to 'Motor Vehicle Report'.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Update the value of Notes_Technical_Troubleshooting__c field of Background_Search__c object.
        2. Call "GetJurisListByState" method of "BackgroundSearchTriggercl" class and assign value from "GetJurisListByState" method to listjuris list of Jurisdiction__c object.

      14.2. Get Jurisdiction List By State:

        Logic:

        1. value of Name field of BGC_List_of_Services__c object should be equal to 'Child Abuse Registry'.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Update the value of Notes_Technical_Troubleshooting__c field of Background_Search__c object.
        2. Call "GetJurisListByState" method of "BackgroundSearchTriggercl" class and assign value from "GetJurisListByState" method to listjuris list of Jurisdiction__c object.

      14.3. Get Jurisdiction List By State:

        Logic:

        1. value of Name field of BGC_List_of_Services__c object should not be equal to 'Motor Vehicle Report' and 'Child Abuse Registry'.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Call "GetJurisListByState" method of "BackgroundSearchTriggercl" class and assign value from "GetJurisListByState" method to listjuris list of Jurisdiction__c object.

      14.4. Get BGS Owner:

        Logic:

        1. Size of listjuris list of Jurisdiction__c object should be greater than zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Assign listjuris list to singlejuris object.
        2. Call "GetBGSOwner" method of "BackgroundSearchTriggercl" class and assign value from "GetBGSOwner" method to "b" object variable of Background_Search__c object.

      14.5. Get BGS Owner and get Jurisdiction List By State:

        Logic:

        1. Size of listjuris list of Jurisdiction__c object should be equal to zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Call "GetJurisListByState" method of "BackgroundSearchTriggercl" class and assign value from "GetJurisListByState" method to listjuris list of Jurisdiction__c object.
        2. Assign listjuris list to singlejuris object, if the size of listjuris list is greater than zero.
        3. Call "GetBGSOwner" method of "BackgroundSearchTriggercl" class and assign value from "GetBGSOwner" method to "b" object variable of Background_Search__c object, if the size of listjuris list is greater than zero.

      15. Query on PreEmploy_Case__c object:

        Logic:

        1. Jurisdiction__c and PreEmploy_Case__c field of Background_Search__c object should not be equal to null.
        2. value of Search_Type_Name__c field of Background_Search__c object should not be equal to 'Statewide Research'.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on PreEmploy_Case__c object and fetch the value of Previous_Hits_Present__c based on PreEmploy_Case__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query to oRelatedCase object of PreEmploy_Case__c object.
        2. Call "timestamp" method of "Salesforcecl" and assign the value of "timestamp" method to Notes_Internal__c field of Background_Search__c object, the oRelatedCase variable is not null and the value of Previous_Hits_Present__c field of PreEmploy_Case__c object is true.

      II. Trigger.isBefore and Trigger.isUpdate

      1. Fetch record from PreEmploy_Case__c object and update Case RecordType:

        Logic:

        1. PreEmploy_Case__c field of Background_Search__c object should not be equal to null.
        2. value of Search_Complete__c field of Background_Search__c object should be false.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on PreEmploy_Case__c object and fetch the value of Report_Case_Closed__c field based on PreEmploy_Case__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query to oPreEmployCase object of PreEmploy_Case__c object.
        2. Call "UpdateCaseRecordType" of "BackgroundSearchTriggercl" class and pass PreEmploy_Case__c field of Background_Search__c as a parameter, if oPreEmployCase variable is not null and value of Report_Case_Closed__c field of PreEmploy_Case__c object is true.

      2. Insert Background_Search__c record:

        Logic:

        1. value of Search_Type_Name__c field of Background_Search__c object should be equal to 'County Criminal' or 'County Civil'.
        2. value of Sister_County__c field of Background_Search__c object should be false.

        If above condition are matched then script assignment the value in following fields:

        Value assignment:

        1. Create Background_Search__c record as per current values of Background_Search__c record.

      3. Update County__c field of Background_Search__c object:

        Logic:

        1. County__c of Background_Search__c object should be equal to null.
        2. Applicant_Zip_Code__c of Background_Search__c object should not be equal to null.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on Zip_Code__c object and fetch the value of County__c and AssociatedCounty__c field based on Applicant_Zip_Code__c field of Background_Search__c object.

        Value assignment:

        1. Value of above query assign to listzip list of Zip_Code__c object.
        2. Assign value of AssociatedCounty__c field of Zip_Code__c to County__c of Background_Search__c object, if size of listzip list greater than zero.

      4. Insert Search Restriction:

        Logic:

        1. value of Jurisdiction__c field of Background_Search__c object should not be equal to null.
        2. value of Search_Type_Name__c field of Background_Search__c object should not be equal to 'Statewide Research'.
        3. value of Status_Standard__c field of Background_Search__c object should not be equal to 'Hold'.
        4. value of Search_Restriction__c field of Background_Search__c object should not be equal to 'Approved to Run Industry Restricted Search'.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Call "InsertSearchRestriction" method of "BackgroundSearchTriggercl" class and pass object of Background_Search__c object as a parameter.

      III. Trigger.isAfter and Trigger.isUpdate

      1. Update the record of Verification__c object:

        Logic:

        1. value of Status_Standard__c field of Background_Search__c object should be equal to 'Cancelled/Not Requested'.
        2. value of Service_Classification__c field of Background_Search__c object should be equal to 'Verification'.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on Verification__c object and fetch the value of id, Status__c, Search_Complete__c field based on id of Background_Search__c object.

        Value assignment:

        1. Value of above query assign to listver list of Verification__c object.
        2. Assign the value of Status__c field of Verification__c object to sStatus variable, if size of listver list should be greater than zero.
        3. Set 'Cancelled' on Status__c field of Verification__c object, if value of sStatus variable should not be equal to 'Cancelled'.
        4. Set true on Search_Complete__c field of Verification__c object, if value of sStatus variable should not be equal to 'Cancelled'.

      2. Query on Background_Search__c object:

        Logic:

        1. Value of Search_Complete__c field of Background_Search__c object should be true.
        2. OR
        3. value of Search_Type_Name__c field of Background_Search__c should be equal to 'Credit Report' or 'Motor Vehicle Report'.

        If above condition are matched then script fetch and update following fields.

        Query:

        1. Query on Background_Search__c object and fetch the value of Status_Standard__c, Invalid__c, Ready_for_Processing__c, RecordTypeId, Search_Type_Name__c,Search_Complete__c, Clear_Search__c, All_Clear__c field based on PreEmploy_Case__c of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query to listbs list of Background_Search__c object.
        2. Set false on bHit variable.
        3. Add one on countTotal variable.

      2.1.1. Update countInvalid variable:

        Logic:

        1. value of Invalid__c field of Background_Search__c object should be true.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countInvalid variable.

      2.1.2. Update countReadyForProcessing variable:

        Logic:

        1. value of Ready_for_Processing__c field of Background_Search__c object should be false.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countReadyForProcessing variable.

      2.1.3. Update countSearchComplete variable:

        Logic:

        1. value of Search_Complete__c field of Background_Search__c object should be true.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countSearchComplete variable.

      2.1.4. Update countClear variable:

        Logic:

        1. value of Status_Standard__c field of Background_Search__c object should be equal to 'Clear'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countClear variable.

      2.1.5. Update countComplete variable:

        Logic:

        1. value of Status_Standard__c field of Background_Search__c object should be equal to 'Complete'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countComplete variable.

      2.1.6.1. Update countCancelled variable:

        Logic:

        1. value of Status_Standard__c field of Background_Search__c object should be equal to 'Cancelled/Not Requested'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countCancelled variable.

      2.1.6.2. Update countCancelled variable:

        Logic:

        1. value of Status_Standard__c field of Background_Search__c object should be equal to 'Not Requested'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countCancelled variable.

      2.1.6.3. Update countCancelled variable:

        Logic:

        1. value of Status_Standard__c field of Background_Search__c object should be equal to 'Cancelled'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countCancelled variable.

      2.1.7. Update countHit variable:

        Logic:

        1. value of Status_Standard__c field of Background_Search__c object should be equal to 'Hit' or 'Unverified Hit' or 'Needs Review'.
        2. value of Search_Complete__c field of Background_Search__c object should be true.

        If above condition are matched then script update following field.

        Value assignment:

        1. Add one on countHit variable.

      2.1.8. Update countNeedsReview variable:

        Logic:

        1. value of Status_Standard__c field of Background_Search__c object should be equal to 'Needs Review'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countNeedsReview variable.

      2.1.9. Update countOtherStatus variable:

        Logic:

        1. Value of Status_Standard__c field of Background_Search__c object should not be equal to 'Needs Review' OR 'Unverified Hit' OR 'Hit' OR 'Cancelled' OR 'Not Requested' OR 'Cancelled/Not Requested' OR 'Complete' OR 'Clear'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countOtherStatus variable.

      2.1.10. Update countSearchTypeSSN variable:

        Logic:

        1. value of Search_Type_Name__c field of Background_Search__c object should be equal to 'SSN Address Locator'.
        2. value of Search_Complete__c field of Background_Search__c object should be true.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countSearchTypeSSN variable.

      2.1.11. Update countSearchTypeCredit variable:

        Logic:

        1. value of Search_Type_Name__c field of Background_Search__c object should be equal to 'Credit Report'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countSearchTypeCredit variable.

      2.1.12. Update countSearchTypeMotor variable:

        Logic:

        1. value of Search_Type_Name__c field of Background_Search__c object should be equal to 'Motor Vehicle Report'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Add one on countSearchTypeMotor variable.

      2.2. Query on RecordType object:

        Logic:

        1. value of countInvalid variable should be equal to zero.
        2. value of countTotal variable should be greater than zero.

        If above condition are matched then script fetch and update following field:

        Query:

        1. Query on RecordType object and fetch the value of id, Name, SobjectType field based on Name should be equal to 'Cancelled' OR Name should be equal to 'Graded Clear/Pass' OR Name should be equal to 'Graded_Clear_Pass' OR Name should be equal to 'Complete' OR Name should be equal to 'Pending Grading' OR Name should be equal to 'Pending_Grading' AND SobjectType should be equal to 'Background_Search__c' OR SobjectType should be equal to 'PreEmploy_Case__c'.

        Value assignment:

        1. Assign the value of above query to listrt list of RecordType object.

      2.2.1. Update CompleteRecordType variable:

        Logic:

        1. value of Name field of RecordType object should be equal to 'Complete'.
        2. value of SobjectType field of RecordType object should be equal to 'Background_Search__c'.

        If above condition are matched then script update following field.

        Value assignment:

        1. Assign the value of rectype object of RecordType object to CompleteRecordType variable.

      2.2.2. Update CancelledRecordType variable:

        Logic:

        1. value of Name field of RecordType object should be equal to 'Cancelled'.
        2. SobjectType of RecordType object should be equal to 'Background_Search__c'.

        If above condition are matched then script update following field.

        Value assignment:

        1. Assign the value of rectype object of RecordType object to CancelledRecordType variable.

      2.2.3. Update GradedPassRecordType variable:

        Logic:

        1. value of Name field of RecordType object should be equal to 'Graded_Clear_Pass' or 'Graded Clear/Pass'.
        2. SobjectType of RecordType object should be equal to 'Background_Search__c'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Assign the value of rectype object of RecordType object to GradedPassRecordType variable.

      2.2.4. Update CaseCompleteRecordType variable:

        Logic:

        1. value of Name field of RecordType object should be equal to 'Complete'.
        2. SobjectType of RecordType object should be equal to 'PreEmploy_Case__c'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Assign the value of rectype object type variable of RecordType object to CaseCompleteRecordType variable.

      2.2.5. Update CaseGradedPassRecordType variable:

        Logic:

        1. value of Name field of RecordType object should be equal to 'Graded_Clear_Pass' or 'Graded Clear/Pass'.
        2. SobjectType of RecordType object should be equal to 'PreEmploy_Case__c'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Assign the value of rectype object of RecordType object to CaseGradedPassRecordType variable.

      2.2.6. Update PendingGradingRecordType variable:

        Logic:

        1. value of Name field of RecordType object should be equal to 'Pending Grading' or 'Pending_Grading'.
        2. SobjectType of RecordType object should be equal to 'PreEmploy_Case__c'.

        If above condition are matched then script update following field:

        Value assignment:

        1. Assign the value of rectype object of RecordType object to PendingGradingRecordType variable.

      2.3. Fetch the record on PreEmploy_Case__c object:

        Logic:

        1. countSearchComplete variable should be equal to countTotal variable.

        If above condition are matched then script fetch and update following field:

        Query:

        1. Query on PreEmploy_Case__c object and fetch the value of id, Name, Account_Name__c, Account__c, IsAllSearchesClosed__c, IsHitSearchPresent__c, IsAllSearchesCancelled__c, Report_Closed_Date__c, IsDelayComplete__c, Is8HoursDelayActivated__c, Invite_User_to_MBCR__c, MBC_User_Created__c, Report_Case_Status__c, Distributed_for_Formation__c, Formation_Complete__c, Queue_For_Grading__c, Report_Case_Closed__c, Subject_First_Name__c, Subject_Last_Name__c, No_Subject_of_Background_Contact__c, Subject_Email__c, Grading_Complete__c, RecordTypeId, Subject_of_background__c, Report_Case_Grade__c fields based on PreEmploy_Case__c field of Background_Search__c object AND Report_Case_Closed__c should be false AND Contact_Has_Dispute__c should be false AND Formation_Complete__c should be true.

        Value assignment:

        1. Value of above query assign to listpc list of PreEmploy_Case__c object.

      2.3.1. Create MBCR User:

        Logic:

        1. Size of listpc list should be greater than zero.
        2. Value of countSearchTypeCredit or countSearchTypeMotor or countHit or countNeedsReview variable should be greater than zero.
        3. Value of Is8HoursDelayActivated__c and IsDelayComplete__c field of PreEmploy_Case__c object should be false.
        4. Value of Subject_of_background__c field of PreEmploy_Case__c object should be equal to null.
        5. Value of Status_Standard__c field of Background_Search__c object should not be equal to 'Cancelled/Not Requested'.

        If above condition are matched then script fetch and update following fields:

        Create Contact:

        1. Call "CreateContact" method of "MBCRUserCreation" class for create Contact record.

        Query:

        1. Query on User object and fetch the value of Id field based on id of Contact object should be equal to Subject_of_background__c of PreEmploy_Case__c object.

        Value assignment:

        1. Assign the value of above query in LstUserProfile list of User object.
        2. Call "CreateUser" method of "MBCRUserCreation" class for create an user, if the size of LstUserProfile list is equal to zero.
        3. Set true on MBC_User_Created__c field of PreEmploy_Case__c object, if the size of LstUserProfile list is equal to zero.
        4. Call "setSubjectOfSearchCall" method of this trigger for update Subject_Of_Search__c field, if the size of LstUserProfile list is equal to zero.
        5. Set true on Is8HoursDelayActivated__c field of PreEmploy_Case__c object.
        6. Set current datetime on Hours8DelayStartTime__c field of PreEmploy_Case__c object.

      2.3.2. Create MBCR User:

        Logic:

        1. Merge the logic of 2.3.1 point
        2. Value of Subject_of_background__c field of PreEmploy_Case__c object should not be equal to null.
        3. Value of MBC_User_Created__c field of PreEmploy_Case__c object should not be true.
        4. Value of Status_Standard__c field of Background_Search__c object should not be equal to 'Cancelled/Not Requested'.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on Contact object and fetch the value of accountID field based on Subject_of_background__c of PreEmploy_Case__c object and assign the value of query in LstCon list of Contact object.

        Delete Contact:

        1. Delete the value of LstCon list, if accountID of Contact object should be equal to null.

        Create Contact:

        1. Call "CreateContact" method of "MBCRUserCreation" class for create Contact record.

        Query:

        1. Query on User object and fetch the value of Id field based on id of Contact object should be equal to Subject_of_background__c of PreEmploy_Case__c object.

        Value assignment:

        1. Assign the value of above query in LstUserProfile list of User object.
        2. Call "CreateUser" method of "MBCRUserCreation" class for create an user, if the size of LstUserProfile list is equal to zero.
        3. Set true on MBC_User_Created__c field of PreEmploy_Case__c object, if the size of LstUserProfile list is equal to zero.
        4. Call "setSubjectOfSearchCall" method of this trigger for update Subject_Of_Search__c field, if the size of LstUserProfile list is equal to zero.
        5. Set true on Is8HoursDelayActivated__c field of PreEmploy_Case__c object.
        6. Set current datetime on Hours8DelayStartTime__c field of PreEmploy_Case__c object.

      2.3.3. Fetch the data from BGC_Configuration__c object:

        Logic:

        1. Size of listpc list should be greater than zero.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on BGC_Configuration__c object and fetch the value of id, Grading_Pass_Verbiage__c, Enabled_Grading_for_Audit__c, Enabled_Grading__c, Grading_Do_Not_Auto_Clear__c fields based on Account__c field of PreEmploy_Case__c object AND Enabled_Grading__c should be true or Enabled_Grading_for_Audit__c should be true.

        Value assignment:

        1. Assign the value of above query to listbc list of BGC_Configuration__c object.

      2.3.3.1. Update the fields of PreEmploy_Case__c object:

        Logic:

        1. Size of listbc list should be greater than zero.
        2. Sum of countClear, countComplete and countCancelled variables should be equal to countTotal variable.
        3. Value of countCancelled variable should not be equal to value of countTotal variable.
        4. Value of countHit variable should be equal to zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set True on IsAllSearchesClosed__c field, set False on IsHitSearchPresent__c and IsAllSearchesCancelled__c field of PreEmploy_Case__c object.
        2. Set value of Grading_Pass_Verbiage__c field of BGC_Configuration__c object to Report_Case_Grade__c field of PreEmploy_Case__c object, if value of Grading_Do_Not_Auto_Clear__c field should be false AND value of Grading_Pass_Verbiage__c field should not be equal to null AND Grading_Pass_Verbiage__c field should not be blank.
        3. Set 'Complete - All Results Clear' on Report_Case_Status__c field of PreEmploy_Case__c object, if value of Grading_Do_Not_Auto_Clear__c field should be false AND value of countClear variable should be greater than zero.
        4. Set 'Complete' on Report_Case_Status__c field of PreEmploy_Case__c object, if value of Grading_Do_Not_Auto_Clear__c field should be false AND value of countClear variable should be equal to zero.
        5. Call "SetCaseValueAfterUpdate" method of "BackgroundSearchTriggercl" class, if value of Grading_Do_Not_Auto_Clear__c field should be false.
        6. Call "SetCaseValueAfterUpdate" method of "BackgroundSearchTriggercl" class with different parameter, if value of Grading_Do_Not_Auto_Clear__c field should be true.

      2.3.3.2. Update the fields of PreEmploy_Case__c object:

        Logic:

        1. Size of listbc list should be greater than zero.
        2. Value of countCancelled variable should be equal to value of countTotal variable.
        3. Value of countHit variable should be equal to zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set True on IsAllSearchesClosed__c and IsAllSearchesCancelled__c field, set False on IsHitSearchPresent__c of PreEmploy_Case__c object.
        2. Call "SetCaseValueAfterUpdate" method of "BackgroundSearchTriggercl" class.

      2.3.3.3. Update the fields of PreEmploy_Case__c object:

        Logic:

        1. Size of listbc list and value of countHit variable should be greater than zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set True on IsAllSearchesClosed__c and IsHitSearchPresent__c field, set False on IsAllSearchesCancelled__c of PreEmploy_Case__c object.
        2. Call "SetCaseValueAfterUpdate" method of "BackgroundSearchTriggercl" class.

      2.3.3.4. Update the fields of PreEmploy_Case__c object:

        Logic:

        1. Size of listbc list should be equal to zero.
        2. Value of countCancelled variable should be equal to value of countTotal variable.
        3. Value of countHit variable should be equal to zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set 'Cancelled - Per Client Request' on Report_Case_Status__c field of PreEmploy_Case__c object.
        2. Set CaseCompleteRecordType.Id on RecordTypeId field of PreEmploy_Case__c object.

      2.3.3.5. Update the fields of PreEmploy_Case__c object:

        Logic:

        1. Size of listbc list should be equal to zero.
        2. Sum of countClear variable, countComplete variable, countCancelled variable should be equal to value of countTotal variable.
        3. Value of countHit variable should be equal to zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set 'Complete - All Results Clear' on Report_Case_Status__c field of PreEmploy_Case__c object, if value of countClear variable should be greater than zero.
        2. Set 'Complete' on Report_Case_Status__c field of PreEmploy_Case__c object, if value of countClear variable should be equal to zero.
        3. Set CaseCompleteRecordType.Id on RecordTypeId field of PreEmploy_Case__c object.

      2.3.3.6. Update the fields of PreEmploy_Case__c object:

        Logic:

        1. Size of listbc list should be equal to zero.
        2. Value of countHit variable should be greater than zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set 'Complete - Review Needed' on Report_Case_Status__c field of PreEmploy_Case__c object.
        2. Set CaseCompleteRecordType.Id on RecordTypeId field of PreEmploy_Case__c object.

      2.3.3.7. Update the fields of PreEmploy_Case__c object:

        Logic:

        1. Size of listbc list should be equal to zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set True on Report_Case_Closed__c field of PreEmploy_Case__c object, if Is8HoursDelayActivated__c field should be false AND IsDelayComplete__c should be true.
        2. Set current datetime on Report_Closed_Date__c field of PreEmploy_Case__c object, if Is8HoursDelayActivated__c field should be false AND IsDelayComplete__c should be true.
        3. Set false on Queue_For_Grading__c field of PreEmploy_Case__c object.

      2.4. Fetch the record on PreEmploy_Case__c object:

        Logic:

        1. countSearchComplete variable should not be equal to countTotal variable.

        If above condition are matched then script fetch following fields:

        Query:

        1. Query on PreEmploy_Case__c object and fetch the value of id, Name, Account_Name__c, Account__c, Report_Closed_Date__c, IsDelayComplete__c, Is8HoursDelayActivated__c, Invite_User_to_MBCR__c, MBC_User_Created__c, Report_Case_Status__c, Distributed_for_Formation__c, Formation_Complete__c, Queue_For_Grading__c, Report_Case_Closed__c, Subject_First_Name__c, Subject_Last_Name__c, No_Subject_of_Background_Contact__c, Subject_Email__c, Grading_Complete__c, RecordTypeId, Subject_of_background__c, Report_Case_Grade__c based on PreEmploy_Case__c field of Background_Search__c object AND Report_Case_Closed__c should be false.

      2.4.1. Create MBCR User:

        Logic:

        1. Size of listpc list and (value of countSearchTypeCredit OR countSearchTypeMotor OR countHit OR countNeedsReview variable) should be greater than zero.
        2. Value of Is8HoursDelayActivated__c and IsDelayComplete__c field of PreEmploy_Case__c object should be false.
        3. Value of Subject_of_background__c field of PreEmploy_Case__c object should be equal to null.
        4. Value of Status_Standard__c field of Background_Search__c object should not be equal to 'Cancelled/Not Requested'.

        If above condition are matched then script fetch and update following fields:

        Create Contact:

        1. Call "CreateContact" method of "MBCRUserCreation" class for create Contact record.

        Query:

        1. Query on User object and fetch the value of Id field based on id of Contact object should be equal to Subject_of_background__c of PreEmploy_Case__c object.

        Value assignment:

        1. Assign the value of above query in LstUserProfile list of User object.
        2. Call "CreateUser" method of "MBCRUserCreation" class for create an user.
        3. Set true on MBC_User_Created__c field of PreEmploy_Case__c object.
        4. Call "setSubjectOfSearchCall" method of this trigger for update Subject_Of_Search__c field.
        5. Set true on Is8HoursDelayActivated__c field of PreEmploy_Case__c object.
        6. Set current datetime on Hours8DelayStartTime__c field of PreEmploy_Case__c object.

      2.4.2. Create MBCR User:

        Logic:

        1. Size of listpc list should be greater than zero.
        2. Value of countSearchTypeCredit OR countSearchTypeMotor OR countHit OR countNeedsReview variable should be greater than zero.
        3. Value of Is8HoursDelayActivated__c and IsDelayComplete__c field of PreEmploy_Case__c object should be false.
        4. Value of Subject_of_background__c field of PreEmploy_Case__c object should not be equal to null.
        5. Value of MBC_User_Created__c field of PreEmploy_Case__c object should not be true.
        6. Value of Status_Standard__c field of Background_Search__c object should not be equal to 'Cancelled/Not Requested'.

        If above condition are matched then script fetch and update following fields:

        Query:

        1. Query on Contact object and fetch the value of accountID field based on Subject_of_background__c of PreEmploy_Case__c object and assign the value of query in LstCon list of Contact object.

        Delete Contact:

        1. Delete the value of LstCon list, if accountID of Contact object should be equal to null.

        Create Contact:

        1. Call "CreateContact" method of "MBCRUserCreation" class for create Contact record.

        Query:

        1. Query on User object and fetch the value of Id field based on id of Contact object should be equal to Subject_of_background__c of PreEmploy_Case__c object.

        Value assignment:

        1. Assign the value of above query in LstUserProfile list of User object.
        2. Call "CreateUser" method of "MBCRUserCreation" class for create an user.
        3. Set true on MBC_User_Created__c field of PreEmploy_Case__c object.
        4. Call "setSubjectOfSearchCall" method of this trigger for update Subject_Of_Search__c field.
        5. Set true on Is8HoursDelayActivated__c field of PreEmploy_Case__c object.
        6. Set current datetime on Hours8DelayStartTime__c field of PreEmploy_Case__c object.

      IV. Trigger.isAfter and Trigger.isInsert

      1.1. Fetch the data from BGC_DTOC_Order__c object:

        Logic:

        1. Value of Search_Type_Name__c field of Background_Search__c object should not be equal to null.
        2. Value of Search_Type_Name__c field of Background_Search__c object should be condition 'drug test' OR 'occ health'.

        If above condition are matched then script fetch and update following fields.

        Query:

        1. Query on BGC_DTOC_Order__c object and fetch the value of Id, Background_Search__c fields based on PreEmploy_Case__c field of Background_Search__c object AND Order_Details__c should not be equal to null AND Order_Details__c should be LIKE value of sSearch variable.

        Value assignment:

        1. Set 'Occupational' on sSearchType variable, if Search_Type_Name__c field should be contain 'occ health'.
        2. Set '%'+sSearchType+'%' on sSearch variable.
        3. Assign the value of above query on oDTOC list of BGC_DTOC_Order__c object.

      1.2. Update the record of BGC_DTOC_Order__c object:

        Logic:

        1. Merge the logic of point 1.1 .
        2. Size of oDTOC list should be greater than zero.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Assign the value of oDTOC list to oDTOCId object of BGC_DTOC_Order__c object.
        2. Set Id of Background_Search__c object to Background_Search__c field of BGC_DTOC_Order__c object.

      2. Create Statewide Search record:

        Logic:

        1. Jurisdiction__c of Background_Search__c object should not be equal to null.
        2. Search_Type_Name__c of Background_Search__c object should be equal to 'County Criminal'.

        If above condition are matched then script call following method:

        Call Method:

        1. Call "AddStateWiseSearch" method of this trigger.

      3. Fetch the data in PreEmploy_Case__c object:

        Logic:

        1. Search_Type_Name__c of Background_Search__c object should be equal to 'Credit Report' OR 'Motor Vehicle Report'.
        2. Status_Standard__c of Background_Search__c object should not be equal to 'Cancelled/Not Requested'.

        If above condition are matched then script fetch following fields:

        Query:

        1. Query on PreEmploy_Case__c object and fetch the value of Id, Name, Account_Name__c, Is8HoursDelayActivated__c, Hours8DelayStartTime__c, IsDelayComplete__c, Subject_of_background__c, Subject_First_Name__c, Subject_Last_Name__c, Invite_User_to_MBCR__c, No_Subject_of_Background_Contact__c, Subject_Email__c, account__c, isCaseCreate__c, Report_Closed_Date__c, MBC_User_Created__c, Report_Case_Status__c, Distributed_for_Formation__c fields based on PreEmploy_Case__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query in listpc list of PreEmploy_Case__c object.

      3.1. Create contact and fetch the data in User object:

        Logic:

        1. Size of listpc list should be greater than zero.
        2. value of Is8HoursDelayActivated__c and IsDelayComplete__c field of PreEmploy_Case__c object should be false.
        3. Subject_of_background__c of PreEmploy_Case__c object should be equal to null.

        If above condition are matched then script fetch, update and create following records:

        Call Method:

        1. Call "CreateContact" method of "MBCRUserCreation" class for create MBCR user contact.

        Query:

        1. Query on User object to fetch the value of Id field based on Subject_of_background__c field of PreEmploy_Case__c object.

        Value assignment:

        1. Assign the value of above query in LstUserProfile list of User object.
        2. Call "CreateUser" method of "MBCRUserCreation" class for create MBCR user, if size of LstUserProfile list should be equal to zero.
        3. Call "setSubjectOfSearchCall" method of this trigger, if size of LstUserProfile list should be equal to zero.
        4. Set true in MBC_User_Created__c field of PreEmploy_Case__c object, if size of LstUserProfile list should be equal to zero.

      3.2. Create contact and fetch the data in User object:

        Logic:

        1. Size of listpc list should be greater than zero.
        2. Is8HoursDelayActivated__c and IsDelayComplete__c field of PreEmploy_Case__c object should be false.
        3. Subject_of_background__c of PreEmploy_Case__c object should not be equal to null.

        If above condition are matched then script fetch, update and create following records:

        Query:

        1. Query on Contact object to fetch the value of accountID field based on Subject_of_background__c field of PreEmploy_Case__c object.

        Value assignment:

        1. Assign the value of above query in LstCon list of Contact object.
        2. Delete the value of LstCon list, if size of LstCon list should be greater than zero AND accountID field should be equal to null.
        3. Call "CreateContact" method of "MBCRUserCreation" class for create MBCR user contact, if size of LstCon list should be greater than zero AND accountID field should be equal to null.

        Query:

        1. Query on User object to fetch the value of Id field based on Subject_of_background__c field of PreEmploy_Case__c object.

        Value assignment:

        1. Assign the value of above query in LstUserProfile list of User object.
        2. Call "CreateUser" method of "MBCRUserCreation" class for create MBCR user, if size of LstUserProfile list should be equal to zero.
        3. Call "setSubjectOfSearchCall" method of this trigger, if size of LstUserProfile list should be equal to zero.
        4. Set true in MBC_User_Created__c field of PreEmploy_Case__c object, if size of LstUserProfile list should be equal to zero.

      3.3. Update the fields of PreEmploy_Case__c object:

        Logic:

        1. Size of listpc list should be greater than zero.
        2. value of Is8HoursDelayActivated__c and IsDelayComplete__c field of PreEmploy_Case__c object should be false.

        If above condition are matched then script update following fields:

        Value assignment:

        1. Set true on Is8HoursDelayActivated__c field.
        2. Set current datetime on Hours8DelayStartTime__c field.

      V. AddStateWiseSearch method

      Query:

      1. Query on Jurisdiction__c object, fetch the value of Id, State_Providence__c, State_Providence__r.Statewide_Research_Addition__c fields based on Jurisdiction__c field of Background_Search__c object.

      Value assignment:

      1. Assign the value of above query in LstJurisSearch list of Jurisdiction__c object.

      1. Update the value of bIsStatewideResearchAddition and sJurisState variable:

        Logic:

        1. Value of Id and State_Providence__c field of Jurisdiction__c object should not be equal to null.

        If above condition are matched then script update following variables:

        Value assignment:

        1. Set the value of State_Providence__r.Statewide_Research_Addition__c field of Jurisdiction__c object to bIsStatewideResearchAddition variable.
        2. Set the value of State_Providence__c field of Jurisdiction__c sJurisState variable.

      2.1. Update the value of sOrderId and sSubjectOfBackground variable:

        Logic:

        1. Value of bIsStatewideResearchAddition variable should be true.
        2. Value of Service_Ordered__c field of Background_Search__c object should not be equal to null.

        If above condition are matched then script update following variables:

        Query:

        1. Query on PreEmploy_Case__c object, fetch the value of Id, Order_Number__c, Subject_of_background__c fields based on PreEmploy_Case__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query in LstCaseOrder list of PreEmploy_Case__c object.
        2. Set the value of Order_Number__c field of PreEmploy_Case__c object to sOrderId variable, if size of LstCaseOrder list should be greater than zero.
        3. Set the value of Subject_of_background__c field of PreEmploy_Case__c object to sSubjectOfBackground variable, if size of LstCaseOrder list should be greater than zero.

      2.2. Update the value of iCount variable:

        Logic:

        1. Value of bIsStatewideResearchAddition variable should be true.
        2. Value of sOrderId variable and value of Service_Ordered__c field of Background_Search__c object should not be equal to null.

        If above condition are matched then script fetch the count of records:

        Query:

        1. Query on BGC_S_O_Individual__c object, fetch the Count of record based on sOrderId variable AND Selected_Service__r.Name should be equal to 'Statewide Criminal' OR Selected_Service__r.Name should be equal to 'Statewide Search' OR Selected_Service__r.Name should be equal to 'Statewide Research'.

        Value assignment:

        1. Assign the value of above query to iCount variable.

      3.1. Update the value of iCount, sOrderId, sOrderState and sSubjectOfBackground variable:

        Logic:

        1. Value of bIsStatewideResearchAddition variable should be true.
        2. Value of Service_Ordered__c field of Background_Search__c object should be equal to null.

        If above condition are matched then script fetch the count of records:

        Query:

        1. Query on Background_Search__c object, fetch the Id based on PreEmploy_Case__c, Alternate_Name__c, Archived_Alternate_Name_ID__c fields of Background_Search__c object AND sJurisState variable AND SearchType__r.Name should be equal to 'Statewide Criminal' OR SearchType__r.Name should be equal to 'Statewide Research' OR SearchType__r.Name should be equal to 'Statewide Search'.

        Value assignment:

        1. Assign the value of above query to LstBGS list of Background_Search__c object.
        2. Assign the size LstBGS list to iCount variable.

        Query:

        1. Query on PreEmploy_Case__c object, fetch the Id, Order_Number__c, Order_Number__r.State_Providence__c, Subject_of_background__c based on PreEmploy_Case__c field of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query to LstCaseOrder list of PreEmploy_Case__c object.
        2. Set the value of Order_Number__c field of PreEmploy_Case__c object to sOrderId variable, if the size of LstCaseOrder list should be greater than zero.
        3. Set the value of Order_Number__r.State_Providence__c field of PreEmploy_Case__c object to sOrderState variable, if the size of LstCaseOrder list should be greater than zero.
        4. Set the value of Subject_of_background__c field of PreEmploy_Case__c object to sSubjectOfBackground variable, if the size of LstCaseOrder list should be greater than zero.

      3.2. Update the value of iCount variable:

        Logic:

        1. Value of bIsStatewideResearchAddition variable should be true.
        2. Value of Service_Ordered__c, Archived_Alternate_Name_ID__c and Alternate_Name__c field of Background_Search__c object should be equal to null.
        3. Value of Archived_Additional_Address_ID__c or additional_address__c field of Background_Search__c object should not be equal to null.
        4. Value of iCount variable should be equal to zero.
        5. Value of sOrderId variable should not be equal to null.

        If above condition are matched then script fetch the count of records:

        Query:

        Query:

        1. Query on BGC_S_O_Individual__c object, fetch the Count of record based on sOrderId variable AND Selected_Service__r.Name should be equal to 'Statewide Criminal' OR Selected_Service__r.Name should be equal to 'Statewide Search' OR Selected_Service__r.Name should be equal to 'Statewide Research'.

        Value assignment:

        1. Assign the value of above query to iCount variable.
        2. Set zero on iCount variable, if value of sOrderState variable should not be equal to value of Applicant_State_Providence__c field of Background_Search__c object.

      3.2. Create "Statewide Search" type search:

        Logic:

        1. Value of bIsStatewideResearchAddition variable should be true.
        2. Value of iCount variable should be equal to zero.

        If above condition are matched then script update the following fields:

        Value assignment:

        1. Create Background_Search__c record as per current values of Background_Search__c record.

      VI. getIsSpclTaxResearch method

      This method is a parameterized method and it contain two parameter, one is bSpcltaxR variable that is boolean data type and other one is bgs object of Background_Search__c object.

      1. Update the value of bSpcltaxR variable:

        Logic:

        1. Value of bSpcltaxR variable should be true.

        If above condition are matched then script fetch and update the following fields:

        Query:

        1. Query on BGC_Configuration__c object and fetch the value of id, Specialty_Texas_Research__c field, based on Account__c of Background_Search__c object.

        Value assignment:

        1. Assign the value of above query on lstBgcConfig1 list of BGC_Configuration__c object.
        2. Set true on bSpcltaxR variable, if size of lstBgcConfig1 list should be greater than zero AND Specialty_Texas_Research__c should be true.

      VII. setSubjectOfSearchCall method

      This method is a parameterized method and it contain one parameter, sBGCase parameter is string data type.

      1. Set the value of Subject_Of_Search__c field of Background_Search__c object:

        Logic:

        1. Value of sBGCase variable should not be equal to null and blank.

        If above condition are matched then script fetch and update the following fields:

        Query:

        1. Query on Background_Search__c object with limit 100 and fetch the value of id, Subject_of_Search__c fields based on sBGCase variable AND Subject_of_Search__c should be equal to null.

        Value assignment:

        1. Assign the value of above query in lstBGSearch list of Background_Search__c object.
        2. Add one by one value of lstBGSearch to lstBGS string type list, if size of lstBGSearch list is greater than zero.
        3. Call "setSubjectOfSearch" method of "BackgroundSearchTriggercl" class, if the size of lstBGS list is equal to "5".
        4. Clear the size of lstBGS list, if the size of lstBGS list is equal to "5".

      2. Again set the value of Subject_Of_Search__c field of Background_Search__c object:

        Logic:

        1. Merge the logic of point 1.

        If above condition are matched then script fetch and update the following fields:

        Query:

        1. Query on Background_Search__c object with limit 4 and fetch the value of id, Subject_of_Search__c fields based on sBGCase variable AND Subject_of_Search__c should be equal to null.

        Value assignment:

        1. Assign the value of above query in lstBGSearch1 list of Background_Search__c object.
        2. Add one by one value of lstBGSearch1 to lstBGS1 string type list, if size of lstBGSearch1 list is greater than zero.
        3. Call "setSubjectOfSearch" method of "BackgroundSearchTriggercl" class.

About Background Search trigger class:

    Background Search object contains one "BackgroundSearchTrigger" trigger and this trigger contains one "BackgroundSearchTriggercl" class. This class contains different types of methods, which are perform different types of actions.

How to reach Background Search Trigger class:

    We can see the Background Search trigger class by using "Setup":

    Step 1: Click on the user name(Right corner of the screen).

    Step 2: Select setup.

    Step 3: In "App Setup", click on "Develop" >> click on "Apex Classes".

    Step 4: And find "BackgroundSearchTriggercl" class in list of class.

Working of Background Search trigger class:

    We have defined some methods, that are performed different types of actions.

    1. UpdateCaseRecordType
    2. FillListBackGroundSearch
    3. GetJurisListByCounty
    4. GetJurisListByState
    5. GetBGSOwner
    6. AppendMultiSearchTypeQuery
    7. SetCaseValueAfterUpdate
    8. AddNotes
    9. AddCase
    10. InsertSearchRestriction
    11. checkNullString
    12. setSubjectOfSearch

      I. UpdateCaseRecordType

      If this method is call then script fetch and update following fields:

      Query:

      1. Query on PreEmploy_Case__c object and fetch the value of id,Account__c,Report_Closed_Date__c,Report_Case_Status__c, Comp_Report_Sent__c,Queue_For_Grading__c,Report_Case_Closed__c, Grading_Complete__c, Report_Case_Grade__c, RecordTypeId, IsAllSearchesClosed__c, Is8HoursDelayActivated__c, Hours8DelayStartTime__c, IsHitSearchPresent__c, IsAllSearchesCancelled__c based on sCaseId variable AND Report_Case_Closed__c should be equal to null.

      Value assignment:

      1. Assign the value of above query in listpc list of PreEmploy_Case__c object.
      2. Update the current record of PreEmploy_Case__c object as per value of listpc list, if the size of listpc list is greater than zero.

      II. FillListBackGroundSearch

      This is a list type method and return list of Background_Search__c object.It contain following parameters:

      1. string sType
      2. string sListOfServiceID
      3. string sCaseId
      4. string sAlternateName
      5. string sCounty
      6. string sState
      7. string sCountry
      8. string sArchivedAlternateName
      9. string sJurisdiction
      10. string sFirstName
      11. string sLastName

      If this method is call then script fetch following fields:

      Query:

      1. Query on Background_Search__c object and fetch the value of id, Service_Ordered__c, Name fields based on sFirstName, sLastName, sListOfServiceID, sJurisdiction, sCounty, sState, sCountry, sCaseId, sAlternateName and sArchivedAlternateName variable.

      Value assignment:

      1. Assign the value of above query in LstBGS list of Background_Search__c object.

      III. GetJurisListByCounty

      This is a list type method and return list of Jurisdiction__c object.It contain following parameters:

      1. string sType
      2. string sLocationBasedType
      3. string sCounty
      4. string sSearchType
      5. boolean bIsLocationBased
      6. boolean bSpecialityTaxesResearch

      If this method is call then script fetch following fields:

      Query:

      1. Query on Jurisdiction__c object and fetch the value of id, State_Providence__c, Primary_Vendor__c, County__c, Scripted__c, Internal_Queue__c fields based on Active_Jurisdiction__c should be true AND Primary_Vendor__c should not be equal to null AND Jurisdiction_Rank__c should be equal to 'Specialty Texas Research' OR Jurisdiction_Rank__c should be equal to 'Primary-Default' AND Location_Based_Type__c should not be equal to null AND Location_Based_Type__c should be equal to sLocationBasedType variable AND County__c should not be equal to null AND County__c should be equal to sCounty AND Search_Type_1__c should not be equal to null AND Search_Type_1__c should be equal to sSearchType.

      Value assignment:

      1. Assign the value of above query in LstJuris list of Jurisdiction__c object.

      IV. GetJurisListByState

      This is a list type method and return list of Jurisdiction__c object.It contain following parameters:

      1. string sSearchName
      2. string sType
      3. string sLocationBasedType
      4. string sDLorIDState
      5. string sApplicantDLState
      6. string sDLStateFromCase
      7. string sSearchType
      8. boolean bIsLocationBased
      9. boolean bSpecialityTaxesResearch

      If this method is call then script fetch following fields:

      Query:

      1. Query on Jurisdiction__c object and fetch the value of id, State_Providence__c, Primary_Vendor__c, County__c, Scripted__c,Internal_Queue__c fields based on Active_Jurisdiction__c should be true AND Primary_Vendor__c should not be equal to null Jurisdiction_Rank__c should be equal to 'Specialty Texas Research' OR Jurisdiction_Rank__c should be equal to 'Primary-Default' AND Location_Based_Type__c should be equal to sLocationBasedType variable AND State_Providence__c should be equal to sDLorIDState OR State_Providence__c should be equal to sApplicantDLState OR State_Providence__c should be equal to sDLStateFromCase AND Search_Type_1__c should be equal to sSearchType.

      Value assignment:

      1. Assign the value of above query in LstJuris list of Jurisdiction__c object.

      V. GetBGSOwner

      This is Background_Search__c object type method.It contain following parameters:

      1. Jurisdiction__c singlejuris
      2. Background_Search__c b

      Logic:

      1. singlejuris variable should not be equal to null.

      If above condition are matched then script fetch and update following fields:

      Query:

      1. Query on Vendor__c object and fetch the value of Account__c field based on singlejuris object's Id and Jurisdiction__c should not be equal to null OR singlejuris object's Primary_Vendor__c field.

      Value assignment:

      1. Assign the value of above query in listvendor list of Vendor__c object.
      2. Assign the value of listvendor list to singlevendor object of Vendor__c object, if size of listvendor is greater than zero.
      3. Set the value of Account__c field of Vendor__c object to Researcher__c field of Background_Search__c object, if size of listvendor is greater than zero AND singlevendor object should not be equal to null.

      VI. AppendMultiSearchTypeQuery

      This is string data type method.It contain following parameters:

      1. string sType
      2. string sSearchType

      If this method is call then script update following fields:

      Value assignment:

      1. Add ' (Search_Type_1__c = \''+ sSearchType +'\' and Search_Type_1__c != null) OR ' on sSOQL variable, if value of sType variable is equal to 'Multi4SearchType'.
      2. Add ' (Search_Type_2__c = \''+ sSearchType +'\' and Search_Type_2__c != null) OR ' on sSOQL variable.
      3. Add ' (Search_Type_3__c = \''+ sSearchType +'\' and Search_Type_3__c != null) OR ' on sSOQL variable.
      4. Add ' (Search_Type_4__c = \''+ sSearchType +'\' and Search_Type_4__c != null) ) ' on sSOQL variable.

      VII. SetCaseValueAfterUpdate

      This is PreEmploy_Case__c object type method.It contain following parameters:

      1. PreEmploy_Case__c pc
      2. string sReportCaseStatus
      3. string sRecordTypeId
      4. boolean bIsGradingComplete
      5. datetime dtReportClosedDate
      6. boolean bIsReportCaseClosed
      7. boolean bIsQueueForGrading

      If this method is call then script update following fields:

      Value assignment:

      1. Set the value of sReportCaseStatus variable to Report_Case_Status__c field of PreEmploy_Case__c object, if sReportCaseStatus is not equal to null.
      2. Set the value of sRecordTypeId variable to RecordTypeId field of PreEmploy_Case__c object, if sRecordTypeId is not equal to null.
      3. Set the value of bIsGradingComplete variable to Grading_Complete__c field of PreEmploy_Case__c object, if bIsGradingComplete is not equal to null.
      4. Set the value of dtReportClosedDate variable to Report_Closed_Date__c field of PreEmploy_Case__c object, if dtReportClosedDate is not equal to null.
      5. Set the value of bIsReportCaseClosed variable to Report_Case_Closed__c field of PreEmploy_Case__c object, if bIsReportCaseClosed is true AND Is8HoursDelayActivated__c is false OR IsDelayComplete__c is true.
      6. Set false on Report_Case_Closed__c field of PreEmploy_Case__c object, if bIsReportCaseClosed is false AND Is8HoursDelayActivated__c is true OR IsDelayComplete__c is false.
      7. Set null on Report_Closed_Date__c field of PreEmploy_Case__c object, if bIsReportCaseClosed is false AND Is8HoursDelayActivated__c is true OR IsDelayComplete__c is false.
      8. Set the value of bIsQueueForGrading variable to Queue_For_Grading__c field of PreEmploy_Case__c object, if bIsQueueForGrading is not equal to null.

      VIII. AddNotes

      This is Background_Search__c object type method.It contain following parameter:

      1. Background_Search__c b

      If this method is call then script update following fields:

      Value assignment:

      1. Set 'This search is restricted for certain industries; we are unable to process this search at this time. Please contact your customer service representative. If No response is received within 48 hours this search will be closed.' value on sNotesToPreClient variable.
      2. Set 'This search is restricted for certain industries, records show that the industry in the assigned account does not match the industries approved for this jurisdiction. Notification has been sent to customer service.' value on sNoteInternal variable.
      3. Set 'b.Notes_Pre_to_Client__c + Salesforcecl.timestamp( '', sNotesToPreClient )' on Notes_Pre_to_Client__c field of Background_Search__c object, if Notes_Pre_to_Client__c is not equal to null.
      4. Set 'Salesforcecl.timestamp( b.Notes_Pre_to_Client__c , sNotesToPreClient )' on Notes_Pre_to_Client__c field of Background_Search__c object, if Notes_Pre_to_Client__c is equal to null.
      5. Set 'b.Notes_Internal__c + Salesforcecl.timestamp( '', sNoteInternal)' on Notes_Internal__c field of Background_Search__c object, if Notes_Internal__c is not equal to null.
      6. Set 'Salesforcecl.timestamp( b.Notes_Internal__c , sNoteInternal)' on Notes_Internal__c field of Background_Search__c object, if Notes_Internal__c is equal to null.

      IX. AddCase

      This is void type method.It contain following parameter:

      1. Background_Search__c b

      If this method is call then script fetch and update following fields:

      Query:

      1. Query on Jurisdiction__c object and fetch the value of Industry__c field based on Jurisdiction__c field of Background_Search__c object.

      Value assignment:

      1. Assign the value of above query to listjuris list of Jurisdiction__c object.
      2. Set the value of Industry__c field to sJurisIndustry variable, if size of listjuris list greater than zero.

      Insert Case record:

      1. Subject ='Unable to Process Search'.
      2. Origin = 'Internal'.
      3. Reason = 'Other (Comment Required)'.
      4. Status = 'New', Priority = 'High', .
      5. Description = 'This search is restricted for certain industries; we are unable to process this search at this time. The industry's approved for these jurisdictions are: ' + sJurisIndustry + ' .If this client meets the industry criteria, then the account will need to be updated so that this message doesn't appear in the future, otherwise the search will need to be cancelled.'.
      6. AccountId = b.Account__c.
      7. Background_Search__c = b.id.
      8. Related_Background_Check__c = b.PreEmploy_Case__c.

      X. InsertSearchRestriction

      This is Background_Search__c object type method.It contain following parameter:

      1. Background_Search__c b

      Logic:

      1. value of Jurisdiction__c field of Background_Search__c should not be equal to null.

      If above condition are matched then script fetch and update following fields:

      Query:

      1. Query on Jurisdiction__c object and fetch the value of Industry_Specific__c, Industry__c fields based on Jurisdiction__c field of Background_Search__c object.

      Value assignment:

      1. Assign the value of above query in lstjuris list of Jurisdiction__c object.
      2. Set the value of Industry_Specific__c to bIndustrySpecific variable, if size of lstjuris list is greater than zero.
      3. Set the value of Industry__c to sIndustry variable, if size of lstjuris list is greater than zero.
      4. Set 'No Restriction on Search' on Search_Restriction__c field of Background_Search__c object, if Industry_Specific__c is false.

      Logic:

      1. value of Industry_Specific__c field of Jurisdiction__c should be true.

      If above condition are matched then script fetch and update following fields:

      Query:

      1. Query on Account object and fetch the value of Industry field based on Account__c field of Background_Search__c object.

      Value assignment:

      1. Assign the value of above query in lstAcc list of Account object.
      2. Set the value of Industry field to sIndustryAcc variable, if size of lstAcc list is greater than zero.
      3. Set 'Approved to Run Industry Restricted Search' on Search_Restriction__c field of Background_Search__c object, if size of lstAcc list is greater than zero AND sIndustry variable is contain the value of sIndustryAcc variable.
      4. Set 'Not Approved to Run Industry Restricted Search' on Search_Restriction__c field of Background_Search__c object, if size of lstAcc list is greater than zero AND sIndustry variable is not contain the value of sIndustryAcc variable.
      5. Set 'Hold' on Status_Standard__c field of Background_Search__c object, if size of lstAcc list is greater than zero AND sIndustry variable is not contain the value of sIndustryAcc variable.
      6. Call "AddCase" method, if size of lstAcc list is greater than zero AND sIndustry variable is not contain the value of sIndustryAcc variable.
      7. Call "AddNotes" method, if size of lstAcc list is greater than zero AND sIndustry variable is not contain the value of sIndustryAcc variable.
      8. Set 'No Restriction on Search' to Search_Restriction__c field of Background_Search__c object, if size of lstAcc list is equal to zero.

      XI. checkNullString

      This is string data type method.It contain following parameter:

      1. string sValue

      Logic:

      1. value of sValue variable should be equal to null.

      If above condition are matched then script update following field:

      Value assignment:

      1. Set blank on sValue variable.

      XII. setSubjectOfSearch

      This is string data type method.It contain following parameters:

      1. List lstSearch
      2. string sBackgroundSubject

      If this method is call then script update following field:

      Value assignment:

      1. Set the value of sBackgroundSubject variable to Subject_of_Search__c field of Background_Search__c object.