You need to sign in to do that
Don't have an account?
Sales 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);
}
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);
}
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:
- Go to Setup
- In the Quick Find box, enter Opportunities
- Click on the Triggers
- Then Click on the New button and paste your code
- Now save the trigger code.
Please let me know if you need any other information on this.Thanks,
Abhishek Bansal
All Answers
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:
- Go to Setup
- In the Quick Find box, enter Opportunities
- Click on the Triggers
- Then Click on the New button and paste your code
- Now save the trigger code.
Please let me know if you need any other information on this.Thanks,
Abhishek Bansal
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