• rams123
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 0
    Replies
I have 2 account records lets take "acc1", "acc2" and here i want to delete "acc1" and  i need to transfer all the related data of "acc1" to "acc2". It means i need to update parent id of all the related records (from differenct child objects) with "acc2".

If any one knows please suggest me on the same. 
How to satisfy these below lines in test class in salesforce?


Profile userProfile = [SELECT Id FROM Profile WHERE Name='System Administrator'];
            user userRole = [SELECT id, name, UserRole.name FROM User WHERE UserRole.name like '% FAWS Technical Onboarding Manager%'];
       if((userProfile.Id != UserInfo.getProfileId())||(userRole.Id != userInfo.getUserRoleId())){  
           

can any one suggest please?
Profile userProfile = [SELECT Id FROM Profile WHERE Name='System Administrator'];
            user userRole = [SELECT id, name, UserRole.name FROM User WHERE UserRole.name like '% FAWS Technical Onboarding Manager%'];
       if((userProfile.Id != UserInfo.getProfileId())||(userRole.Id != userInfo.getUserRoleId())){  
           
           if((Trigger.isBefore)||(Trigger.isUndelete))
           { 
            List<Specialist_Lead__c > slist = new List<Specialist_Lead__c >();
            set<Id> leadId = new set<Id>();    
            List<string> adteamtype = new List<string>();    
            
            for(Specialist_Lead__c  s: trigger.new){
                leadId.add(s.Lead__c);
                adteamtype.add(s.Additional_Team_Type__c);
            }    
            slist = [select id, Lead__c, Additional_Team_Type__c 
                     from Specialist_Lead__c 
                     where Lead__c IN :leadId
                     and Additional_Team_Type__c IN :adteamtype];
            
            Map< String, Id > duplicateSpecialistMap = new Map< String, Id >();    
            
            for(Specialist_Lead__c s : slist){
                duplicateSpecialistMap.put(s.Additional_Team_Type__c, s.Id);        
            }
            
            for(Specialist_Lead__c s: trigger.new){
                Id duplicateSpecialistId = duplicateSpecialistMap.get(s.Additional_Team_Type__c);
                if(duplicateSpecialistId != null)
                {            
                   s.addError('This AdditionalTeamType is already existed with this Lead');            
                }
            }    
        }
    }

please suggest me if any one knows, find below my code.

i am facing error :"Error:Apex trigger cloudRevenueForcastTrigger caused an unexpected exception, contact your administrator: cloudRevenueForcastTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a1Q4B0000008PPGUA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cloudRevenueForcastTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a1Q4B0000008P7qUAE; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cloudRevenueForcastTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 1 with id a1Q4B0000008P5pUAE; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a1Q4B0000008P5p) is currently being saved. Saving object (id = a1Q4B0000008P5p) would cause it to be recursively saved, which is not allowed.: [] Class.cloudRevenueForcastTriggerHandler.updateSegmentValue: line 85, column 1 Trigger.cloudRevenueForcastTrigger: line 14, column 1: [] Class.cloudRevenueForcastTriggerHandler.updateSegmentValue: line 85, column 1 Trigger.cloudRevenueForcastTrigger: line 14, column 1: []: Class.cloudRevenueForcastTriggerHandler.segmentValueUpdate: line 62, column 1"

Public void updateSegmentValue(List<Cloud_Revenue_Forecast__c> newList){
        
        set<string> crfIds = new set<string>();
        set<string> segmenttype = new set<string>();
        List<Cloud_Revenue_Forecast__c> updateRecords = new List<Cloud_Revenue_Forecast__c>();
        
        for(Cloud_Revenue_Forecast__c c : newList){            
            if(c.Segment_Value__c != null){
                crfIds.add(c.Id);
                segmenttype.add(c.Segment_Type__c);
            }            
        }
        Map<Id, Cloud_Revenue_Forecast__c> arSegmentValueMap = new Map<Id, Cloud_Revenue_Forecast__c>();        
        aggregateResult[] sumSegmentValue = [select sum(Segment_Value__c)cnt from Cloud_Revenue_Forecast__c where segment_type__c IN :segmenttype];        
        List<Cloud_Revenue_Forecast__c> uniquesegmentrecords = new List<Cloud_Revenue_Forecast__c>([select id, Segment_Value__c from Cloud_Revenue_Forecast__c where segment_type__c IN :segmenttype ]);
                
        for(Cloud_Revenue_Forecast__c c : uniquesegmentrecords){
            c.Segment_Value__c = (Decimal)sumSegmentValue[0].get('cnt');
            updateRecords.add(c);
        }
        update updateRecords;        
    }