function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sales DevelopmentSales Development 

Error: Compile Error: Incorrect SObject type: Opportunity should be Account at line -1 column -1

By writing an apex trigger on salesforce i get this error message and i don't understand what line -1 and column -1 mean. Can someone help me ? 

Here is my code : 

Trigger OpportunityTrigger on Opportunity (after insert, after update, after delete, after undelete) {
     List<Opportunity>  opportunities =  new  List<Opportunity>();
                   if(Trigger.isAfter){
                       if(Trigger.isInsert || Trigger.isUndelete){
                          opportunities = Trigger.new;
                       }else if(Trigger.isUpdate){                   
 for(Opportunity Opportunity : Trigger.new){
    if(Opportunity.Amount != Trigger.oldMap.get(Opportunity.id).Amount){
        opportunities.add(Opportunity);
    }
                              }
                       } else if(Trigger.isDelete){
                            opportunities  = trigger.old;
                       }
                   }
        list<RollUpSummaryUtility.fieldDefinition> fieldDefinitions1 = 

            new list<RollUpSummaryUtility.fieldDefinition> {

                new RollUpSummaryUtility.fieldDefinition('SUM', 'Amount', 

                'PreviousOpp_MRR__c')

            };

        RollUpSummaryUtility.ObjectDefination objDef = 
          new RollUpSummaryUtility.ObjectDefination('Opportunity','AccountId','Account','',null);

        new RollUpSummaryUtility().rollUp(fieldDefinitions1, objDef , opportunities); 
}
Best Answer chosen by Sales Development
Abhishek BansalAbhishek Bansal
Hi ,

The error suggests that you tried to create a new trigger on the Account object and then specify the object as Opportunity at line no 1. Please follow the correct steps to create a new trigger on the Opportunity object as mentioned below:
  1. Go to Setup
  2. In the Quick Find box, enter Opportunities
  3. Click on the Triggers
  4. Then Click on the New button and paste your code
  5. Now save the trigger code.
Please let me know if you need any other information on this.

Thanks,
Abhishek Bansal
 

All Answers

Abhishek BansalAbhishek Bansal
Hi ,

The error suggests that you tried to create a new trigger on the Account object and then specify the object as Opportunity at line no 1. Please follow the correct steps to create a new trigger on the Opportunity object as mentioned below:
  1. Go to Setup
  2. In the Quick Find box, enter Opportunities
  3. Click on the Triggers
  4. Then Click on the New button and paste your code
  5. Now save the trigger code.
Please let me know if you need any other information on this.

Thanks,
Abhishek Bansal
 
This was selected as the best answer
Sales DevelopmentSales Development
Thanks, that was the very problem ! Now, i would like to add some criteria to the rollup so that only some opportunities are summed up.
But i don't know how and where to write it in the above apex trigger.
Criteria would be : Stage = Closed Won and End of Contract Date = Max Date(which is another field already calculated by rollup summary)

Thanks