You need to sign in to do that
Don't have an account?
Don Pierce
Trying to define a trigger to number the quote line items within each quote
Here is the code but I am getting this error:
Error: Compile Error: unexpected syntax: 'missing EOF at '}'' at line 61 column 1
Of course line 61 is the closing curly brace before the Plublic Class declaration
trigger QuoteLineItemTrigger on QuoteLineItem (after insert, after update){
// prevent recursion
if (!QuoteLineItemUtility.TriggerIsRunning){
QuoteLineItemUtility.TriggerIsRunning = true;
Set<Id> QuoteIds = new Set<Id>();
List<QuoteLineItem> lineItemsForUpdate = new List<QuoteLineItem>();
// gather IDs first of quotes
for (QuoteLineItem ql : trigger.new) {
QuoteIds.add(ql.QuoteId);
}
}
if (!QuoteIds.isEmpty()) {
// get all line items for all of the above quotes in bulk so that we don't hit governor limits
Id prevQuoteId;
Integer lastLineNumber;
// we can query all and these triggered records in an after trigger, nothing missing
for (QuoteLineItem ql : [Select Id, Item_Numbering__c
From QuoteLineItem
Where QuoteId in :QuoteIds
Order By QuoteId, Item_Numbering__c NULLS LAST]) {
// These are coming in already grouped by the same quote
// and are sorted by the line number within that group
if (prevQuoteId == null || prevQuoteId != ql.QuoteId) {
// start fresh because this is the first iteration OR we made it to
// another group of line items
prevQuoteId = ql.QuoteId;
lastLineNumber = 0; //back to default
}
// Set the new line numbers as needed
if(ql.Item_Numbering__c == null || ql.Item_Numbering__c == 0) {
ql.Item_Numbering__c = lastLineNumber + 1;
// Need to create a "new" in memory line item to break reference to the
// trigger reference, otherwise you will get an error like "cannot update in an After trigger"
lineItemsForUpdate.add(new QuoteLineItem(id = ql.id, Item_Numbering__c = ql.Item_Numbering__c));
}
lastLineNumber = ql.Item_Numbering__c;
} // end for
}
if (!lineItemsForUpdate.isEmpty())
update lineItemsForUpdate; // DML only the changed line items
QuoteLineItemUtility.TriggerIsRunning = false;
}
}
public class QuoteLineItemUtility(){
public static TriggerIsRunning = false;
}
Error: Compile Error: unexpected syntax: 'missing EOF at '}'' at line 61 column 1
Of course line 61 is the closing curly brace before the Plublic Class declaration
trigger QuoteLineItemTrigger on QuoteLineItem (after insert, after update){
// prevent recursion
if (!QuoteLineItemUtility.TriggerIsRunning){
QuoteLineItemUtility.TriggerIsRunning = true;
Set<Id> QuoteIds = new Set<Id>();
List<QuoteLineItem> lineItemsForUpdate = new List<QuoteLineItem>();
// gather IDs first of quotes
for (QuoteLineItem ql : trigger.new) {
QuoteIds.add(ql.QuoteId);
}
}
if (!QuoteIds.isEmpty()) {
// get all line items for all of the above quotes in bulk so that we don't hit governor limits
Id prevQuoteId;
Integer lastLineNumber;
// we can query all and these triggered records in an after trigger, nothing missing
for (QuoteLineItem ql : [Select Id, Item_Numbering__c
From QuoteLineItem
Where QuoteId in :QuoteIds
Order By QuoteId, Item_Numbering__c NULLS LAST]) {
// These are coming in already grouped by the same quote
// and are sorted by the line number within that group
if (prevQuoteId == null || prevQuoteId != ql.QuoteId) {
// start fresh because this is the first iteration OR we made it to
// another group of line items
prevQuoteId = ql.QuoteId;
lastLineNumber = 0; //back to default
}
// Set the new line numbers as needed
if(ql.Item_Numbering__c == null || ql.Item_Numbering__c == 0) {
ql.Item_Numbering__c = lastLineNumber + 1;
// Need to create a "new" in memory line item to break reference to the
// trigger reference, otherwise you will get an error like "cannot update in an After trigger"
lineItemsForUpdate.add(new QuoteLineItem(id = ql.id, Item_Numbering__c = ql.Item_Numbering__c));
}
lastLineNumber = ql.Item_Numbering__c;
} // end for
}
if (!lineItemsForUpdate.isEmpty())
update lineItemsForUpdate; // DML only the changed line items
QuoteLineItemUtility.TriggerIsRunning = false;
}
}
public class QuoteLineItemUtility(){
public static TriggerIsRunning = false;
}
http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Trigger:
Class:
All Answers
http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Trigger:
Class: