+ Start a Discussion
Gaurav AgnihotriGaurav Agnihotri 

Trigger doesn't fire when a field is removed from the page layout

Gurus, 
I encountered a very strange problem. Below is my simple trigger.  It looks for a lookup field custom field "Pelco_Account_Name__c " on quote object and if it null then populated the value of AccountId
trigger updateOpptyAccount on Quote (before insert) {
    for (Quote QuoteInLoop : Trigger.new){
       // if(QuoteInLoop.Opportunity.name != '.'){
        Boolean sMainAccount=QuoteInLoop.Main_Account__c;
        String sMainAccountId=QuoteInLoop.AccountId;
        String sQuoteAccountId=QuoteInLoop.Pelco_Account_Name__c;
        String sQuotePriceBook=QuoteInLoop.PriceBook2Id;
        String sQuoteId=QuoteInLoop.Id;
        String sOptyId=QuoteInLoop.OpportunityId;
        //checking if price book is attached to the quote
        //if no price book exist than defaulting the standard price book
        if(sQuotePriceBook == null)
        {
            QuoteInLoop.Pricebook2Id =[SELECT Id FROM Pricebook2 Limit 1].Id;
        }
       
        //if pelco quote account is null
        if (sQuoteAccountId == null)
        {
            QuoteInLoop.Pelco_Account_Name__c=QuoteInLoop.AccountId;
            sQuoteAccountId=QuoteInLoop.AccountId;
        }
        
     }//closing forLoop
 }//closing trigger updateOpptyAccount
This trigger does not work if I remove AccountName field from the quote page layout. As soon as I put the field back it works.  I disable all the workflow rules and approval, still the problem persist.

Any comments/suggestions?

Thanks, 
Gaurav
Best Answer chosen by Gaurav Agnihotri
3 Creeks3 Creeks
Is the field you are remove an Account lookup?   If so, when you remove it you are now longer associating the quote with an account so account id is null. 
 

All Answers

3 Creeks3 Creeks
Is the field you are remove an Account lookup?   If so, when you remove it you are now longer associating the quote with an account so account id is null. 
 
This was selected as the best answer
Gaurav AgnihotriGaurav Agnihotri
Yes, that field is indeed  an account lookup field. thank you for explaining.