I want to update master detail lookup field value through trigger but i guess due to order of execution system is performing validation rule first and because of this trigger is not firing.

trigger mapCCNumber on Transaction__c (before insert) {
  if(Trigger.isBefore && Trigger.isInsert) {

    List<CC_Master__c> cm = [SELECT id from CC_Master__c WHERE Name = 'To be aligned' LIMIT 1];
    List<CC_Reconciliation__c> ccRec = [SELECT id from CC_Reconciliation__c WHERE Name = 'To be Reconciled' LIMIT 1];

    for(Transaction__c  tc : Trigger.new) {
     system.debug('CC Master' + cm[0].id);
     system.debug('Reconcilation' + ccRec[0].id);
     //CC_Number__c is master detail lookup
     //CC_Reconciliation_ID__c is master detail lookup
     tc.CC_Number__c = cm[0].id;
     tc.CC_Reconciliation_ID__c = ccRec[0].id;

Is there any work around for this Thanks in advance !!

1 Answer 1


Well, what kind of validation rules do you have? The order of execution https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm states that user-defined validation rules are run after before-triggers. But certain system-defined validation rules, such as required fields, are indeed run before before-triggers. Is your trigger trying to fill some required fields? Because that is not going to work.

  • i assumed that order of execution could be reason for not firing the trigger. But i was wrong thanks for letting me know about this. My trigger is trying to fill master detail lookup field which is a required field. Is there any way to fill the required fill through before insert event trigger ?
    – MIX DML
    Commented Apr 2, 2015 at 14:44
  • You could use the so-called URL hack for that. Here's an explanation on how to do that raydehler.com/cloud/clod/… Commented Apr 2, 2015 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .