You need to sign in to do that
Don't have an account?
sonam guptha
trigger on contact
hi
I have 2 fields on contact which is inc__c and dec__c
so when i set the value on inc__c = 20, Dec__c = 0 should set to null
if i change the value on Dec__c = 0 to Dec__c = 1
the inc__c should decrement to inc__c = 19.
if add one more Dec__c =2
i.e. inc__c = 18
how can i acheive this,if its trigger please give me the sample code,i really appreciate your responses
Thanks
I have 2 fields on contact which is inc__c and dec__c
so when i set the value on inc__c = 20, Dec__c = 0 should set to null
if i change the value on Dec__c = 0 to Dec__c = 1
the inc__c should decrement to inc__c = 19.
if add one more Dec__c =2
i.e. inc__c = 18
how can i acheive this,if its trigger please give me the sample code,i really appreciate your responses
Thanks
trigger incAndDec on Contact (before insert, before update) {
for(Contact con : trigger.new) {
Decimal dec = con.dec__c;
Decimal inc = con.inc__c;
if(trigger.isInsert) {
if(dec != Null)
con.inc__c = 20-dec ;
if(inc!= Null)
con.dec__c = 20-inc ;
}
if(trigger.isUpdate) {
if(inc != trigger.oldMap.get(con.Id).inc__c && inc != null)
con.dec__c = 20-inc;
if(dec != trigger.oldMap.get(con.Id).dec__c && dec != null)
con.inc__c = 20-dec;
}
}
}
trigger IncAndDec on Contact (before insert, before update) {
for(Contact con : trigger.new) {
Integer dec = con.dec__c;
Integer inc = con.inc__c;
if(trigger.isBefore && trigger.isInsert) {
if(dec__c != Null)
con.inc__c = 20-dec__c ;
if(inc__c!= Null)
con.dec__c = 20-inc__c ;
}
if(trigger.isBefore && trigger.isUpdate) {
if(inc__c != trigger.oldMap.get(con.Id).inc__c && inc__c != null)
con.dec__c = 20-inc__c;
if(dec__c != trigger.oldMap.get(con.Id).dec__c && dec__c != null)
con.inc__c = 20-dec__c;
}
}
}