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 

Having trouble with trigger that after insert and after update..

Hi i facing problem with trigger that on opportunity i.e in opportunity there are fields like fs_include__c , target_ship_date,amount,stage etc..
if any one inserts a new opportunity record then if the field record _type_name== 'nc power' ,super_region == 'asia' and fs_include__c is "false" then automatically some fields have to be filled like 'amount' should be '1' and target_ship_date__c should be existing target_ship_date plus 3 months etc. and shuold be followed for the update also means when the record is updated then the same process should be followed(not every time updated only once it is updated that means when the record is updated every time it should not be updated every time only once it should be updated)...
RamuRamu (Salesforce Developers) 
Create a checkbox field and use the if else statements in the trigger to see if this is true or false. Let the flag be set to true from the after insert/update trigger and later on the trigger will not enter into the code as it is set to true in the first run.

Hope this helps !!
rajesh kumar 50rajesh kumar 50
hi ramu thanks for ur reply but my question is i want to create a trigger based on the condition given above..
RamuRamu (Salesforce Developers) 
The trigger goes something like this

trigger OpptyTrigger on Opportunity (before insert) {
    for(Opportunity Op:trigger.new){
        if(op.RecordTypeId=='01290000000emz1' && op.Check__c=='true'){
            op.Amount=1;
            op.Expiration_Month__c=op.CloseDate.addmonths(3);         
        }
    }
}

Please mark this as the best answer if it solved your issue.