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

field updation is not working properly in triggers



In my appliction two objects are there.

SeafootNote:Any Refund(checkbox),SFN Number(text)

Refund:Refund Amount(Input Field(Number)),

           SFN Number(lookup filed)which is looking over to SFN Number in SeafootNote


If i enter the  value in SFN Number and Refund amount in Refund object i want to make true in the Any refund field of correspondingSFN Number record in SeaFootNote object.But my trigger is not working properly.If i enter the new record in SeaFootNote ,though i didnt select the checkbox in Any Refund input field after saving the record Any Refund field is checked.


Plz tell me where i am going wrong in my code.


My code is as follows:

trigger refund on chiranjeevi__Sea_Foot_Note__c (before insert,before update) {

 List<chiranjeevi__Refund__c> refundlist=new List<chiranjeevi__Refund__c>();
 for (chiranjeevi__Sea_Foot_Note__c a :
 refundlist=[SELECT  chiranjeevi__Refund_Amount__c from chiranjeevi__Refund__c where chiranjeevi__SFN_Number__c=:a.chiranjeevi__SFN_number__c];
  for (chiranjeevi__Sea_Foot_Note__c a :
 Thanks in advance,


Anand SinghAnand Singh

The problem with the code is as follows:

Although you tried to find related chiranjeevi__Refund__c for each new record in chiranjeevi__Sea_Foot_Note__c, however you are updating all chiranjeevi__Sea_Foot_Note__c if related record exists in chiranjeevi__Refund__c for last inserted record (in batch) in chiranjeevi__Sea_Foot_Note__c


I have modified the code as follows:

trigger refund on chiranjeevi__Sea_Foot_Note__c (before insert,before update) { for (chiranjeevi__Sea_Foot_Note__c a : { for(chiranjeevi__Refund__c refundlist :[SELECT chiranjeevi__Refund_Amount__c from chiranjeevi__Refund__c where chiranjeevi__SFN_Number__c=:a.chiranjeevi__SFN_number__c limit 1]) { a.chiranjeevi__Any_refund__c=true; } } }


Hope this works!!


Thanks for ur reply,


Now  filed is not at all updated in any mode like new,save,edit.Any Isuues field is always unchecked.


will u plz tell me the solution.


Thanks in advance,