You need to sign in to do that
Don't have an account?
Akash Deokar
before update trigger on opportunity is not working
I have written before update trigger on opportunity but it is not working for below code, not providing error when changing stage to verbal agreement.
Note: I have created one opportunity stage as verbal agreement(80%).
for(Opportunity opp:[Select id,name, Legal_Entity_Name__r.SAP_CODE__c,StageName from opportunity where (StageName='Verbal Agreement' and id in:trigger.new)]){
if(opp.Legal_Entity_Name__r.SAP_CODE__c==null && opp.Legal_Entity_Name__r.Name==null){
opp.addError('Oppotunity cannot move to 80% as SAP CODE or LE is not present');
For below code there is error occured as mentioned in code but error is getting for all the stages instead of verbal agreement.
trigger SAP_CODE on Opportunity (before Update) {
Set<Opportunity> updatedoppty = new Set<Opportunity>();
for (Opportunity opp: trigger.new){
updatedoppty.add(opp);
}
Map<id,Opportunity> mapopty = new Map<id,Opportunity>();
mapopty.putAll([Select id, name, Legal_Entity_Name__r.SAP_CODE__c,StageName from opportunity where (StageName='Verbal Agreement' and id in:updatedoppty)]);
For (Opportunity opp: trigger.new){
if(null==mapopty.get(opp.Legal_Entity_Name__r.name)){
opp.addError('Oppotunity cannot move to 80% as LE is not present');
}
if(null==mapopty.get(opp.Legal_Entity_Name__r.SAP_CODE__c))
{
opp.addError('Oppotunity cannot move to 80% as SAP CODE is not present');
}
}
Note: I have created one opportunity stage as verbal agreement(80%).
for(Opportunity opp:[Select id,name, Legal_Entity_Name__r.SAP_CODE__c,StageName from opportunity where (StageName='Verbal Agreement' and id in:trigger.new)]){
if(opp.Legal_Entity_Name__r.SAP_CODE__c==null && opp.Legal_Entity_Name__r.Name==null){
opp.addError('Oppotunity cannot move to 80% as SAP CODE or LE is not present');
For below code there is error occured as mentioned in code but error is getting for all the stages instead of verbal agreement.
trigger SAP_CODE on Opportunity (before Update) {
Set<Opportunity> updatedoppty = new Set<Opportunity>();
for (Opportunity opp: trigger.new){
updatedoppty.add(opp);
}
Map<id,Opportunity> mapopty = new Map<id,Opportunity>();
mapopty.putAll([Select id, name, Legal_Entity_Name__r.SAP_CODE__c,StageName from opportunity where (StageName='Verbal Agreement' and id in:updatedoppty)]);
For (Opportunity opp: trigger.new){
if(null==mapopty.get(opp.Legal_Entity_Name__r.name)){
opp.addError('Oppotunity cannot move to 80% as LE is not present');
}
if(null==mapopty.get(opp.Legal_Entity_Name__r.SAP_CODE__c))
{
opp.addError('Oppotunity cannot move to 80% as SAP CODE is not present');
}
}
instead of your first code snippet because here you are iterating over SOQL query thats why it's not working
Above code is working for me,Its only giving error when i try changes Stage to Verbal Agreement
Trying to run trigger with below code:
Output:
Please suggest how to call.