You need to sign in to do that
Don't have an account?
SarikaP
Code Optimization/Code Bulkification
Hello,
Is there a better way to code the below lines of code:
Logic:
We have 2 terms and conditions for the quote in an custom object Terms_and_Conditions_Quote__c currently for the quotes greater than 5K. (as T&C's are linked to product)
For all the quotes greater than 5K, Term A should not be present and Term B should be present.
if(setGrtAmtQTC != null && setGrtAmtQTC.size() > 0) //Set of quoteids with quote amount greater than 5K.
{
//Looking for Quotes with Term A
Map<Id,Terms_and_Conditions_Quote__c> mapdelCCTCQuoteId = new Map<Id,Terms_and_Conditions_Quote__c>([select Id,Quote__c,Terms_and_Conditions__c from Terms_and_Conditions_Quote__c where quote__c in : setGrtAmtQTC and Terms_and_Conditions__c =: 'a0o60000000ZyWmAAK']); //Term A
// Delete Credit Card T&C for Quotes having greater amount than 5K
System.debug('List size to delete credit card quote:' + mapdelCCTCQuoteId.size());
if(mapdelCCTCQuoteId != null && mapdelCCTCQuoteId.size() > 0)
{
lsttodel1.addall(mapdelCCTCQuoteId.values());
//check for the quotes with same Term A if we have Term B too.
for(Terms_and_Conditions_Quote__c obj: mapdelCCTCQuoteId.values())
setdelCCQId.add(mapdelCCTCQuoteId.get(obj.Id).Quote__c);
Set<Terms_and_Conditions_Quote__c> setremnetpqid = new Set<Terms_and_Conditions_Quote__c>([select Quote__c from Terms_and_Conditions_Quote__c where quote__c in : setdelCCQId and Terms_and_Conditions__c =: 'a0o60000000ZyWf']); //Term B
//if quotes has term B, remove it from set setdelCCQId
if(setremnetpqid!= null && setremnetpqid.size() > 0)
{
for(Terms_and_Conditions_Quote__c objq: setremnetpqid)
setdelCCQId.remove(objq.Quote__c);
}
//For all the quotes that dont have Term B in the set setdelCCQId add them
if(setdelCCQId != null && setdelCCQId.size() > 0)
{
for(Id tcquoteid : setdelCCQId)
{
lsttoins1.add(new Terms_and_Conditions_Quote__c(
Quote__c = tcquoteid,
Terms_and_Conditions__c = 'a0o60000000ZyWf'//Term B
));
}
}
}
}
Is there a better way to code the below lines of code:
Logic:
We have 2 terms and conditions for the quote in an custom object Terms_and_Conditions_Quote__c currently for the quotes greater than 5K. (as T&C's are linked to product)
For all the quotes greater than 5K, Term A should not be present and Term B should be present.
if(setGrtAmtQTC != null && setGrtAmtQTC.size() > 0) //Set of quoteids with quote amount greater than 5K.
{
//Looking for Quotes with Term A
Map<Id,Terms_and_Conditions_Quote__c> mapdelCCTCQuoteId = new Map<Id,Terms_and_Conditions_Quote__c>([select Id,Quote__c,Terms_and_Conditions__c from Terms_and_Conditions_Quote__c where quote__c in : setGrtAmtQTC and Terms_and_Conditions__c =: 'a0o60000000ZyWmAAK']); //Term A
// Delete Credit Card T&C for Quotes having greater amount than 5K
System.debug('List size to delete credit card quote:' + mapdelCCTCQuoteId.size());
if(mapdelCCTCQuoteId != null && mapdelCCTCQuoteId.size() > 0)
{
lsttodel1.addall(mapdelCCTCQuoteId.values());
//check for the quotes with same Term A if we have Term B too.
for(Terms_and_Conditions_Quote__c obj: mapdelCCTCQuoteId.values())
setdelCCQId.add(mapdelCCTCQuoteId.get(obj.Id).Quote__c);
Set<Terms_and_Conditions_Quote__c> setremnetpqid = new Set<Terms_and_Conditions_Quote__c>([select Quote__c from Terms_and_Conditions_Quote__c where quote__c in : setdelCCQId and Terms_and_Conditions__c =: 'a0o60000000ZyWf']); //Term B
//if quotes has term B, remove it from set setdelCCQId
if(setremnetpqid!= null && setremnetpqid.size() > 0)
{
for(Terms_and_Conditions_Quote__c objq: setremnetpqid)
setdelCCQId.remove(objq.Quote__c);
}
//For all the quotes that dont have Term B in the set setdelCCQId add them
if(setdelCCQId != null && setdelCCQId.size() > 0)
{
for(Id tcquoteid : setdelCCQId)
{
lsttoins1.add(new Terms_and_Conditions_Quote__c(
Quote__c = tcquoteid,
Terms_and_Conditions__c = 'a0o60000000ZyWf'//Term B
));
}
}
}
}