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
raj sfdc 8raj sfdc 8 

after updating the transaction key and password in provider detail page ,the updates are not reflecting to password object

trigger Raj_provider_detail_page on Provider_detail__c (Before Insert,Before Update) {

    //if (trigger.isBefore){
        //  Map to be checked against for the existence of a Custom Setting for a User

        map<string, Password__c> userToCustomSetting = new map<string, Password__c>();

        //  Lists for new, updated, and existing settings.

        list<Password__c >new set = new list<Password__c>();

        //list<Password__c> update2 = new list<Password__c>();

        list<Password__c> exsist3 = [SELECT  Id,Name,Password__c,ProviderID__c,MeterNumber__c,ProviderName__c,TransactionType__c
                                                       FROM   Password__c 
                                                       ORDER BY  CreatedDate
                                                       LIMIT   50];
        //  Notice the LIMIT above?  Without it, you'll probably receive a mark against you in your
        //  AppExchange Security Review findings report.  Queries need a WHERE or LIMIT

        //  Any triggered Provider_detail__c that meets the Password requirements will be added to this list
        list<Provider_detail__c> ApplicationSettings = new list<Provider_detail__c>();

        //  Populate the map based on the above query's results - keyed by the Username (name contains username)               
        if (!exsist3.isEmpty()){
            for (Password__c s : exsist3){
                userToCustomSetting.put(s.Name,s);
            }
        }

        for (Provider_detail__c to : trigger.new){
            if ((to.Password__c != null && to.Password__c  != '' )||(to.Transaction_Key != null && to.Transaction_Key != '')){
                //  Inserts are easier - as long as the Password was provided, we'll add it
                if (trigger.isInsert)
                    ApplicationSettings.add(to);
                //  We'll make sure the old and new Password values don't match and aren't udpated to the "masked" value
                else if (trigger.isUpdate)
                    if ((to.Password__c != '************' && to.Password__c != trigger.newMap.get(to.id).Password__c)||(to.Transaction_Key!='*************' && to.Transaction_Key != trigger.newMap.get(to.id).Transaction_Key))
                    ApplicationSettings.add(to);
            }
        }

        if (!ApplicationSettings.isEmpty()){
            for (Provider_detail__c to : ApplicationSettings){
                // if(to.Meter_Number__c != null){
                if( to.Meter_Number__c != null && to.Merchant_Id__c != null && to.Password__c != null ){
                    new set.add(new Password__c(Name = string.valueof(to.id), Password__c = to.Password__c,MeterNumber__c=to.Meter_Number__c,ProviderName__c = to.provider_Name__c,TransactionType__c = to.Transaction_Type__c,ProviderID__c = to.id));
                    //  Replace the Password
                    system.debug('id======>>>>>>>>>>>>>>>========='+to.id);
                    to.Password__c = '************';
                }
            }
            system.debug('ApplicationSettings===='+ApplicationSettings);
            //  Do inserts
            if (!new set.isEmpty() && ApplicationSettings[0].id != null){
                // if (!new set.isEmpty()){    
                system.debug('new set====='+new set);
                insert new set;
            }
        }

        if (!ApplicationSettings.isEmpty())
        { if(ApplicationSettings[0].get('Transaction_Key')!=null && ApplicationSettings[0].get('SysConct_Merchant_Id__c')!=null) /////
        {
            for (Provider_detail__c to : ApplicationSettings){
                //if(to.Transaction_Key != null){
                if(to.Transaction_Key != null && to.Merchant_Id__c != null){
                    string str1 = to.Transaction_Key;
                    if(str1.length()<256){
                        new set.add(new Password__c(Name = string.valueof(to.id),ProviderName__c = to.SysConct_Provider_Name__c,TransactionType__c = to.SysConct_Transaction_Type__c,ProviderID__c = to.id,AuthKey1__c = str1,MeterNumber__c = to.SysConct_Merchant_Id__c));
                        //  Replace the Password
                        to.Transaction_Key = '**************';
                    }
                    else{
                        string str2 = str1.substring(0,244);
                        string str3 = str1.remove(str2);

                        new set.add(new Password__c(Name = string.valueof(to.id),ProviderName__c = to.SysConct_Provider_Name__c,TransactionType__c = to.SysConct_Transaction_Type__c,ProviderID__c = to.id,AuthKey1__c = str2,AuthKey2__c = str3,MeterNumber__c = to.SysConct_Merchant_Id__c));
                        //  Replace the Password
                        to.Transaction_Key = '*************';

                    }
                }

            }
            system.debug('ApplicationSettings===='+ApplicationSettings);
            //  Do inserts 
            if (!new set.isEmpty() && ApplicationSettings[0].id != null){
                // if (!new set.isEmpty()){    
                system.debug('new set====='+new set);
                insert new set;
            }
        }
        } //////
   // }
}