You need to sign in to do that
Don't have an account?

Trigger gives errors on old opportunities
I have written a Trigger that works on opportunity Object. Its working fine with all the new opportunities created after I deployed the trigger. But all the old opportunities were giving the following error. The client is getting this error when he first tries to login as Admin and then logins as another user. Here is the scenario in detail.
1. User logins as admin. Then he goes to Set up-> Users and logins as a particular user.
2. User opens an existing opportunity
3. Modifies the Opportunity and hits Save
4.He receives the following message and opportunity is not saved
“Your Changes Cannot Be Saved
The record you were editing was modified by Sfdc Admin during your edit session.
Please re-display the record before editing again.
5. If user then closes the opportunity and repeats step 2 to 3 – the opportunity is saved with no issue.
6. Or if the user clicks on the 'Please re-display the record before editing again.' link from the
error, the opportunity re-displays. When he repeats the steps, the opportunity gets saved again without any error
This is only happening with the old opportunites(opp created before the trigger was deployed) and when the user is logging in as another user
after loggin in as admin first. I am really confused. I looked into my code and the initial lines of my code look like this:
if (Trigger.isUpdate && Helper.getcallfromPV() == false) {
list<Opportunity> oppt = [select Id from Opportunity where Id IN :Trigger.newMap.keySet() limit 1];
I am wondering if since I am looking into Trigger.newMap, I am getting this error for old opportunities? Okay, but
why does the triggers work once you refresh the opportunity? If the trigger is only looking into new opportunities,
it should not work on old opportunities no matter what, right? But how come it works normally once your refresh the
opportunity. Any help please?
if you posted some more code, it will be easier to help.
What I think is wrong is that you query the opportunities that are in the trigger. Why? They are already in the trigger context. You can just loop through the Trigger.New (this has all the opportunities in it) and then execute code based on the condition Trigger.IsUpdate.
Somethinkg like this:
Because, I have SOQL queries. If I do it that way, wouldn't that be a problem when I write SOQL queries inside a FOR loop? Since this another way of accessing new Opp ID, I did it this way.
if it is an update trigger, you already have the opportunity ID in the trigger context. So why are you querying that opportunity (and only the ID) again?
If you post the entire trigger code, it will be easier to understand what you are trying to do.
I have sent you the code in a message. I am not sure what you are saying, even if it is in the context, I should be able to refer it, right?
May be looking at the code will give you a better idea of what I was trying to do.