You need to sign in to do that
Don't have an account?
rajesh kumar 50
Facing problem with trigger on opportunity
when i insert or update a record some fields have to be automatically updated and when we update only once it should be updated based on the condition.
we have to do it in trigger only because in the conditon one field in related to account object i.e Super_region__c field so no way to do from workflow
i have a written a trigger but it is not taking a relation field can any one suggest me to correct my issue
below is my trigger
trigger opportunityinsertupdate on opportunity(before insert,before update) {
boolean flag=True;
if(trigger.isInsert) {
//list<account> lacc = new list<account>();
//lacc = [select id,super_region__c,name from account ];
for(opportunity o : trigger.new) {
if(((o.Record_Type_Name__c == 'NC Power')||(o.Record_Type_Name__c == 'NC Oil & Gas')) && (o.FS_Included__c == false) && (o.account.Super_Region__c == 'Asia/India')) {
o.stagename = 'Sales Lead';
o.amount = 1;
o.CurrencyIsoCode = 'USD';
o.Target_ShipDate__c = o.Target_ShipDate__c.addmonths(3);
flag = false;
}
}
}
if(trigger.isUpdate && flag) {
for(opportunity o1:trigger.new){
if(((o1.Record_Type_Name__c == 'NC Power')||(o1.Record_Type_Name__c == 'NC Oil & Gas')) && (o1.FS_Included__c == false) && o1.account.Super_Region__c == 'Asia/India' && o1.Check__c == false) {
o1.stagename = 'Sales Lead';
o1.amount = 1;
o1.CurrencyIsoCode = 'USD';
o1.Target_ShipDate__c = o1.Target_ShipDate__c.addmonths(3);
o1.Check__c = true;
}
}
}
}
thanks in advance
we have to do it in trigger only because in the conditon one field in related to account object i.e Super_region__c field so no way to do from workflow
i have a written a trigger but it is not taking a relation field can any one suggest me to correct my issue
below is my trigger
trigger opportunityinsertupdate on opportunity(before insert,before update) {
boolean flag=True;
if(trigger.isInsert) {
//list<account> lacc = new list<account>();
//lacc = [select id,super_region__c,name from account ];
for(opportunity o : trigger.new) {
if(((o.Record_Type_Name__c == 'NC Power')||(o.Record_Type_Name__c == 'NC Oil & Gas')) && (o.FS_Included__c == false) && (o.account.Super_Region__c == 'Asia/India')) {
o.stagename = 'Sales Lead';
o.amount = 1;
o.CurrencyIsoCode = 'USD';
o.Target_ShipDate__c = o.Target_ShipDate__c.addmonths(3);
flag = false;
}
}
}
if(trigger.isUpdate && flag) {
for(opportunity o1:trigger.new){
if(((o1.Record_Type_Name__c == 'NC Power')||(o1.Record_Type_Name__c == 'NC Oil & Gas')) && (o1.FS_Included__c == false) && o1.account.Super_Region__c == 'Asia/India' && o1.Check__c == false) {
o1.stagename = 'Sales Lead';
o1.amount = 1;
o1.CurrencyIsoCode = 'USD';
o1.Target_ShipDate__c = o1.Target_ShipDate__c.addmonths(3);
o1.Check__c = true;
}
}
}
}
thanks in advance
Try the below code.