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
Pradeep dPradeep d 

need help to do code coverage

public class contactPaginationController{
    Public contactPaginationController(){
        
    }
    //variable used in page.
    Public Integer size{
        get;
        set;
    }
    Public Integer noOfRecords{
        get;
        set;
    }
    public List<SelectOption> paginationSizeOptions{
        get;
        set;
    }
    public static final Integer QUERY_LIMIT = 1000;
    public static final Integer PAGE_SIZE = 10;
    public Contact con {
        set;
        get;
    }
    public static string SelectedOption {
        get;
        set;
    }
    public static string selectedOperatorOption {
        get;
        set;
    }
    public string enteredText {
        get;
        set;
    }
    public string selectedDataType {
        get;
        set;
    }
    public List < SelectOption > options {
        get;
        set;
    }
    public Map<string, string> checkDataTypeMap{
        set;
        get;
    }
    public List < SelectOption > operatorOptions {
        get;
        set;
    }
    public boolean selectedAllProperties {
        get;
        set;
    }
    public transient Map < String, Schema.SObjectType > schemaMap = Schema.getGlobalDescribe();
    public List <WrapperClass> wrapperRecordList{
        get;
        set;
    }
    public Map<Id, WrapperClass> mapHoldingSelectedRecords{
        get;
        set;
    }
    public List<Wrapperclass> paginationmap{
        get;
        set;
    }
    public integer count {
        get;
        set;
    }
    public Integer Totalcount{
        get;
        set;
    }
    public string schedulestate{
        get;
        set;
    }
    public integer rccount{
        get;
        set;
    }
    public Set<Id> Selectedids;
    public decimal rdc{set;get;}
    public date ltd {set;get;}
    public List<record_count__c> Rfc {set;get;}
    public List<Contact> contactstatus {set;get;}
    public string Lasttransactionstatus {set;get;}
    public string orgtName;
    
    //constructor calling init method.
    public contactPaginationController(ApexPages.StandardController controller){
        mapHoldingSelectedRecords = new Map<Id, WrapperClass>();
        paginationmap =  new List<WrapperClass>();
        con =  new contact();
        options = new List < SelectOption > ();
        checkDataTypeMap = new Map < String, string > ();
        operatorOptions = new List < SelectOption > ();
        organization orgName = [select id, name from Organization];
        orgtName = orgName.name;
        system.debug('orgname ' + orgtName);
        contactstatus = [select id from contact where direct_send__c = true limit 10000];
        if(!contactstatus.isEmpty()){
            Lasttransactionstatus = 'Pending';
        }
        else{
            Lasttransactionstatus = 'Completed';
        }  
        Rfc =  [select count__c, last_transaction_date__c from record_count__c limit 1];
        for(record_count__c rd: Rfc){
            rdc = Rd.count__c;
            ltd = Rd.last_transaction_date__c;
        }
        ltd = date.valueof(ltd);
        system.debug('Custom Setting : ' + Rfc);
        //To fetch the Contact fields by Describe call
        Selectoption sv = new SelectOption('--Please Select--', '--Please Select--');
        Options.add(sv);
        Map < String, Schema.SObjectField > ContactFieldsMap = SchemaMap.get('Contact').getDescribe().fields.getMap();
        for (Schema.SObjectField sField: ContactFieldsMap.Values()) {      
            schema.describefieldresult fieldName = sfield.getDescribe();
            Schema.DisplayType fielddataType = sfield.getDescribe().getType();
            string fieldType = string.valueOf(fielddataType);
            SelectOption sp = new SelectOption(fieldName.getName(), fieldName.getName());
            checkDataTypeMap.put(fieldName.getName(), fieldType);
            options.add(sp);
            options.sort();      
        }  
        //Add the filter conditons feteched from Custom settings to show in picklist
        SelectOption selOpt = new SelectOption('--Please Select--', '--Please Select--');
        operatorOptions.add(selOpt);
        List < CustomCondition1__c > filetConditions = CustomCondition1__c.getall().values();
        for (CustomCondition1__c Fcon: filetConditions) {      
            SelectOption Fsp = new SelectOption(Fcon.Name, Fcon.Name);
            operatorOptions.add(Fsp);
            operatorOptions.sort();          
        } 
    }
    
    
    
    
    //Init method which queries the records from standard set controller.
    public void init() {        
        wrapperRecordList = new List<WrapperClass>();
        system.debug(setCon.getRecords());
        for (Contact cont : (List<Contact>)setCon.getRecords()) {  
            if(mapHoldingSelectedRecords != null && mapHoldingSelectedRecords.containsKey(cont.id)){
                wrapperRecordList.add(new WrapperClass(cont,true));       
            }
            else{
                wrapperRecordList.add(new WrapperClass(cont, false));
            }          
        }
        system.debug(wrapperRecordList.size()); 
        
    }
    public List<Contact> conlist =  new List<contact>();
    public string doql;
    /** Instantiate the StandardSetController from a query locater*/
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                
                //string soql = 'select id, lastname, name, email, phone from contact Limit :QUERY_LIMIT';
                
                string soql = 'SELECT id,LastName,AssistantName,AssistantPhone,Birthdate,Department,Description,Email,Fax,';
                soql      += 'HomePhone,MailingAddress,MailingCity,MailingCountry,MailingPostalCode,MailingState,datefield__c,To_date__c,' ;
                soql      += 'MailingStreet,MobilePhone,Name,firstname,OtherAddress,OtherCity,OtherCountry,OtherPhone,OtherPostalCode,';
                soql      += 'OtherState,OtherStreet,Account.Name,LastModifiedDate,Phone,Title,Mail_Sent_Date__c,' ;
                soql      += '(SELECT Assistant_Name__c,Assistant_Phone__c,Birthdate__c,Contact__c,CreatedById,'
                    + 'CreatedDate,Department__c,Description__c,Email__c,Fax__c,First_Name__c,Home_Phone__c,Id,IsDeleted,Mailing_City__c,'
                    +'Mailing_Country__c,Mailing_State_Province__c,Mailing_Street__c,Mailing_Zip_Postal_Code__c,Mobile_Phone__c,Name,'
                    +'Other_City__c,Other_Country__c,Other_Phone__c,Other_State_Province__c,Other_Street__c,Other_Zip_Postal_Code__c,'
                    +'OwnerId,Phone__c,Title__c from Cons__r) From Contact  ';
                doql = soql;
                system.debug('doql : ' + doql);
                
                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(soql + ' Limit : QUERY_LIMIT' ));
                system.debug(setCon);
                
            }
            //Search();
            return setCon;
        }
        set;
    }
    
    public void countpage(){
        contactPaginationController_utility cu = new contactPaginationController_utility();
        cu.fromDate = fromDate;  
        cu.toDate = toDate;
        cu.lastDate30 = lastDate30 ;
        cu.lastDate60 = lastDate60 ;
        cu.lastDate90 = lastDate90 ;
        
        cu.querybat = querybat;
        cu.countall();
        
    } 
    public string querybat;
    public boolean directsend;
    public datetime fromDate;
    public datetime toDate;
    public date lastDate30;
    public date lastDate60;
    public date lastDate90;
    public List<CronTrigger> crontrig;
    public Id scheduleid;
    public void Search(){
        
        
        fromDate = con.datefield__c;
        toDate = con.To_date__c;
        directsend = con.schedule_check__c;
        lastDate30 = System.today().addDays(-30);
        lastDate60 = System.today().addDays(-60);
        lastDate90 = System.today().addDays(-90);
        system.debug(doql);
        string whereConditions = 'where ';
        string resultQuery = '' ;
        
        
        if(con.datefield__c !=null && con.To_date__c !=null){          
            resultQuery  = doql + whereConditions + ' LastModifiedDate >= :fromDate AND LastModifiedDate <= :toDate' ;
            
        }
        if(Con.Last_Sent_Date__c !='--None--'){
            resultQuery  =  getLastsentDate(Con.Last_Sent_Date__c ,resultQuery) ;
            //   conlist = database.query(resultQuery + ' Limit : QUERY_LIMIT');
            //  system.debug(conlist);
        }
        if(string.isNotBlank(SelectedOption) && string.isNotBlank(selectedOperatorOption) && string.isNotBlank(enteredText)){
            resultQuery = getOperatorSelection(SelectedOption,selectedOperatorOption,resultQuery,enteredText) ;
        }  
        system.debug(resultQuery + ' Limit : QUERY_LIMIT');
        
        
        querybat= resultQuery;
        
        if(directsend== true){
            
            updatecheck b2 = new updatecheck();
            
            b2.fromDate = fromDate;  
            b2.toDate = toDate;
            b2.lastDate30 = lastDate30 ;
            b2.lastDate60 = lastDate60 ;
            b2.lastDate90 = lastDate90 ;
            b2.queryString = querybat;  
            
            Database.executeBatch(b2); 
            
            
        }
        else{
            
            setCon = new ApexPages.StandardSetController(Database.getQueryLocator(resultQuery + ' Limit : QUERY_LIMIT' ));
            system.debug(setCon.getRecords());
            
            setCon.setPageSize(PAGE_SIZE);
            init();
            
        }
        system.debug(setCon);
        
        
    }
    
    public void deselection(){
        updatefalse b2 = new updatefalse();
        database.executebatch(b2);
        
        //    contactPaginationController_utility.deselectall();   
        
    }
    
    
    
    
    /** indicates whether there are more records after the current page set.*/
    public Boolean hasNext {
        get {
            return setCon.getHasNext();
        }
        set;
    }
    
    /** indicates whether there are more records before the current page set.*/
    public Boolean hasPrevious {
        get {
            return setCon.getHasPrevious();
        }
        set;
    }
    
    /** returns the page number of the current page set*/
    public Integer pageNumber {
        get {
            return setCon.getPageNumber();
        }
        set;
    }
    
    /** return total number of pages for page set*/
    Public Integer getTotalPages(){
        Decimal totalSize = setCon.getResultSize();
        Decimal pageSize = setCon.getPageSize();
        Decimal pages = totalSize/pageSize;
        return (Integer)pages.round(System.RoundingMode.CEILING);
    }
    
    /** returns the first page of the page set*/
    public void first() { 
        selectmethod();
        setCon.first();   
        init();
        
    }
    
    /** returns the last page of the page set*/
    public void last() {
        selectmethod();
        setCon.last();
        init();
    }
    
    /** returns the previous page of the page set*/
    public void previous() {
        selectmethod();
        setCon.previous();
        init();
    }
    
    /** returns the next page of the page set*/
    public void next() {
        selectmethod();
        setCon.next();
        init();
    }
    
    private string getLastsentDate(string lastSentDate,string dynamicSoql){
        
        if(con.Last_Sent_Date__c =='30 days')
            dynamicSoql = dynamicSoql + ' and Mail_Sent_Date__c < :lastDate30';
        if(con.Last_Sent_Date__c =='60 days')
            dynamicSoql = dynamicSoql + ' and Mail_Sent_Date__c < :lastDate60';
        if(con.Last_Sent_Date__c =='90 days')
            dynamicSoql = dynamicSoql + ' and Mail_Sent_Date__c < :lastDate90';
        if(con.Last_Sent_Date__c =='Contacted')
            dynamicSoql = dynamicSoql + ' and Mail_Sent_Date__c != null';
        if(con.Last_Sent_Date__c =='Not Contacted')
            dynamicSoql = dynamicSoql + ' and Mail_Sent_Date__c = null';
        
        return dynamicSoql;
    }
    private string getOperatorSelection(string SelectedOption,string selectedOperator,string dynamicSoql,string enteredText){
        string selectedDataType = checkDataTypeMap.get(SelectedOption);
        if (selectedOperatorOption == 'Equal to'){
            if(selectedDataType == 'BOOLEAN' || selectedDataType == 'Id')
                dynamicSoql = dynamicSoql + ' AND '+ SelectedOption + '= ' + enteredText; 
            else
                dynamicSoql = dynamicSoql + ' AND '+ SelectedOption + '= ' + '\'' + enteredText + '\'';
        }
        if (selectedOperatorOption == 'Not equal to'){
            if(selectedDataType == 'BOOLEAN' || selectedDataType == 'Id')
                dynamicSoql = dynamicSoql +' AND' + SelectedOption + '!= ' + enteredText;
            else
                dynamicSoql = dynamicSoql + ' AND '+ SelectedOption + '!= ' + '\'' + enteredText + '\'';
        }
        return dynamicSoql;        
    }
    
    public void selectAllChks(){
        selectedAllProperties = true;
        
    }  
    public List<Contact> checkupdate = new List<Contact>(); 
    public List<Contact> boolupdate = new List<Contact>();
    public void selectmethod() {
        system.debug('wrapper size :' + wrapperRecordList);
        if(!wrapperRecordList.isEmpty())
            for(WrapperClass wrp : wrapperRecordList){
                if(wrp.isSelected ){
                    mapHoldingSelectedRecords.put(wrp.contactRecord.id, wrp);
                    
                }
                
                if(wrp.isSelected == false && mapHoldingSelectedRecords.containsKey(wrp.contactRecord.id)){
                    mapHoldingSelectedRecords.remove(wrp.contactRecord.id);
                }
            }  
        system.debug(mapHoldingSelectedRecords.size());
        
    }
    //This is the method which manages to remove the deselected records, and keep the records which are selected in map.
    public List<Contact> ctlist = new List<Contact>();
    public string cont;
    public pageReference updateSearchItemsMap() {
        // if(directsend== false)
        selectmethod();           
        set<Id> executeNowSet = new set<Id>();
        selectedIds = new Set<Id>();           
        if(!mapHoldingSelectedRecords.isEmpty()){    
            selectedIds = mapHoldingSelectedRecords.keyset();
            count =mapHoldingSelectedRecords.size(); 
            cont = string.valueOf(count);
            for(wrapperclass wr : mapHoldingSelectedRecords.values()){
                ctlist.add(wr.contactRecord );
            }
            for(Contact c : ctlist){
                c.Direct_send__c = true;
                checkupdate.add(c);
            }
            try{
                update checkupdate;
                system.debug('checkupdate : ' + checkupdate); 
            }
            catch(Exception e){
                system.debug(e.getMessage());
            }
            List<record_count__c> settings = [select count__c,Last_Transaction_Date__c from record_count__c limit 1];
            if(!settings.isEmpty()){
                for(record_count__c rc : settings)
                {
                    rc.count__c = Count;
                    rc.Last_Transaction_Date__c = system.today();
                    update rc;
                }
            }
            
            if(mapHoldingSelectedRecords.size()>0  && mapHoldingSelectedRecords.size() <= 10){
                system.debug('size' + mapHoldingSelectedRecords.size());
                try{
                    if(!mapHoldingSelectedRecords.isEmpty())
                        apiCall(orgtName,cont);
                        sendemail();
                }
                catch(Exception e){
                    system.debug(e.getmessage());
                }
            }
            
            else{
                touchcontactbatch objtouchcontactbatch = new touchcontactbatch ();
                objtouchcontactbatch.SelectedId = selectedIds ;
                objtouchcontactbatch.queryString = querybat;  
                objtouchcontactbatch.fromDate = fromDate;  
                objtouchcontactbatch.toDate = toDate;
                objtouchcontactbatch.lastDate30 = lastDate30 ;
                objtouchcontactbatch.lastDate60 = lastDate60 ;
                objtouchcontactbatch.lastDate90 = lastDate90 ;
                
                //  for(integer i=0;i<mapHoldingSelectedRecords.size();i++){
                if(mapHoldingSelectedRecords.size()>10 && mapHoldingSelectedRecords.size()<= 3000 ){
                    //Execute the batch directly
                    apiCall(orgtName,cont);
                    Database.executeBatch(objtouchcontactbatch); 
                    system.debug('execute batch');
                }
                
            }
        }
        
        
        system.debug('paginationmapsize :' + paginationmap.size());
        system.debug('selectedrecords size :' + selectedIds.size());
        pageReference pr = new pageReference('/apex/paginationtest');
        pr.setRedirect(true);
        return pr;
        
    }
    
    public void touchtbatch(){
        
        conlist = [SELECT id, LastName, AssistantName, AssistantPhone, Birthdate, Department, Description, Email, Fax, HomePhone, MailingAddress,
                   MailingCity, MailingCountry, MailingPostalCode, MailingState, MailingStreet, MobilePhone, Name, OtherAddress, OtherCity,
                   OtherCountry, OtherPhone, OtherPostalCode, OtherState, OtherStreet, Phone, Title,
                   (SELECT id, email__c, Assistant_Name__c, Assistant_Phone__c, Birthdate__c, Contact__c,
                    Department__c, Description__c, Fax__c, First_Name__c, Home_Phone__c, Mailing_City__c, Mailing_Country__c,
                    Mailing_State_Province__c, Mailing_Street__c, Mailing_Zip_Postal_Code__c, Mobile_Phone__c,
                    Other_City__c, Other_Country__c, Other_Phone__c, Other_State_Province__c, Other_Street__c,
                    Other_Zip_Postal_Code__c, Phone__c, Title__c from Cons__r)
                   From Contact where id in :selectedIds limit 9999  
                  ];
        system.debug(conlist);    
        list < Dummy_Contact__c > listDummyContactMain = new list < Dummy_Contact__c > ();
        list < Dummy_Contact__c > listDummyContactNew = new list < Dummy_Contact__c > ();
        
        for (Contact c: conlist) {
            if (c.Cons__r.size() == 0) {
                
                Dummy_Contact__c Dcobj = new Dummy_Contact__c();
                Dcobj.Name = c.LastName;
                Dcobj.Assistant_Name__c = c.AssistantName;
                Dcobj.Assistant_Phone__c = c.AssistantPhone;
                Dcobj.Birthdate__c = c.Birthdate;
                Dcobj.Description__c = c.Description;
                Dcobj.Department__c = c.Department;      
                Dcobj.Email__c = c.Email;
                Dcobj.Fax__c = c.Fax;
                Dcobj.Mailing_City__c = c.MailingCity;
                Dcobj.Mailing_Country__c = c.MailingCountry;
                Dcobj.Mailing_Zip_Postal_Code__c = c.MailingPostalCode;
                Dcobj.Mailing_State_Province__c = c.MailingState;
                Dcobj.Mailing_Street__c = c.MailingStreet;
                Dcobj.Other_City__c = c.OtherCity;
                Dcobj.Other_Country__c = c.OtherCountry;
                Dcobj.Other_Phone__c = c.OtherPhone;
                Dcobj.Other_Zip_Postal_Code__c = c.OtherPostalCode;
                Dcobj.Other_State_Province__c = c.OtherState;
                Dcobj.Other_Street__c = c.OtherStreet;
                Dcobj.Phone__c = c.Phone;
                Dcobj.Home_Phone__c = c.HomePhone;
                Dcobj.Mobile_Phone__c = c.MobilePhone;
                Dcobj.Title__c = c.Title;
                Dcobj.Contact__c = c.id;
                
                listDummyContactNew.add(Dcobj);
                
                //insert Dcobj;
                
            } else {
                listDummyContactMain.add(c.Cons__r[0]);
            }
        }
        if (!listDummyContactNew.isEmpty())
            try{
                insert listDummyContactNew;
            }
        catch(Exception e){
            system.debug(e.getMessage());
        }
        //SelectedId = new set<id> ();
        listDummyContactMain.addAll(listDummyContactNew);
        
        for (Dummy_Contact__c dummy: listDummyContactMain) {
            //  SelectedId.add(dummy.id);
        }
        system.debug('dummy record list :' + listDummyContactNew);   
        
    }
    
    public string urlcode;
    public void sendemail(){
        touchtbatch();
        List<Contact> conupdate =  new List<Contact>();  
        List<Contact> updatecon = new List<Contact>();    
        ContactUpdateURL__c mc = ContactUpdateURL__c.getall().values();
        urlcode = mc.URLforContactUpdate__c;   
        system.debug(ctlist );
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        for(Contact c :ctlist ){
            system.debug(c.id);
            conupdate.add(c);
            for(Dummy_Contact__c dc:c.cons__r){
                system.debug(dc.id);
                String body = '' ;
                //Creating tabular format for the case details
                body = '<html><body>Dear '+dc.name+',<br><br> '+  + 
                    
                    'I' + 'm currently updating my contact database and want to make sure I have your current data right.' + +
                    
                    'Could you have a quick look at below info? If you would like to change or update certain information, just click the ' + 'Update Now' + ' link on the bottom of the email and save your changes when done.<br> <br>' + +
                    
                    'Last Name:' +dc.name+  '<br><br>' + +
                    
                    'Email:' + dc.email__c+ '<br><br>' + +
                    
                    
                    'Title:' +dc.Title__c + '<br><br>'+ +
                    
                    'Phone:' +dc.phone__c+ '<br><br>' + +
                    
                    'Mobile:' +dc.Mobile_Phone__c+ '<br><br>' + +
                    
                    'Fax:' +dc.fax__c+ '<br>' + +
                    
                    'Street:' +dc.Mailing_Street__c+ '<br><br>' + +
                    
                    'Postalcode:' +dc.Mailing_Zip_Postal_Code__c+ '<br><br>'+ +
                    
                    'City:' +dc.Mailing_City__c+ '<br><br>' + +
                    
                    'State/Province:' +dc.Mailing_State_Province__c+ '<br><br>' + +
                    
                    'Country:' +dc.Mailing_Country__c+ '<br><br>' + +
                    
                    
                    '<a href="'+urlcode+dc.id+'">Update Now</a>' + '<br><br><br>' + +
                    
                    'Many thanks in advance, ' +'<br>' + +
                    
                    
                    '' + UserInfo.getlastname() +' </html></body>';
                
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
                String[] toAddresses = new String[] {dc.Email__c} ;
                    mail.setToAddresses(toAddresses) ;
                mail.setSubject('Touch Contact');
                mail.setHtmlBody(body);
                mails.add(mail);          
            }
        }
        Messaging.SendEmailResult[] results = Messaging.sendEmail(mails);
        for(Contact cs : conupdate){
            if (results[0].success) {
                System.debug('The email was sent successfully.');
                cs.Mail_Sent_Date__c= system.today();
                cs.Direct_send__c = false;
                updatecon.add(cs);
            } else {
                System.debug('The email failed to send: '
                             + results[0].errors[0].message);
            }  
        }
        update updatecon;
        
    }
    //Webservice Callout
    public String apiCall(String orgName, String Count)
    {         
        try
        {
            String LOGIN_DOMAIN = Label.TouchContactDomain;
            String userName = Label.TouchContactUserName;
            String pwd = Label.TouchContactPassword;
            
            HttpRequest request = new HttpRequest();
            request.setEndpoint('https://' + LOGIN_DOMAIN + '.salesforce.com/services/Soap/u/22.0');
            request.setMethod('POST');
            request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
            request.setHeader('SOAPAction', '""');
            request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + userName+ '</username><password>' + pwd+ '</password></login></Body></Envelope>');
            Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement()
                .getChildElement('Body', 'http://schemas.xmlsoap.org/soap/envelope/')
                .getChildElement('loginResponse', 'urn:partner.soap.sforce.com')
                .getChildElement('result', 'urn:partner.soap.sforce.com');
            final String SERVER_URL = resultElmt.getChildElement('serverUrl', 'urn:partner.soap.sforce.com') .getText().split('/services')[0];
            final String SESSION_ID = resultElmt.getChildElement('sessionId', 'urn:partner.soap.sforce.com') .getText();
            String addr = SERVER_URL + '/services/apexrest/TouchContactCheckAccess';
            HttpRequest req = new HttpRequest();
            req.setEndpoint( addr );
            req.setMethod('POST');
            req.setHeader('Authorization', 'OAuth ' + SESSION_ID);
            req.setHeader('Content-Type','application/json');
            
            Map<String,String> postBody = new Map<String,String>();
            postBody.put('orgName',orgName);
            postBody.put('Count',Count);
            String reqBody = JSON.serialize(postBody);
            
            req.setBody(reqBody);
            Http http = new Http();
            HttpResponse response = http.send(req);
            String body = response.getBody();
            System.debug('body :'+body);
            return body;
        }catch(Exception ex){
            Return '';
        }       
    }
    
    public static String encryptPassword(String password,String encKey) 
    {
        Blob key = Blob.valueOf(encKey); 
        Blob data = Blob.valueOf(password); 
        Blob encryptedData = Crypto.encryptWithManagedIV('AES128', key, data); 
        String encData = EncodingUtil.base64Encode(encryptedData); 
        return encData; 
    } 
    
    public static String decryptPassword(String encData,String encKey) 
    {
        Blob key = Blob.valueOf(encKey); 
        Blob encDataBlob = EncodingUtil.base64Decode(encData); 
        Blob decryptedData = Crypto.decryptWithManagedIV('AES128', key, encDataBlob); 
        String rawUnEncData = decryptedData.toString(); 
        return rawUnEncData; 
    }
    
    //wrapper class being used for checkbox showing.
    public class WrapperClass {
        public Boolean isSelected {get;set;}
        public Contact contactRecord {get;set;}
        public WrapperClass(Contact contactRecord, Boolean isSelected) {
            this.contactRecord = contactRecord;
            this.isSelected = isSelected;
        }
    }
    
}