-
ChatterFeed
-
1Best Answers
-
0Likes Received
-
0Likes Given
-
2Questions
-
5Replies
Updating a checkbox field if a File is uploaded through ContentDocumentLink trigger
Hi everyone,
Here is my business requirement:
On the standard Quote object, I have a custom checkbox field called PO_Attached__c. If a File is uploaded to a Quote record, PO_Attached__c should be updated to true. I currently achieve this functionality using the Attachments functionality by use of an Apex trigger.
However, we are now migrating to Files. I have updated my code block as below. It saves fine, but the checkbox is never updated. Any ideas why? Thanks in advance.
Here is my business requirement:
On the standard Quote object, I have a custom checkbox field called PO_Attached__c. If a File is uploaded to a Quote record, PO_Attached__c should be updated to true. I currently achieve this functionality using the Attachments functionality by use of an Apex trigger.
However, we are now migrating to Files. I have updated my code block as below. It saves fine, but the checkbox is never updated. Any ideas why? Thanks in advance.
trigger quoteAttachment2 on ContentDocumentLink (after insert) { List<Quote> listOfQuote = [select id from Quote where id =: Trigger.New[0].LinkedEntityId]; if(listOfQuote.size()>0) { listOfQuote[0].PO_Attached__c = true; update listOfQuote; } }
- Tarek Zaheer 1
- December 04, 2017
- Like
- 0
Code Coverage - Test Class does not cover "After Update" with checkRecursive
Hi everyone, There have been some other posts on this exact same issue but none of those posted solutions have worked for me. I have a trigger that is firing twice when it should only be firing once. To solve this, I used checkRecursive (class pasted below). My trigger works fine now. However, my test class is not covering the section of my trigger which is isUpdate. This is due to the checkRecursive.
Trigger:
Test Class:
RecursiveCheck class:
If someone can point out how I need to change one of the three above blocks of code, that would be much appreciated. I'm getting good code coverage except under the IsUpdate clause due to the RecursiveCheck.
Thank you!
Trigger:
trigger bsWarranty on QuoteLineItem (after insert,after update, after delete) { if(trigger.isinsert){ for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0200, add 0003-0129 if ((QLI.PricebookEntryId == '01u61000003LhrX')) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqI'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0404, add 0003-0374 if ((QLI.PricebookEntryId == '01u61000003LhpS')) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003M03X'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0870, add 0003-1179 if ((QLI.PricebookEntryId == '01u61000003LhpQ')) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqA'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { if ((QLI.PricebookEntryId == '01u61000003LhpR')|| //0270-0912 (QLI.PricebookEntryId == '01u61000003LhpX') || //0270-0878 (QLI.PricebookEntryId == '01u61000003Lhpa') || //0270-0747 (QLI.PricebookEntryId == '01u61000003Lhpb')) { //0270-0749 //if above, add 0003-0878 QuoteLineItem newQLI = new QuoteLineItem(); system.debug(QLI.Quantity); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003Lhpn'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { if ((QLI.PricebookEntryId == '01u61000003LhpT')|| //0270-0860 (QLI.PricebookEntryId == '01u61000003LhpU') || //0270-0858 (QLI.PricebookEntryId == '01u61000003LhpV') || //0270-0821 (QLI.PricebookEntryId == '01u61000003LhpW') || //0270-0822 (QLI.PricebookEntryId == '01u61000003LhpY') || //0270-0817 (QLI.PricebookEntryId == '01u61000003LhpZ') || //0270-0818 (QLI.PricebookEntryId == '01u61000003Lhpc') || //0270-0604 (QLI.PricebookEntryId == '01u61000003Lhpe')) //0270-0415 //if above, add 0003-1085 { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003Lhpy'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0793 or 0270-0790 (not currently on contract), add 0003-0259 if ((QLI.PricebookEntryId == '01u61000003Lhpg')|| (QLI.PricebookEntryId == '01u61000003Lhpd')) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqU'; insert newQLI; }}}} if (trigger.isupdate) { if(RecursiveCheck.runOnce()){ for (QuoteLineItem QLInew : Trigger.new){ Decimal QuantityNew = QLInew.Quantity; QuoteLineItem QLIold = Trigger.oldMap.get(QLInew.id); Decimal QuantityOld = QLIold.Quantity; system.debug('@@@@@@@@@@'+QuantityOld); system.debug('@@@@@@@@@@'+QuantityNew); if (((QuantityNew != QuantityOld) && (QLInew.Quote.Pricebook2.id == '01s61000003U9Id') && ((QLInew.PricebookEntryId == '01u61000003LhrX') || // 0270-0200 (QLInew.PricebookEntryId == '01u61000003LhpS') || // 0270-0404 (QLInew.PricebookEntryId == '01u61000003LhpQ') || // 0270-0870 (QLInew.PricebookEntryId == '01u61000003LhpR') || // 0270-0912 (QLInew.PricebookEntryId == '01u61000003LhpX') || // 0270-0878 (QLInew.PricebookEntryId == '01u61000003Lhpa') || // 0270-0747 (QLInew.PricebookEntryId == '01u61000003Lhpb') || // 0270-0749 (QLInew.PricebookEntryId == '01u61000003LhpT') || // 0270-0860 (QLInew.PricebookEntryId == '01u61000003LhpU') || // 0270-0858 (QLInew.PricebookEntryId == '01u61000003LhpV') || // 0270-0821 (QLInew.PricebookEntryId == '01u61000003LhpW') || // 0270-0822 (QLInew.PricebookEntryId == '01u61000003LhpY') || // 0270-0817 (QLInew.PricebookEntryId == '01u61000003LhpZ') || // 0270-0818 (QLInew.PricebookEntryId == '01u61000003Lhpc') || // 0270-0604 (QLInew.PricebookEntryId == '01t61000001D7y6') || // 0270-0415 (QLInew.PricebookEntryId == '01u61000003Lhpd') || // 0270-0793 (QLInew.PricebookEntryId == '01u61000003Lhpg') //0270-0790 ))) { system.debug(QuantityNew); system.debug(QuantityOld); List<QuotelineItem> zeroQLI = [SELECT id FROM QuoteLineItem WHERE UnitPrice = 0]; delete zeroQLI; } for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0200, add 0003-0129 if ((QLI.PricebookEntryId == '01u61000003LhrX') && (QuantityNew != QuantityOld)) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqI'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0404, add 0003-0374 if ((QLI.PricebookEntryId == '01u61000003LhpS') && (QuantityNew != QuantityOld)) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003M03X'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0870, add 0003-1179 if ((QLI.PricebookEntryId == '01u61000003LhpQ') && (QuantityNew != QuantityOld)) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqA'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { if ((QLI.PricebookEntryId == '01u61000003LhpR')|| //0270-0912 (QLI.PricebookEntryId == '01u61000003LhpX') || //0270-0878 (QLI.PricebookEntryId == '01u61000003Lhpa') || //0270-0747 (QLI.PricebookEntryId == '01u61000003Lhpb') //0270-0749 && (QuantityNew != QuantityOld)) { //if above, add 0003-0878 QuoteLineItem newQLI = new QuoteLineItem(); system.debug(QuantityNew); system.debug(QuantityOld); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003Lhpn'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { if ((QLI.PricebookEntryId == '01u61000003LhpT')|| //0270-0860 (QLI.PricebookEntryId == '01u61000003LhpU') || //0270-0858 (QLI.PricebookEntryId == '01u61000003LhpV') || //0270-0821 (QLI.PricebookEntryId == '01u61000003LhpW') || //0270-0822 (QLI.PricebookEntryId == '01u61000003LhpY') || //0270-0817 (QLI.PricebookEntryId == '01u61000003LhpZ') || //0270-0818 (QLI.PricebookEntryId == '01u61000003Lhpc') || //0270-0604 (QLI.PricebookEntryId == '01t61000001D7y6') //0270-0415 && (QuantityNew != QuantityOld)) //if above, add 0003-1085 { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003Lhpy'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0793 or 0270-0790 (not currently on contract), add 0003-0259 if ((QLI.PricebookEntryId == '01u61000003Lhpd')|| (QLI.PricebookEntryId == '01u61000003Lhpg') && (QuantityNew != QuantityOld)) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqU'; insert newQLI; }}}}}} if(trigger.isdelete){ for (QuoteLineItem QLInew : Trigger.old){ // if (QLInew.Quote.Pricebook2.Name == 'Bon Secours (exp 1/5/2020)'){ List<QuotelineItem> zeroQLI = [SELECT id FROM QuoteLineItem WHERE UnitPrice = 0]; delete zeroQLI; }}}
Test Class:
@isTest(SeeAllData=true) public class bsWarranty_Test { static testMethod void testBonSecoursWarranty(){ Account acct = New Account(); acct.Name = 'Test Account'; acct.PC_Territory__c = '1234'; acct.CC_Territory__c = '1234'; acct.Facility_Type__c = 'Acute'; acct.ShippingCountryCode = 'US'; acct.ShippingStreet = '1234 Test Lane'; acct.ShippingPostalCode = '12345'; acct.ShippingStateCode = 'WA'; insert acct; Opportunity opp = New Opportunity(); opp.Name = 'Test'; opp.CloseDate = Date.today(); opp.CurrencyIsoCode = 'USD'; opp.AccountId = acct.id; opp.StageName = 'Qualified'; opp.Business_Type__c = 'Patient care'; opp.RecordTypeId = '012610000002W6nAAE'; opp.Pricebook2Id = '01s61000003U9Id'; insert opp; Quote quote = New Quote(); quote.Name = 'Test'; quote.ExpirationDate = date.today(); quote.ShippingHandling = 0; quote.Ship_Date__c = date.today(); quote.OpportunityId = opp.id; quote.Pricebook2Id = '01s61000003U9Id'; insert quote; QuoteLineItem QLI = New QuoteLineItem(); qli.QuoteId = Quote.Id; qli.PricebookEntryId = '01u61000003LhpS'; qli.UnitPrice = 0; qli.Quantity = 1; insert QLI; QuoteLineItem QLI1 = New QuoteLineItem(); qli1.QuoteId = Quote.Id; qli1.PricebookEntryId = '01u61000003LhrX'; qli1.UnitPrice = 0; qli1.Quantity = 1; insert QLI1; QuoteLineItem QLI2 = New QuoteLineItem(); qli2.QuoteId = Quote.Id; qli2.PricebookEntryId = '01u61000003LhpQ'; qli2.UnitPrice = 0; qli2.Quantity = 1; insert QLI2; QuoteLineItem QLI3 = New QuoteLineItem(); qli3.QuoteId = Quote.Id; qli3.PricebookEntryId = '01u61000003LhpR'; qli3.UnitPrice = 0; qli3.Quantity = 1; insert QLI3; QuoteLineItem QLI4 = New QuoteLineItem(); qli4.QuoteId = Quote.Id; qli4.PricebookEntryId = '01u61000003LhpT'; qli4.UnitPrice = 0; qli4.Quantity = 1; insert QLI4; QuoteLineItem QLI5 = New QuoteLineItem(); qli5.QuoteId = Quote.Id; qli5.PricebookEntryId = '01u61000003Lhpg'; qli5.UnitPrice = 0; qli5.Quantity = 1; insert QLI5; Quote quote1 = New Quote(); quote1.Name = 'Test1'; quote1.ExpirationDate = date.today(); quote1.ShippingHandling = 0; quote1.Ship_Date__c = date.today(); quote1.OpportunityId = opp.id; quote1.Pricebook2Id = '01s61000003U9Id'; insert quote1; QuoteLineItem QLI6 = New QuoteLineItem(); qli6.QuoteId = quote1.Id; qli6.PricebookEntryId = '01u61000003Lhpg'; qli6.UnitPrice = 0; qli6.Quantity = 1; insert QLI6; QLI6.Quantity = 2; update QLI6; delete QLI6; } }
RecursiveCheck class:
public Class RecursiveCheck{ private static boolean run = true; public static boolean runOnce(){ if(run){ run=false; return true; }else{ return run; } } }
If someone can point out how I need to change one of the three above blocks of code, that would be much appreciated. I'm getting good code coverage except under the IsUpdate clause due to the RecursiveCheck.
Thank you!
- Tarek Zaheer 1
- February 06, 2017
- Like
- 0
Updating a checkbox field if a File is uploaded through ContentDocumentLink trigger
Hi everyone,
Here is my business requirement:
On the standard Quote object, I have a custom checkbox field called PO_Attached__c. If a File is uploaded to a Quote record, PO_Attached__c should be updated to true. I currently achieve this functionality using the Attachments functionality by use of an Apex trigger.
However, we are now migrating to Files. I have updated my code block as below. It saves fine, but the checkbox is never updated. Any ideas why? Thanks in advance.
Here is my business requirement:
On the standard Quote object, I have a custom checkbox field called PO_Attached__c. If a File is uploaded to a Quote record, PO_Attached__c should be updated to true. I currently achieve this functionality using the Attachments functionality by use of an Apex trigger.
However, we are now migrating to Files. I have updated my code block as below. It saves fine, but the checkbox is never updated. Any ideas why? Thanks in advance.
trigger quoteAttachment2 on ContentDocumentLink (after insert) { List<Quote> listOfQuote = [select id from Quote where id =: Trigger.New[0].LinkedEntityId]; if(listOfQuote.size()>0) { listOfQuote[0].PO_Attached__c = true; update listOfQuote; } }
- Tarek Zaheer 1
- December 04, 2017
- Like
- 0
Code Coverage - Test Class does not cover "After Update" with checkRecursive
Hi everyone, There have been some other posts on this exact same issue but none of those posted solutions have worked for me. I have a trigger that is firing twice when it should only be firing once. To solve this, I used checkRecursive (class pasted below). My trigger works fine now. However, my test class is not covering the section of my trigger which is isUpdate. This is due to the checkRecursive.
Trigger:
Test Class:
RecursiveCheck class:
If someone can point out how I need to change one of the three above blocks of code, that would be much appreciated. I'm getting good code coverage except under the IsUpdate clause due to the RecursiveCheck.
Thank you!
Trigger:
trigger bsWarranty on QuoteLineItem (after insert,after update, after delete) { if(trigger.isinsert){ for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0200, add 0003-0129 if ((QLI.PricebookEntryId == '01u61000003LhrX')) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqI'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0404, add 0003-0374 if ((QLI.PricebookEntryId == '01u61000003LhpS')) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003M03X'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0870, add 0003-1179 if ((QLI.PricebookEntryId == '01u61000003LhpQ')) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqA'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { if ((QLI.PricebookEntryId == '01u61000003LhpR')|| //0270-0912 (QLI.PricebookEntryId == '01u61000003LhpX') || //0270-0878 (QLI.PricebookEntryId == '01u61000003Lhpa') || //0270-0747 (QLI.PricebookEntryId == '01u61000003Lhpb')) { //0270-0749 //if above, add 0003-0878 QuoteLineItem newQLI = new QuoteLineItem(); system.debug(QLI.Quantity); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003Lhpn'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { if ((QLI.PricebookEntryId == '01u61000003LhpT')|| //0270-0860 (QLI.PricebookEntryId == '01u61000003LhpU') || //0270-0858 (QLI.PricebookEntryId == '01u61000003LhpV') || //0270-0821 (QLI.PricebookEntryId == '01u61000003LhpW') || //0270-0822 (QLI.PricebookEntryId == '01u61000003LhpY') || //0270-0817 (QLI.PricebookEntryId == '01u61000003LhpZ') || //0270-0818 (QLI.PricebookEntryId == '01u61000003Lhpc') || //0270-0604 (QLI.PricebookEntryId == '01u61000003Lhpe')) //0270-0415 //if above, add 0003-1085 { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003Lhpy'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0793 or 0270-0790 (not currently on contract), add 0003-0259 if ((QLI.PricebookEntryId == '01u61000003Lhpg')|| (QLI.PricebookEntryId == '01u61000003Lhpd')) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqU'; insert newQLI; }}}} if (trigger.isupdate) { if(RecursiveCheck.runOnce()){ for (QuoteLineItem QLInew : Trigger.new){ Decimal QuantityNew = QLInew.Quantity; QuoteLineItem QLIold = Trigger.oldMap.get(QLInew.id); Decimal QuantityOld = QLIold.Quantity; system.debug('@@@@@@@@@@'+QuantityOld); system.debug('@@@@@@@@@@'+QuantityNew); if (((QuantityNew != QuantityOld) && (QLInew.Quote.Pricebook2.id == '01s61000003U9Id') && ((QLInew.PricebookEntryId == '01u61000003LhrX') || // 0270-0200 (QLInew.PricebookEntryId == '01u61000003LhpS') || // 0270-0404 (QLInew.PricebookEntryId == '01u61000003LhpQ') || // 0270-0870 (QLInew.PricebookEntryId == '01u61000003LhpR') || // 0270-0912 (QLInew.PricebookEntryId == '01u61000003LhpX') || // 0270-0878 (QLInew.PricebookEntryId == '01u61000003Lhpa') || // 0270-0747 (QLInew.PricebookEntryId == '01u61000003Lhpb') || // 0270-0749 (QLInew.PricebookEntryId == '01u61000003LhpT') || // 0270-0860 (QLInew.PricebookEntryId == '01u61000003LhpU') || // 0270-0858 (QLInew.PricebookEntryId == '01u61000003LhpV') || // 0270-0821 (QLInew.PricebookEntryId == '01u61000003LhpW') || // 0270-0822 (QLInew.PricebookEntryId == '01u61000003LhpY') || // 0270-0817 (QLInew.PricebookEntryId == '01u61000003LhpZ') || // 0270-0818 (QLInew.PricebookEntryId == '01u61000003Lhpc') || // 0270-0604 (QLInew.PricebookEntryId == '01t61000001D7y6') || // 0270-0415 (QLInew.PricebookEntryId == '01u61000003Lhpd') || // 0270-0793 (QLInew.PricebookEntryId == '01u61000003Lhpg') //0270-0790 ))) { system.debug(QuantityNew); system.debug(QuantityOld); List<QuotelineItem> zeroQLI = [SELECT id FROM QuoteLineItem WHERE UnitPrice = 0]; delete zeroQLI; } for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0200, add 0003-0129 if ((QLI.PricebookEntryId == '01u61000003LhrX') && (QuantityNew != QuantityOld)) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqI'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0404, add 0003-0374 if ((QLI.PricebookEntryId == '01u61000003LhpS') && (QuantityNew != QuantityOld)) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003M03X'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0870, add 0003-1179 if ((QLI.PricebookEntryId == '01u61000003LhpQ') && (QuantityNew != QuantityOld)) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqA'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { if ((QLI.PricebookEntryId == '01u61000003LhpR')|| //0270-0912 (QLI.PricebookEntryId == '01u61000003LhpX') || //0270-0878 (QLI.PricebookEntryId == '01u61000003Lhpa') || //0270-0747 (QLI.PricebookEntryId == '01u61000003Lhpb') //0270-0749 && (QuantityNew != QuantityOld)) { //if above, add 0003-0878 QuoteLineItem newQLI = new QuoteLineItem(); system.debug(QuantityNew); system.debug(QuantityOld); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003Lhpn'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { if ((QLI.PricebookEntryId == '01u61000003LhpT')|| //0270-0860 (QLI.PricebookEntryId == '01u61000003LhpU') || //0270-0858 (QLI.PricebookEntryId == '01u61000003LhpV') || //0270-0821 (QLI.PricebookEntryId == '01u61000003LhpW') || //0270-0822 (QLI.PricebookEntryId == '01u61000003LhpY') || //0270-0817 (QLI.PricebookEntryId == '01u61000003LhpZ') || //0270-0818 (QLI.PricebookEntryId == '01u61000003Lhpc') || //0270-0604 (QLI.PricebookEntryId == '01t61000001D7y6') //0270-0415 && (QuantityNew != QuantityOld)) //if above, add 0003-1085 { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003Lhpy'; insert newQLI; }}} for (QuoteLineItem QLI : Trigger.new) { for (Integer i = 0; i < QLI.Quantity; i++) { //if 0270-0793 or 0270-0790 (not currently on contract), add 0003-0259 if ((QLI.PricebookEntryId == '01u61000003Lhpd')|| (QLI.PricebookEntryId == '01u61000003Lhpg') && (QuantityNew != QuantityOld)) { QuoteLineItem newQLI = new QuoteLineItem(); newQLI.Quantity = 36; newQLI.QuoteId = QLI.QuoteId; newQLI.UnitPrice = 0; newQLI.PricebookEntryId = '01u61000003LhqU'; insert newQLI; }}}}}} if(trigger.isdelete){ for (QuoteLineItem QLInew : Trigger.old){ // if (QLInew.Quote.Pricebook2.Name == 'Bon Secours (exp 1/5/2020)'){ List<QuotelineItem> zeroQLI = [SELECT id FROM QuoteLineItem WHERE UnitPrice = 0]; delete zeroQLI; }}}
Test Class:
@isTest(SeeAllData=true) public class bsWarranty_Test { static testMethod void testBonSecoursWarranty(){ Account acct = New Account(); acct.Name = 'Test Account'; acct.PC_Territory__c = '1234'; acct.CC_Territory__c = '1234'; acct.Facility_Type__c = 'Acute'; acct.ShippingCountryCode = 'US'; acct.ShippingStreet = '1234 Test Lane'; acct.ShippingPostalCode = '12345'; acct.ShippingStateCode = 'WA'; insert acct; Opportunity opp = New Opportunity(); opp.Name = 'Test'; opp.CloseDate = Date.today(); opp.CurrencyIsoCode = 'USD'; opp.AccountId = acct.id; opp.StageName = 'Qualified'; opp.Business_Type__c = 'Patient care'; opp.RecordTypeId = '012610000002W6nAAE'; opp.Pricebook2Id = '01s61000003U9Id'; insert opp; Quote quote = New Quote(); quote.Name = 'Test'; quote.ExpirationDate = date.today(); quote.ShippingHandling = 0; quote.Ship_Date__c = date.today(); quote.OpportunityId = opp.id; quote.Pricebook2Id = '01s61000003U9Id'; insert quote; QuoteLineItem QLI = New QuoteLineItem(); qli.QuoteId = Quote.Id; qli.PricebookEntryId = '01u61000003LhpS'; qli.UnitPrice = 0; qli.Quantity = 1; insert QLI; QuoteLineItem QLI1 = New QuoteLineItem(); qli1.QuoteId = Quote.Id; qli1.PricebookEntryId = '01u61000003LhrX'; qli1.UnitPrice = 0; qli1.Quantity = 1; insert QLI1; QuoteLineItem QLI2 = New QuoteLineItem(); qli2.QuoteId = Quote.Id; qli2.PricebookEntryId = '01u61000003LhpQ'; qli2.UnitPrice = 0; qli2.Quantity = 1; insert QLI2; QuoteLineItem QLI3 = New QuoteLineItem(); qli3.QuoteId = Quote.Id; qli3.PricebookEntryId = '01u61000003LhpR'; qli3.UnitPrice = 0; qli3.Quantity = 1; insert QLI3; QuoteLineItem QLI4 = New QuoteLineItem(); qli4.QuoteId = Quote.Id; qli4.PricebookEntryId = '01u61000003LhpT'; qli4.UnitPrice = 0; qli4.Quantity = 1; insert QLI4; QuoteLineItem QLI5 = New QuoteLineItem(); qli5.QuoteId = Quote.Id; qli5.PricebookEntryId = '01u61000003Lhpg'; qli5.UnitPrice = 0; qli5.Quantity = 1; insert QLI5; Quote quote1 = New Quote(); quote1.Name = 'Test1'; quote1.ExpirationDate = date.today(); quote1.ShippingHandling = 0; quote1.Ship_Date__c = date.today(); quote1.OpportunityId = opp.id; quote1.Pricebook2Id = '01s61000003U9Id'; insert quote1; QuoteLineItem QLI6 = New QuoteLineItem(); qli6.QuoteId = quote1.Id; qli6.PricebookEntryId = '01u61000003Lhpg'; qli6.UnitPrice = 0; qli6.Quantity = 1; insert QLI6; QLI6.Quantity = 2; update QLI6; delete QLI6; } }
RecursiveCheck class:
public Class RecursiveCheck{ private static boolean run = true; public static boolean runOnce(){ if(run){ run=false; return true; }else{ return run; } } }
If someone can point out how I need to change one of the three above blocks of code, that would be much appreciated. I'm getting good code coverage except under the IsUpdate clause due to the RecursiveCheck.
Thank you!
- Tarek Zaheer 1
- February 06, 2017
- Like
- 0