+ Start a Discussion
HNT_NeoHNT_Neo 

Help with a fail safe statement in Apex Trigger

Hello everyone, need some help with a trigger I created. 

As you can see, my code doesn't have an alternative to a bank selection. 

For example, if a user leaves the picklist value blank and saves the record, an Apex error code will fire off, and post the error code at the top of the page. 

Is thseir a way to have this trigger skip this record if a blank value exists? That way a user can still save a record. if a blank value is needed. 

thanks!
 
trigger CAPdataTiers on CAPdata__c (before insert, before update) {
    for (CAPdata__c CAP : Trigger.new) {s
        if(CAP.Volume_Market__c.equalsIgnoreCase('As') && 
           CAP.Region_Program_Requirements__c != null && 
           CAP.Region_Program_Requirements__c.equalsIgnoreCase('Midwest'))
        {    
            CAP.TierElitePreferredJobs__c = 36; 
            CAP.TierElitePreferredRV__c = 90000;
            CAP.TierElitePreferredL6MosTA__c = 90;
            CAP.TierElitePreferredL6MosDA__c = 90;
            CAP.TierPreferredJobs__c = 24; 
            CAP.TierPreferredRV__c = 60000;
            CAP.TierPreferredL6MosTA__c = 75;
            CAP.TierRewardsAdvantageJobs__c = 12;
            CAP.TierRewardsAdvantageRV__c = 30000;
            CAP.TierRewardsAdvantageL6MosTA__c = 75;
        }
        else if(CAP.Volume_Market__c.equalsIgnoreCase('B') &&
           CAP.Region_Program_Requirements__c != null && 
           CAP.Region_Program_Res/Midwest Market B
            CA sP.TierElitePreferredJobs__c = 18; 
            CAP.TierElitePreferredRV__c = 45000;
            CAP.TierElitePreferredL6MosTA__c = 90;
            CAP.TierElitePreferredL6MosDA__c = 90;
            CAP.TierPreferredJobs__c = 12; 
            CAP.TierPreferredRV__c = 30000;
            CAP.TierPreferredL6MosTA__c = 50;
            CAP.TierRewardsAdvantageJobs__c = 6;
            CAP.TierRewardsAdvantageRV__c = 15000;
            CAP.TierRewardsAdvantageL6MosTA__c = 25;
        }
}

 
Best Answer chosen by HNT_Neo
Raj VakatiRaj Vakati
try this
 
trigger CAPdataTiers on CAPdata__c (before insert, before update) {
    for (CAPdata__c CAP : Trigger.new) {
	
	if(CAP.Volume_Market__c ==null ){
// dnt do any think .. 
	}else{
        if(CAP.Volume_Market__c.equalsIgnoreCase('As') && 
           CAP.Region_Program_Requirements__c != null && 
           CAP.Region_Program_Requirements__c.equalsIgnoreCase('Midwest'))
        {    
            CAP.TierElitePreferredJobs__c = 36; 
            CAP.TierElitePreferredRV__c = 90000;
            CAP.TierElitePreferredL6MosTA__c = 90;
            CAP.TierElitePreferredL6MosDA__c = 90;
            CAP.TierPreferredJobs__c = 24; 
            CAP.TierPreferredRV__c = 60000;
            CAP.TierPreferredL6MosTA__c = 75;
            CAP.TierRewardsAdvantageJobs__c = 12;
            CAP.TierRewardsAdvantageRV__c = 30000;
            CAP.TierRewardsAdvantageL6MosTA__c = 75;
        }
        else if(CAP.Volume_Market__c.equalsIgnoreCase('B') &&
           CAP.Region_Program_Requirements__c != null && 
           CAP.Region_Program_Res/Midwest Market B
            CA sP.TierElitePreferredJobs__c = 18; 
            CAP.TierElitePreferredRV__c = 45000;
            CAP.TierElitePreferredL6MosTA__c = 90;
            CAP.TierElitePreferredL6MosDA__c = 90;
            CAP.TierPreferredJobs__c = 12; 
            CAP.TierPreferredRV__c = 30000;
            CAP.TierPreferredL6MosTA__c = 50;
            CAP.TierRewardsAdvantageJobs__c = 6;
            CAP.TierRewardsAdvantageRV__c = 15000;
            CAP.TierRewardsAdvantageL6MosTA__c = 25;
        }
		}
}