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
Shubham SengarShubham Sengar 

trigger problem 7

before we insert a new record in the customer object calculate the tax field value based on salary field value and then insert??

How i reach the right code ..??
Best Answer chosen by Shubham Sengar
rushirushi
Hello Shubham,

 Try this code
You can modify your calculations based on requirement

trigger calculateTax on customObj__c (before insert) {
    for(customObj__c  v:Trigger.new){
   if(v.salary__c <= 0)
     v.payTax__c = 0;
   if(v.salary__c > 0 && v.salary__c <= 100000)
     v.payTax__c = v.salary__c/10;
   if( v.salary__c > 100000)
     v.payTax__c = v.salary__c/20;
  }
}

All Answers

Nagesh ENagesh E
You can do before insert trigger and use values coming from save page. 
rushirushi
Hello Shubham,

 Try this code
You can modify your calculations based on requirement

trigger calculateTax on customObj__c (before insert) {
    for(customObj__c  v:Trigger.new){
   if(v.salary__c <= 0)
     v.payTax__c = 0;
   if(v.salary__c > 0 && v.salary__c <= 100000)
     v.payTax__c = v.salary__c/10;
   if( v.salary__c > 100000)
     v.payTax__c = v.salary__c/20;
  }
}
This was selected as the best answer
Shubham SengarShubham Sengar
Thanks Rushi