• Sreelakshmi N 1
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I have 2 custom objects employee__c and company__c.In employee  Object I have a field called salry__c and in Company object Ihave a field max_salry__c .I want to populate max salary of the employees on Parent Object Field max_salry__c.Please help me on trigger for this scenario.

Here is the snippet I tried .

trigger calculateMaxSalary on Employee__c (after update, after insert) {

        /*Map<Id, Compny__c> parentcomp = new Map<Id, Compny__c>();
        List<Id> listIds = new List<Id>();

        for(Employee__c childObj : Trigger.new) {
            listIds.add(childObj.salaries__c);
        }

        parentcomp= new Map<Id, Compny__c> ([Select Id, Name,max_salary__c, (Select Id, salry__c from Emploies__r) from Compny__c where Id in :listIds]);

        for(Employee__c emp : Trigger.new) {    
            Compny__c comp = parentcomp.get(emp.salaries__c);
            system.debug('Max Salary#########'+comp.max_salary__c);
            system.debug('Salary**************'+emp.salry__c);
            //comp.max_salary__c= max(emp.salry__c);
        }

        update parentcomp.values();
        */
        
        
               
  // }