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

How to fire trigger for particular record type only?
Hello,
I want to fire my trigger on particular reocrd type only. But i am getting error.
Apex trigger QuotelineItemApproval caused an unexpected exception, contact your administrator: QuotelineItemApproval: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0Q07E000000dz9aSAA; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3017E0000002lA7. Flow error messages: An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []: Trigger.QuotelineItemApproval: line 95, column 1
trigger QuotelineItemApproval on QuoteLineItem (after insert, after update) {
List<Quote> parentObjList = new List<Quote>();
List<ID> listIds = new List<ID>();
List<Quote> listIds1 = new List<Quote>();
Id devRecordTypeId = Schema.SObjectType.Quote.getRecordTypeInfosByName().get('BenderINC - Industrial Quotes').getRecordTypeId();
if(devRecordTypeId == '012b00000001AxG')
system.debug('***********+devRecordTypeId +*************'+devRecordTypeId );
{
Boolean inRange ;
String status ='Not Required';
String QuoteID ;
Boolean isAwaiting = false;
for (QuoteLineItem childObj : Trigger.new) {
if(QuoteID == null) {
QuoteID = childObj.QuoteID;
}
}
Boolean changed = false;
if(QuoteID != null) {
for(List<QuoteLineItem> items : [select ID, Discount_Flag1__c,Quantity ,Discount from QuotelineItem where QuoteId= : QuoteID ]) {
for(QuoteLineItem item : items ) {
inRange = false;
changed = true;
if(item.Quantity >= 0 && item.Quantity <= 9 && item.Discount <= 0) {
inRange = true;
} else {
if(item.Quantity >= 10 && item.Quantity <= 25 && item.Discount <= 5) {
inRange = true;
} else {
if(item.Quantity >= 26 && item.Quantity <= 49 && item.Discount <= 7) {
inRange = true;
} else {
if(item.Quantity >= 50 && item.Discount <= 10) {
inRange = true;
}
}
}
}
if(!inRange) {
isAwaiting = true;
}
system.debug('***********+Quantity +*************'+item.Quantity);
system.debug('***********+Discount +*************'+item.Discount);
system.debug('***********+inRange +*************'+inRange );
}
}
system.debug('***********+isAwaiting +*************'+isAwaiting );
if(changed ) {
Id retVal = null;
for(ProcessInstanceWorkitem workItem : [Select p.Id from ProcessInstanceWorkitem p where p.ProcessInstance.TargetObjectId =: QuoteID]) {
retVal = workItem.Id;
}
if(isAwaiting ) {
status = 'Awaiting Approval';
} else {
status = 'Not Required';
}
List<Quote> quotes = [select Id,Approval_Status__c from Quote where Id =:QuoteID ];
if(quotes.size() > 0) {
Quote QuoteDetails = quotes[0];
if(retVal != null && status == 'Not Required') {
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setComments('Automatically approved as Approval is no longer required.');
req.setAction('Approve');
req.setNextApproverIds(new Id[] {UserInfo.getUserId()});
req.setWorkitemId(retVal );
Approval.ProcessResult result = Approval.process(req);
}
//QuoteDetails.IsSynching = false;
QuoteDetails.Approval_Status__c = status;
update QuoteDetails;
}
}
}
}
}
Thanks & Regards,
Utkarsha
I want to fire my trigger on particular reocrd type only. But i am getting error.
Apex trigger QuotelineItemApproval caused an unexpected exception, contact your administrator: QuotelineItemApproval: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0Q07E000000dz9aSAA; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3017E0000002lA7. Flow error messages: An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []: Trigger.QuotelineItemApproval: line 95, column 1
trigger QuotelineItemApproval on QuoteLineItem (after insert, after update) {
List<Quote> parentObjList = new List<Quote>();
List<ID> listIds = new List<ID>();
List<Quote> listIds1 = new List<Quote>();
Id devRecordTypeId = Schema.SObjectType.Quote.getRecordTypeInfosByName().get('BenderINC - Industrial Quotes').getRecordTypeId();
if(devRecordTypeId == '012b00000001AxG')
system.debug('***********+devRecordTypeId +*************'+devRecordTypeId );
{
Boolean inRange ;
String status ='Not Required';
String QuoteID ;
Boolean isAwaiting = false;
for (QuoteLineItem childObj : Trigger.new) {
if(QuoteID == null) {
QuoteID = childObj.QuoteID;
}
}
Boolean changed = false;
if(QuoteID != null) {
for(List<QuoteLineItem> items : [select ID, Discount_Flag1__c,Quantity ,Discount from QuotelineItem where QuoteId= : QuoteID ]) {
for(QuoteLineItem item : items ) {
inRange = false;
changed = true;
if(item.Quantity >= 0 && item.Quantity <= 9 && item.Discount <= 0) {
inRange = true;
} else {
if(item.Quantity >= 10 && item.Quantity <= 25 && item.Discount <= 5) {
inRange = true;
} else {
if(item.Quantity >= 26 && item.Quantity <= 49 && item.Discount <= 7) {
inRange = true;
} else {
if(item.Quantity >= 50 && item.Discount <= 10) {
inRange = true;
}
}
}
}
if(!inRange) {
isAwaiting = true;
}
system.debug('***********+Quantity +*************'+item.Quantity);
system.debug('***********+Discount +*************'+item.Discount);
system.debug('***********+inRange +*************'+inRange );
}
}
system.debug('***********+isAwaiting +*************'+isAwaiting );
if(changed ) {
Id retVal = null;
for(ProcessInstanceWorkitem workItem : [Select p.Id from ProcessInstanceWorkitem p where p.ProcessInstance.TargetObjectId =: QuoteID]) {
retVal = workItem.Id;
}
if(isAwaiting ) {
status = 'Awaiting Approval';
} else {
status = 'Not Required';
}
List<Quote> quotes = [select Id,Approval_Status__c from Quote where Id =:QuoteID ];
if(quotes.size() > 0) {
Quote QuoteDetails = quotes[0];
if(retVal != null && status == 'Not Required') {
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setComments('Automatically approved as Approval is no longer required.');
req.setAction('Approve');
req.setNextApproverIds(new Id[] {UserInfo.getUserId()});
req.setWorkitemId(retVal );
Approval.ProcessResult result = Approval.process(req);
}
//QuoteDetails.IsSynching = false;
QuoteDetails.Approval_Status__c = status;
update QuoteDetails;
}
}
}
}
}
Thanks & Regards,
Utkarsha
I suggest please refer bellow links
https://success.salesforce.com/answers?id=90630000000hcDrAAI
https://developer.salesforce.com/forums/?id=906F0000000AprlIAC
Regards
Ramakrishna