• shambavi
  • NEWBIE
  • 40 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
global class PartnerUserNotLoggedfor30DaysBatch implements Database.Batchable<sObject>{
    
    Date myDate;
    
    Date myDate30Days;
    Id email30DaysTemplateId;
    
    global PartnerUserNotLoggedfor30DaysBatch(){
        myDate = Date.today();
        myDate30Days= Date.today()+30;
        
    }
   
    global Database.querylocator start(Database.BatchableContext BC)
    {
        return Database.getQueryLocator([SELECT Id,name,IsActive,isFrozen__c,IsPortalEnabled,Validity_Date__c,ABB_Manager__c,
                            Profile.name,LastLoginDate,email FROM User WHERE IsPortalEnabled = true AND IsActive = true 
                            AND isFrozen__c = false AND (Profile.Name=:Label.SYS_ABBExtChannelPartnerCommunityUser 
                            OR Profile.Name=:Label.SYS_ABB_Ext_Rep_Community_User 
                            OR Profile.Name=:Label.SYS_ABB_Ext_Agent_Community_User)
                            AND LastLoginDate =: myDate30Days]);   
    }
    global void execute(Database.BatchableContext BC, List<User> listOfUsers)
    { 
    
        Set<Id> setChnlMngrIds=new Set<Id>();
        Set<Id> set30DaysExpUsers = new set<Id>();
        Set<Id> set4WksExpUsers = new set<Id>();
        Map<Id,User> mapOf30DaysExpUsers = new Map<Id,User>();
        Map<Id,User> mapOf4WksExpUsers = new Map<Id,User>();
        Map<Id,User> mapOfABBMngrEmails;
        
        if(listOfUsers.size()>0 && listOfUsers != null){
            
            for(user usr : listOfUsers){
                setChnlMngrIds.add(usr.ABB_Manager__c);
                if(usr.LastLoginDate == myDate30Days){
                    set30DaysExpUsers.add(usr.id);
                    mapOf30DaysExpUsers.put(usr.id,usr);
                }
            }
            if(setChnlMngrIds.size()>0){
            mapOfABBMngrEmails = new Map<Id,User>([Select id,name,email from User where id =: setChnlMngrIds Limit 5000 ]);
            }
            
            List<String> lstToAddRecp = new List<String>();
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
            
            if(mapOf30DaysExpUsers != null && mapOf30DaysExpUsers.size()>0){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                for(User usr : mapOf30DaysExpUsers.values()){
                    String BodyText = '<html><body>Dear '+ usr.name +'<br/><br/>'+
                                        'Not Logged for 30 days '+ usr.LastLoginDate+'.'+
                                        '<br/><br/>'+
                                        'To extend your access for next 365 days please contact your ABB Channel Manager.'+
                                        '<br/><br/>Best regards,<br/>SFDC Team<br/><br/>'+
                                        'This is system notification. Please do not reply to this email.'+
                                        '</body></html>'; 
                                        email.setHtmlBody(BodyText );
                    lstToAddRecp.add(usr.email);
                    email.setToAddresses(lstToAddRecp);
                    
                    email.setTargetObjectId(usr.id);
                    email.setSaveAsActivity(false);
                    emails.add(email);    
                    lstToAddRecp.clear();
                }
            }
            
            
            if(emails != null){                    
                Messaging.SendEmailResult[] results = Messaging.sendEmail(emails);
                
            }
            
        }
        
        
    }
    
    global void finish(Database.BatchableContext BC)
      {

      }
}

Thnaks in Advance..
public with sharing class AccountListWrapper {
   
   public with sharing class DisplayAccountRecords {
        
        @AuraEnabled public Id AccountId { get; set; }
        @AuraEnabled public Account AccountRecord { get; set; }
        @AuraEnabled public Boolean IsSelected { get; set; }
        @AuraEnabled public String AccountConfig { get; set; }
        @AuraEnabled public String strGUID {get;set;}
        
        public DisplayAccountRecords(){
               IsSelected = false;
        }
        
    }
}

Thanks in Advance... 
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;
  }

}

 
public class BitSet {
 public Map < String, Integer > alphaNumCharCodes {
  get;
  set;
 }
 public Map < String, Integer > base64CharCodes {
  get;
  set;
 }
 
 public BitSet() {
  LoadCharCodes();
 }

 public void LoadCharCodes() {
  alphaNumCharCodes = new Map < String, Integer > {
   'A' => 65,
   'B' => 66,
   'C' => 67,
   'D' => 68,
   'E' => 69,
   'F' => 70,
   'G' => 71,
   'H' => 72,
   'I' => 73,
   'J' => 74,
   'K' => 75,
   'L' => 76,
   'M' => 77,
   'N' => 78,
   'O' => 79,
   'P' => 80,
   'Q' => 81,
   'R' => 82,
   'S' => 83,
   'T' => 84,
   'U' => 85,
   'V' => 86,
   'W' => 87,
   'X' => 88,
   'Y' => 89,
   'Z' => 90
  };
  base64CharCodes = new Map < String, Integer > ();
 
  Set < String > pUpperCase = alphaNumCharCodes.keySet();
  for (String pKey: pUpperCase) {
 
   alphaNumCharCodes.put(pKey.toLowerCase(), alphaNumCharCodes.get(pKey) + 32);
 
   base64CharCodes.put(pKey, alphaNumCharCodes.get(pKey) - 65);
   base64CharCodes.put(pKey.toLowerCase(), alphaNumCharCodes.get(pKey) - (65) + 26);
  }
 
  for (Integer i = 0; i <= 9; i++) {
   alphaNumCharCodes.put(string.valueOf(i), i + 48);
  
   base64CharCodes.put(string.valueOf(i), i + 52);
  }
    /
    AlphaNumCharCodes.put('+', 43);
    AlphaNumCharCodes.put('/', 47);
    Base64CharCodes.put('+', 62);
    Base64CharCodes.put('/', 63);
 }
 
 public List < Integer > testBits(String pValidFor, List < Integer > nList) {
  List<Integer> ret = new List<Integer>();
    Integer target = 0;
    
    for(Integer i=0; i < pValidFor.length();i++){
        Integer cur = (Base64CharCodes.get((pValidFor.Substring(i, i+1))));
       
        for (Integer j = 0; j < 6; j++) {
            if ((cur & 32) == 32) {
                for(Integer n : nList){
                    if(target == n){
                        ret.add(target);
                        break;
                    }
                }
            }
           
            cur <<= 1;
      
            target++;
        }
    }
    return ret;

 }
 public class PicklistEntryWrapper{
    
    public PicklistEntryWrapper(){}
    public String active {get;set;}
    public String defaultValue {get;set;}
    public String label {get;set;}
    public String value {get;set;}
    public String validFor {get;set;}
 }
}

Thanks in Advance...
Please create a Custom List View Button "New Case" that will pre-populate the Contact, Account, Email, based on the current logged in User if the User is external (community profile) and use the standard functionality if he is not
The contact field should be updated with $User.ContactID if the Record Type is Case from Communities


Thanks in Advance.......


Thanks & Regards
Gopal. 
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;
  }

}

 
Please create a Custom List View Button "New Case" that will pre-populate the Contact, Account, Email, based on the current logged in User if the User is external (community profile) and use the standard functionality if he is not
The contact field should be updated with $User.ContactID if the Record Type is Case from Communities


Thanks in Advance.......


Thanks & Regards
Gopal.