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

help me on test class

global class CreatedAccounts
{
  @InvocableMethod
  global static void CreatedAccount(List<ClsCheckMDM> checkList)
  {
    Id uId = userinfo.getUserId();
    List<Account> updateList = new List<Account> ();
    User partnerCreatedUser = [SELECT Id FROM User WHERE Name = 'Partner Created Account' LIMIT 1];
    User userRec = [SELECT Id, ABB_Manager__c from user where id = :uId LIMIT 1];
    List<Id> accountIds = new List<Id> ();

    for (ClsCheckMDM check : checkList)
    {
      accountIds.add(check.accountId);
    }

    Map<Id, Account> accountMap = new Map<Id, Account> ([SELECT Id, OwnerId FROM Account WHERE Id IN :accountIds LIMIT 100]);
    Map<Id, List<Account_team__c>> accountTeamMap = new Map<Id, List<Account_team__c>> ();

    for(Account_team__c accountTeam : [SELECT Id, Account__c, Account_Access__c, User__c FROM Account_team__c WHERE Account__c IN :accountMap.keySet()])
    {
      if(accountTeamMap.containsKey(accountTeam.Account__c))
      {
        accountTeamMap.get(accountTeam.Account__c).add(accountTeam);
      }
      else
      {
        accountTeamMap.put(accountTeam.Account__c, new List<Account_team__c> { accountTeam });
      }
    }

    List<AccountShare> accountShareRecord = new List<AccountShare> ();
    for (ClsCheckMDM check : checkList)
    {

      if (accountMap.containsKey(check.accountId))
      {
        Account acc = accountMap.get(check.accountId);
        if (!check.isMDM)
        {

          if (accountTeamMap.containsKey(acc.Id))
          {
            for (Account_team__c accountTeam : accountTeamMap.get(acc.Id))
            {
              accountShareRecord.add(new AccountShare
              (
               AccountId = accountTeam.Account__c,
               UserOrGroupId = accountTeam.User__c,
               AccountAccessLevel = (accountTeam.Account_Access__c == 'Read/Write') ? 'Edit' : 'Read',
               OpportunityAccessLevel = 'Read',
               RowCause = 'Manual'
              ));

            }
          }

          acc.OwnerId = partnerCreatedUser.Id;

        }
        else
        {
          acc.OwnerId = userRec.ABB_Manager__c;
        }
        updateList.add(acc);
      }
    }
    try
    {
      update updateList;
      if (!accountShareRecord.isEmpty())
      {
        insert accountShareRecord;
      }
    }
    catch(Exception ex)
    {
      System.debug(logginglevel.ERROR, ex.getMessage());
    }
  }

  global class ClsCheckMDM
  {
    @InvocableVariable
    global Id accountId;

    @InvocableVariable
    global Boolean isMDM;
  }

}

 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi shambavi,

May I suggest you please check the  "Test Generator app" This app helps you to generate test class for controller, trigger & batch. Hope it helps.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar

 
shambavishambavi
Hi Rahul

Thanks For giving reply, in my org don't have to acces to install this App. could you please help me on this...

Thanks...