
1 resposta
Hi,Error is due to this line" for(Company__c object : myObjects) //assume more than 1 record in trigger.new"keyword OBJECT is reserved as it is generic datatype.For your case you want to have aggregate results like ROLLUP summary which SHOULD be implemented using AGGREGATERESULTS in Salesforce. The for loops may hit the governor limit if you have large amount of records.========================================// Below Query will give you aggreagted resultsMap<ID,String> mapIdAggresults = new map<Id,String>();AggregateResult[] groupedResults = [SELECT Sum(Amount__c),Client__c total FROM Company__c where ID in:Tigger.new GROUP BY Client__c];//Loop on list and do desired manipulationsfor (AggregateResult ar : groupedResults) { mapIdAggresults .put(ar.get('Cleint__c'),ar.get('Total'));}/*Query Parent records and use aboce map to update SUM__c fieldreplace the above logic in your trigger code and you should be able to get desired results.Suggestion : The logic that is written in you trigger should be moved to an APex class, This is best practise and recommended approach. in triggers just route logic to appropriate classes on the basis of trigger events/context