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
rajesh kumar 50rajesh kumar 50 

I was having a problem with apex trigger!

Below is my trigger:
trigger opportunityinsertupdate on opportunity(before insert,before update) {
    if(trigger.isInsert) {     
        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.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);
            }
        }
    }
   
    if(trigger.isUpdate)  {
        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.Super_Region__c == 'Asia/India' && o.Check__c == false) {
                o.stagename = 'Sales Lead';
                o.amount = 1;
                o.CurrencyIsoCode = 'USD';
                o.Target_ShipDate__c = o.Target_ShipDate__c.addmonths(3);
                o.Check__c = true;
            }
       
        }
    }
}

But i was facing a problem that when i insert a record the shipdate date is adding 6 months
and check__c field is setting to true..
But my requirement is a record is inserted the shipdate should add 3 months only with exiting shopdate
and when any record is updated then shipdate should add 3 months and check box is set to true..
but with my trigger when i am inserting also the check box is seeting to true and shipdate is adding to 6 months..
can any suggest me to solve my trigger please
thanks in advance..

RamuRamu (Salesforce Developers) 
As per your description, seems like the trigger is running both insert and update logic or there is other trigger with the same logic which is also firing. Please setup debug logs and verify if there are any other triggers in place which are acting on this object.