You need to sign in to do that
Don't have an account?

How to Stop a trigger from running for certain record type
On my quote object I have a visualforce page and a trigger creates new records in several different record types, but I want to use the standard new quote record functionality for one record type. When I try to save a record wit the the standard fuctionality, I recieve the following error message:
Error: Invalid Data. Review all error messages below to correct your data. Apex trigger QuoteNumberUpdate caused an unexpected exception, contact your administrator: QuoteNumberUpdate: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.QuoteNumberUpdate: line 22, column 14
Below is my code:
trigger QuoteNumberUpdate on Quote (after Insert) { Set<Id> qid = new Set<Id>(); decimal bqn=0,fqn =0; for(Quote q : trigger.new){ System.debug('**** 0 q id : '+q.id); qId.add(q.opportunityid); } List<Opportunity> o = [select id, Next_Budget_Quote_Number__c, Next_Firm_Quote_Number__c from Opportunity where id =:qid]; List<Quote> qu = [select id, recordtypeid from quote where id =: qid]; id brecordtypeid = [select id,name from RecordType where sobjecttype='Quote' and name='Budget Quote'].id; id frecordtypeid = [select id,name from RecordType where sobjecttype='Quote' and name='Firm Quote'].id; id oid = System.currentpageReference().getParameters().get('oppid'); String Typ = System.currentpageReference().getParameters().get('Type'); String Rec = System.currentpageReference().getParameters().get('Rec'); System.debug('o[0].Next_Budget_Quote_Number__c'+o[0].Next_Budget_Quote_Number__c); try { bqn = o[0].Next_Budget_Quote_Number__c + 1; } catch(NullPointerException ex) { bqn = 1; } try { fqn = o[0].Next_Firm_Quote_Number__c + 1; } catch(NullPointerException ex) { fqn = 1; } List<recordtype> brec = [select id from recordtype where name = 'Budget Quote']; List<recordtype> frec = [select id from recordtype where name = 'Firm Quote']; for(Opportunity op : o){ If(Rec == 'Budget Quote' ){ o[0].Next_Budget_Quote_Number__c = bqn ; } else If(Rec == 'Firm Quote' ){ o[0].Next_Budget_Quote_Number__c = fqn ; } } update o; }
For the visualforce page, I am passign values through the url, but don't need the values for the standard Opportunity object. How do I solve this problem?
Thank you
Hello,
Well i think you want trigger to be fired on a perticular record type only. You can achieve this by putting your intire trigger code inside if condition.For example suppose u have field name xyz__c which store the value of record type. So you have to make the condition like this if(Trigger.new[0].xyz__c !='Value of your record type') and after this put your intirecode inside this. Below is the Code :
trigger QuoteNumberUpdate on Quote (after insert)
{
if(Trigger.new[0].xyz__c !='Value of your record type')
{
put your intire code inside this.
}
}
Note: You can checek the same with before insert also.
All Answers
Hello,
Well i think you want trigger to be fired on a perticular record type only. You can achieve this by putting your intire trigger code inside if condition.For example suppose u have field name xyz__c which store the value of record type. So you have to make the condition like this if(Trigger.new[0].xyz__c !='Value of your record type') and after this put your intirecode inside this. Below is the Code :
trigger QuoteNumberUpdate on Quote (after insert)
{
if(Trigger.new[0].xyz__c !='Value of your record type')
{
put your intire code inside this.
}
}
Note: You can checek the same with before insert also.
Exactly what I needed.
Thank you