Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. public class QuoteSyncUtil {
  2.  
  3. public static boolean isRunningTest = false;
  4.  
  5. private static Map<String, String> quoteFieldMap = new Map<String, String>();
  6. private static Map<String, String> quoteLineFieldMap = new Map<String, String>();
  7.  
  8. static {
  9. public static String getQuoteFieldsString() {
  10. String fields = '';
  11. for (String field : getQuoteFields()) {
  12. fields += ', ' + field;
  13. }
  14. return fields;
  15. }
  16. Map<String, QuoteLineSyncField__c> quoteLineFields = QuoteLineSyncField__c.getAll();
  17. system.debug('KENNY '+quoteLineFields);
  18.  
  19. for (String quoteLineField : quoteLineFields.keySet()) {
  20. QuoteLineSyncField__c quoteLineSyncField = QuoteLineSyncField__c.getInstance(quoteLineField);
  21. //FIXME - uppercase value cause NPE
  22. quoteLineFieldMap.put(quoteLineSyncField.Name, quoteLineSyncField.OppLineSyncField__c);
  23. system.debug('KENNY '+QuoteLineSyncField__c.getInstance(quoteLineField));
  24. //quoteLineFieldMap.put(quoteLineField, quoteLineSyncField.OppLineSyncField__c);
  25.  
  26. if(quotelinefield == 'Product_Type__c'){
  27. System.debug('********* ' + quoteLineField);
  28. System.debug('^^^^^^^^^ ' + quotelineSyncField.OppLineSyncField__c);
  29. }
  30. }
  31. }
  32.  
  33. public static Set<String> getQuoteLineFields() {
  34. system.debug('KENNY '+quoteLineFieldMap.keyset());
  35. return quoteLineFieldMap.keySet();
  36. }
  37.  
  38. List<String> oppLineFields = QuoteSyncUtil.getOppLineFields();
  39.  
  40. // pricebook entry ids in trigger
  41. Set<Id> pbEntryIds = new Set<Id>();
  42.  
  43. // a Set of Pricebook2 Ids represented in Trigger.new
  44. Set<Id> setPricebookId = new Set<Id>();
  45.  
  46. String oliFields = QuoteSyncUtil.getOppLineFieldsString();
  47. String qliFields = QuoteSyncUtil.getQuoteLineFieldsString();
  48.  
  49. String qliIds = '';
  50. String quoteIdString = '';
  51. for (QuoteLineItem qli : qlisInTrigger) {
  52. if (qliIds != '') qliIds += ', ';
  53. qliIds += ''' + qli.Id + ''';
  54.  
  55. if (quoteIdString != '') quoteIdString += ', ';
  56. quoteIdString += ''' + qli.QuoteId + ''';
  57.  
  58. pbEntryIds.add(qli.PricebookEntryId);
  59. }
  60.  
  61. String qliQuery = 'SELECT Id, ' +
  62. 'QuoteId, ' +
  63. 'PricebookEntryId, ' +
  64. 'UnitPrice, ' +
  65. 'Quantity, ' +
  66. 'Discount, ' +
  67. 'ServiceDate, ' +
  68. 'SortOrder, ' +
  69. 'PricebookEntry.Product2.Name, ' +
  70. 'PricebookEntry.Product2.Product_Type__c, ' +
  71. 'PricebookEntry.Product2.Approval_Required__c, ' +
  72. 'PricebookEntry.Pricebook2Id, ' +
  73. 'ListPrice, ' +
  74. 'Discount_off_List__c ' +
  75. qliFields +
  76. ' FROM QuoteLineItem where QuoteId in (' + quoteIdString + ')';
  77.  
  78. System.debug(qliQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement