0

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Raj_provider_detail_page: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id a5fM00000000aMYIAY; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Raj_provider_detail_page: maximum trigger depth exceeded SysConct_Provider_detail trigger event AfterInsert SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate SysConct_Provider_detail trigger event AfterUpdate: [] Trigger.Raj_provider_detail_page: line 85, column 1: []

trigger Raj_provider_detail_page on SysConct_Provider_detail__c (after insert,after Update) { 

map<string, SysConct_Password__c> userToCustomSetting = new map<string, SysConct_Password__c>();
    list<SysConct_Password__c> newSettings = new list<SysConct_Password__c>();
    Set<String> providerIds=new Set<String>();
    for (SysConct_Provider_detail__c stg : trigger.new){
        providerIds.add(stg.Id);
    }
    list<SysConct_Password__c> existingSettings = [SELECT  Id,Name,Password__c,AuthKey1__c,AuthKey2__c,ProviderID__c,MeterNumber__c,ProviderName__c,TransactionType__c  
                                                   FROM   SysConct_Password__c 
                                                   where Name In : providerIds];
    //  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


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

    for (SysConct_Provider_detail__c stg : trigger.new){
        if ((stg.SysConct_Password__c != null && stg.SysConct_Password__c  != '' )||(stg.SysConct_Transaction_Key__c != null && stg.SysConct_Transaction_Key__c != '')){

            SysConct_Password__c newPassword;
            if(!userToCustomSetting.containsKey(stg.Id)){
                newPassword=new SysConct_Password__c();
                newPassword.Name = string.valueof(stg.id);                  
                newPassword.MeterNumber__c = stg.SysConct_Meter_Number__c;
                newPassword.ProviderName__c = stg.SysConct_Provider_Name__c;
                newPassword.TransactionType__c = stg.SysConct_Transaction_Type__c;
                newPassword.ProviderID__c = stg.id;
                newPassword.Password__c = stg.SysConct_Password__c;

                if(stg.SysConct_Transaction_Key__c != null && stg.SysConct_Transaction_Key__c != ''){
                    string str1 = stg.SysConct_Transaction_Key__c;
                    if(str1.length()<256){
                        newPassword.AuthKey1__c = str1 ;
                    }else{
                        string str2 = str1.substring(0,244);
                        string str3 = str1.remove(str2);
                        newPassword.AuthKey1__c = str2;
                        newPassword.AuthKey2__c = str3;
                    }                        
                }
                newSettings.add(newPassword);                   
            }else{                    
                newPassword = userToCustomSetting.get(stg.Id);
            boolean ischangeKey=false;
                if (stg.SysConct_Password__c != newPassword.Password__c){
                    newPassword.Password__c = stg.SysConct_Password__c;
                    ischangeKey=true;
                }if(stg.SysConct_Transaction_Key__c != newPassword.AuthKey1__c+newPassword.AuthKey2__c){
                    string str1 = stg.SysConct_Transaction_Key__c;
                    if(str1.length()<256){
                        newPassword.AuthKey1__c = str1 ;
                    }else{
                        string str2 = str1.substring(0,244);
                        string str3 = str1.remove(str2);
                        newPassword.AuthKey1__c = str2;
                        newPassword.AuthKey2__c = str3;
                    } 
                    ischangeKey=true;                   
                }
                if(ischangeKey)
                    newSettings.add(newPassword);

            }
        }
    }
    if (!newSettings.isEmpty()){
        system.debug('newSettings====='+newSettings);
        upsert newSettings;
        list<SysConct_Provider_detail__c> validApplicationSettings = new list<SysConct_Provider_detail__c>();
        for(SysConct_Password__c password : newSettings){
            SysConct_Provider_detail__c stg=new SysConct_Provider_detail__c(Id=password.Name);
            if(password.Password__c != null && password.Password__c !=  '')
                stg.SysConct_Password__c = '************';
            if(password.AuthKey1__c != null && password.AuthKey1__c  != '')
                stg.SysConct_Transaction_Key__c = '**************';
            validApplicationSettings.add(stg);
        }
        if(!validApplicationSettings.isEmpty())
            update validApplicationSettings;
    }     
}
0

Add AuthKey1__c to the query

Use this

list<SysConct_Password__c> existingSettings =

 [SELECT 

id,Name,Password__c,ProviderID__c,AuthKey1__c,MeterNumber__c,ProviderName__c,TransactionType__c  


FROM   SysConct_Password__c

 where Name In : providerIds];

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.