• Flauradel Consumido
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
Hi All, I would like to ask for any help as I am really new to this and still learning. I am trying to create a trigger that will roll up the Opportunity Amount on a Custom Object field. Their relationship is lookup only. I keep receiving Error: Compile Error: Invalid field: 'Commission__c' at line 6 column 32

I have a Custom object and set up a lookup from Opportunity to the custom object. What I would like is to get the sum of the Amount of all the opportunities attached to the custom object. 

I need to roll up:
From Object: Opportunity
Field: Amount

Where to roll up: 
Object: Commission__c
Field: Total_Amount__c
 
trigger CommissionRollUp on Commission__c (After Insert){
    Set<Id> setOpportunityIds=new Set<Id>();
        for(Commission__c c:Trigger.new)
            setOpportunityIds.add(c.Amount);
        List<Opportunity> lstOpportunityToUpdate=new List<Opportunity>();
        for(AggregateResult result:[Select Commission__c,count(id) From Commission__c WHERE
Commission__c IN :setOpportunityIds GROUP BY Commission__c LIMIT 2000]){
            Opportunity__r parent=new Opportunity__r();
        Opportunity.Id=result.get('Commission__c');
        Opportunity.Total_Amount__c=(Integer)result.get('expr0');
        lstOpportunityToUpdate.add(Opportunity);
        }
    update lstOpportunityToUpdate;
}

 
I have a custom object "Commission", and Opportunity has a lookup to the custom object. Each "Commission" could have a handful of Opportunities related to it. Need a basic trigger that grabs the total of the Opportunity Amounts attached to the commission and updates a currency field on the Commission record record. 
Hi All, I would like to ask for any help as I am really new to this and still learning. I am trying to create a trigger that will roll up the Opportunity Amount on a Custom Object field. Their relationship is lookup only. I keep receiving Error: Compile Error: Invalid field: 'Commission__c' at line 6 column 32

I have a Custom object and set up a lookup from Opportunity to the custom object. What I would like is to get the sum of the Amount of all the opportunities attached to the custom object. 

I need to roll up:
From Object: Opportunity
Field: Amount

Where to roll up: 
Object: Commission__c
Field: Total_Amount__c
 
trigger CommissionRollUp on Commission__c (After Insert){
    Set<Id> setOpportunityIds=new Set<Id>();
        for(Commission__c c:Trigger.new)
            setOpportunityIds.add(c.Amount);
        List<Opportunity> lstOpportunityToUpdate=new List<Opportunity>();
        for(AggregateResult result:[Select Commission__c,count(id) From Commission__c WHERE
Commission__c IN :setOpportunityIds GROUP BY Commission__c LIMIT 2000]){
            Opportunity__r parent=new Opportunity__r();
        Opportunity.Id=result.get('Commission__c');
        Opportunity.Total_Amount__c=(Integer)result.get('expr0');
        lstOpportunityToUpdate.add(Opportunity);
        }
    update lstOpportunityToUpdate;
}

 
I have a custom object "Commission", and Opportunity has a lookup to the custom object. Each "Commission" could have a handful of Opportunities related to it. Need a basic trigger that grabs the total of the Opportunity Amounts attached to the commission and updates a currency field on the Commission record record. 
Hello,
My scenario is to have a Roll up summary field for Look up relationship object.
Please let me know the work around.

Thanks.