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
Pratik Desai 16Pratik Desai 16 

Incorrect SObject type: Opportunity should be OpportunityLineItem at line -1 column -1..I am getting this error while creating trigger for opportunity

Best Answer chosen by Pratik Desai 16
Pratik Desai 16Pratik Desai 16
Trigger Opp_trigger on Opportunity (Before Insert, Before Update) {
for(Opportunity a :Trigger.New )
{
if(a.Amount < 5000)
a.addError('amount can not be greater than 5000');
}

}

I have written like this..what is the error here
 

All Answers

Raj VakatiRaj Vakati
Looks like you are not creating opportunitylineiteam trigger on opportunity trigger or vise versa 

can you give me a code 
 
trigger updateAccountType on Opportunity(after insert, after update){
}


 
trigger updateAccountType on OpportunityLineItem (after insert, after update){
}

 
Pratik Desai 16Pratik Desai 16
Trigger Opp_trigger on Opportunity (Before Insert, Before Update) {
for(Opportunity a :Trigger.New )
{
if(a.Amount < 5000)
a.addError('amount can not be greater than 5000');
}

}

I have written like this..what is the error here
 
This was selected as the best answer
Raj VakatiRaj Vakati
Delete this trigger and recreate like below .. looks like if you created on the opportunity line item  and trying to change to opportunityy 

User-added image
Use this code
 
Trigger Opp_trigger on Opportunity (Before Insert, Before Update) {
    for(Opportunity a :Trigger.New )
    {
        if(a.Amount < 5000)
            a.addError('amount can not be greater than 5000');
    }
    
}