Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.64 KB | None | 0 0
  1. public with sharing class OpportunityService {
  2. public static final String STAGE_MEETING_BOOKED = 'Meeting Booked';
  3. public static final String STAGE_LICENCE_OUT = 'Licence Out';
  4. public static final String STAGE_COMPLETED = 'Completed';
  5. public static final String STAGE_CHECK_COMPLETE = 'Check Complete';
  6. public static final String STAGE_INSTRUCTED = 'Instructed';
  7. public static final String STAGE_EXCHANGED = 'Exchanged';
  8. public static final String STAGE_QUALIFIED = 'Qualified';
  9. public static final String STAGE_CLOSED_LOST = 'Closed Lost';
  10. public static final String STAGE_VIEWING = 'Viewing';
  11. public static final String STAGE_TERMS_OUT = 'Terms Out';
  12.  
  13. public static final String CAR_PARKING_PRODUCT = 'Car Parking';
  14. public static final String RETAIL_PRODUCT = 'Retail';
  15.  
  16.  
  17. public static final String VIRTUAL_RECORD_TYPE_NAME = 'Virtual';
  18. public static final String CONVENTIONAL_RECORD_TYPE = 'Conventional';
  19. public static final String SERVICED_RECORD_TYPE = 'Serviced';
  20. public static final Id VIRTUAL_RECORD_TYPE_ID;
  21. public static final Id CONVENTIONAL_RECORD_TYPE_ID;
  22. public static final Id SERVICED_RECORD_TYPE_ID;
  23.  
  24. public static final String COMPLETION_NOTIFICATION_SCHEDULED_JOB = 'COMPLETION_NOTIFICATION_SENDER';
  25. public static final Integer NOTIFICATION_DELAY_MIN = 2;
  26.  
  27. static {
  28. VIRTUAL_RECORD_TYPE_ID = RecordTypeHelper.getOpportunityRtIdByName(VIRTUAL_RECORD_TYPE_NAME);
  29. CONVENTIONAL_RECORD_TYPE_ID = RecordTypeHelper.getOpportunityRtIdByName(CONVENTIONAL_RECORD_TYPE);
  30. SERVICED_RECORD_TYPE_ID = RecordTypeHelper.getOpportunityRtIdByName(SERVICED_RECORD_TYPE);
  31. }
  32.  
  33. private static Set<String> conventionalProductsOppClosing = new Set<String>{
  34. ProductService.PRODUCT_CODE_LAB_SPACE,
  35. ProductService.PRODUCT_CODE_OFFICE_RENT,
  36. ProductService.PRODUCT_CODE_RETAIL_RENT,
  37. ProductService.PRODUCT_CODE_STORAGE,
  38. ProductService.PRODUCT_CODE_ALL_INCLUSIVE
  39. };
  40.  
  41. private static Map<Id, RecordType> opportunityRecordTypes;
  42. public static Map<Id, RecordType> getRecordTypes() {
  43. if (opportunityRecordTypes == null) {
  44. opportunityRecordTypes = new Map<Id, RecordType>(
  45. RecordTypeHelper.getRecordTypesForSObject(SObjectConstants.OPPORTUNITY_SOBJECT)
  46. );
  47. }
  48. return opportunityRecordTypes;
  49. }
  50.  
  51. public static List<Opportunity> completeContractOpportunity(Id recordTypeId, List<Opportunity> opportunities, Map<Id, Contract> contractsMap) {
  52. List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
  53. List<Opportunity> opportunitiesToCompletionNotification = new List<Opportunity>();
  54.  
  55. for (Opportunity theOpportunity : opportunities) {
  56. if (recordTypeId == CONVENTIONAL_RECORD_TYPE_ID) {
  57. if (theOpportunity.Product__c != CAR_PARKING_PRODUCT) {
  58. opportunitiesToCompletionNotification.add(theOpportunity);
  59. }
  60. theOpportunity.Contract_Ready_For_Finance__c = true;
  61. } else if (recordTypeId == SERVICED_RECORD_TYPE_ID) {
  62. if (theOpportunity.Product__c != CAR_PARKING_PRODUCT) {
  63. theOpportunity.Contract_Ready_For_Finance__c = true;
  64. opportunitiesToCompletionNotification.add(theOpportunity);
  65. } else {
  66. theOpportunity.Automated_Status_Change__c = true;
  67. theOpportunity.StageName = OpportunityService.STAGE_COMPLETED;
  68. }
  69. } else if (theOpportunity.Product__c == CAR_PARKING_PRODUCT) {
  70. theOpportunity.Automated_Status_Change__c = true;
  71. theOpportunity.StageName = OpportunityService.STAGE_COMPLETED;
  72. }
  73. opportunitiesToUpdate.add(theOpportunity);
  74. }
  75.  
  76. pushCompletionNotifications(opportunitiesToCompletionNotification);
  77.  
  78. return opportunitiesToUpdate;
  79. }
  80.  
  81. private static Boolean isConventionalProductExistOnContract(Map<Id, Contract> contractsMap, String contractId) {
  82. if (contractsMap.containsKey(contractId)) {
  83. Contract currentContract = contractsMap.get(contractId);
  84. for (SBQQ__Subscription__c subscription : currentContract.SBQQ__Subscriptions__r) {
  85. if (conventionalProductsOppClosing.contains(subscription.Product_Code__c)) {
  86. return true;
  87. }
  88. }
  89. }
  90. return false;
  91. }
  92.  
  93. public static void createTaskForCoordinator(List<Opportunity> opportunities) {
  94. Map<Id, Opportunity> completedOpportunitiesMap = new Map<Id, Opportunity>();
  95. Map<String, Opportunity> meetingBookedOpportunitiesMap = new Map<String, Opportunity>();
  96. List<Task> tasksToCreate = new List<Task>();
  97.  
  98. for (Opportunity theOpportunity : opportunities) {
  99. if (theOpportunity.StageName.equals(STAGE_COMPLETED) && theOpportunity.Deposit_Paid__c) {
  100. completedOpportunitiesMap.put(theOpportunity.Id, theOpportunity);
  101. }
  102. if (theOpportunity.StageName.equals(STAGE_MEETING_BOOKED) && theOpportunity.Last_Event_ID__c != null) {
  103. meetingBookedOpportunitiesMap.put(theOpportunity.Last_Event_ID__c, theOpportunity);
  104. }
  105. }
  106.  
  107. if (!completedOpportunitiesMap.isEmpty()) {
  108. Set<Id> contractIds = SObjectUtils.getIdSetFromObjects(completedOpportunitiesMap.values(), 'ContractId');
  109. List<Contract> contracts = [
  110. SELECT Id, Name,
  111. StartDate,
  112. SBQQ__Opportunity__c,
  113. SBQQ__Quote__c,
  114. SBQQ__Quote__r.SBQQ__PrimaryContact__c,
  115. SBQQ__Quote__r.SBQQ__PrimaryContact__r.Name,
  116. SBQQ__Quote__r.Property__c,
  117. SBQQ__Quote__r.Property__r.Serviced_Space_Coordinator__c
  118. FROM Contract
  119. WHERE Id IN :contractIds
  120. AND SBQQ__Quote__r.Property__r.Serviced_Space_Coordinator__c != NULL
  121. ];
  122.  
  123. for (Contract theContract : contracts) {
  124. Id opportunityId = theContract.SBQQ__Opportunity__c;
  125. if (completedOpportunitiesMap.containsKey(opportunityId)) {
  126. Opportunity theOpportunity = completedOpportunitiesMap.get(opportunityId);
  127. tasksToCreate.add(TaskService.generateVirtualOnboardingTask(theOpportunity, theContract));
  128. }
  129. }
  130. }
  131.  
  132. if (!meetingBookedOpportunitiesMap.isEmpty()) {
  133. List<Event> events = [
  134. SELECT Id, RecordTypeId, Property__c, Property__r.Serviced_Space_Coordinator__c, WhoId, ActivityDate
  135. FROM Event
  136. WHERE Id IN:meetingBookedOpportunitiesMap.keySet()
  137. AND Property__r.Serviced_Space_Coordinator__c != NULL
  138. ];
  139. for (Event theEvent : events) {
  140. Id eventId = theEvent.Id;
  141.  
  142. if (meetingBookedOpportunitiesMap.containsKey(eventId)) {
  143. Opportunity theOpportunity = meetingBookedOpportunitiesMap.get(eventId);
  144. tasksToCreate.add(TaskService.generateVirtualMeetingTask(theOpportunity, theEvent));
  145. }
  146. }
  147. }
  148. insert tasksToCreate;
  149. }
  150.  
  151. /**
  152. * @description Calculates Opportunity statuses for specified Opportunities
  153. */
  154. public static void calculateOpportunitiesStatuses(List<Opportunity> theOpportunities) {
  155. Set<Id> automatedStatusCalculationRecordTypes = new Set<Id>{
  156. CONVENTIONAL_RECORD_TYPE_ID, SERVICED_RECORD_TYPE_ID, VIRTUAL_RECORD_TYPE_ID
  157. };
  158. for (Opportunity theOpportunity : theOpportunities) {
  159. if (automatedStatusCalculationRecordTypes.contains(theOpportunity.RecordTypeId)) {
  160. theOpportunity.StageName = OppStatusCalculatorFactory.getStatusCalculator(theOpportunity.RecordTypeId).calculateNewStatus(theOpportunity);
  161. theOpportunity.Automated_Status_Change__c = true;
  162. }
  163. }
  164. }
  165.  
  166. public static Map<Id, List<Opportunity>> getOpportunitiesMapByRecordTypeId(List<Opportunity> theOpportunities) {
  167. Map<Id, List<Opportunity>> opportunitiesMap = new Map<Id, List<Opportunity>>();
  168. for (Opportunity theOpportunity : theOpportunities) {
  169. if (!opportunitiesMap.containsKey(theOpportunity.RecordTypeId)) {
  170. opportunitiesMap.put(theOpportunity.RecordTypeId, new List<Opportunity>());
  171. }
  172. opportunitiesMap.get(theOpportunity.RecordTypeId).add(theOpportunity);
  173. }
  174. return opportunitiesMap;
  175. }
  176.  
  177. public static Map<String, SBQQ__Quote__c> getAcceptedQuotesByOpportunities(List<Opportunity> opportunities) {
  178. Map<String, SBQQ__Quote__c> opportunityAcceptedQuoteMap = new Map<String, SBQQ__Quote__c>();
  179.  
  180. List<SBQQ__Quote__c> acceptedQuotes = [
  181. SELECT Id, SBQQ__Opportunity2__c, Inventory__r.Name, Inventory__c, Net_Fill_Sq_ft__c,
  182. Total_deal_size_Sq_ft__c, Discount_Term_Certain_Percent__c,
  183. Discount_Term_Certain__c, Total_Parking_Spaces__c, Term__c,
  184. Term_Certain__c, Rent_per_Sq_Ft_annual__c, Property_Name__c,
  185. toLabel(SBQQ__Type__c), Total_deal_size_Workstations__c, Net_Fill_Workstations__c,
  186. Deposit_Payment_Total__c, Average_Workstation_Rate__c, Rent_Per_Workstation__c, Account_Name__c,
  187. Net_Subtotal__c, Serviced_Retail_Cost_Per_Week__c, Contract__c
  188. FROM SBQQ__Quote__c
  189. WHERE SBQQ__Status__c = :SBQQ_QuoteConstants.STATUS_ACCEPTED
  190. AND SBQQ__Opportunity2__c IN :opportunities
  191. ];
  192.  
  193. for (SBQQ__Quote__c theQuote : acceptedQuotes) {
  194. opportunityAcceptedQuoteMap.put(theQuote.SBQQ__Opportunity2__c, theQuote);
  195. }
  196.  
  197. return opportunityAcceptedQuoteMap;
  198. }
  199.  
  200. public static void updateOpportunityStage(List<Opportunity> opportunities, String stage) {
  201. for (Opportunity opp : opportunities) {
  202. opp.StageName = stage;
  203. }
  204.  
  205. update opportunities;
  206. }
  207.  
  208. public static void pushCompletionNotifications(List<Opportunity> opportunities) {
  209. // get all primary quotes related to Opportunity
  210. Map<String, SBQQ__Quote__c> opportunityToQuote = OpportunityService.getAcceptedQuotesByOpportunities(opportunities);
  211. // filter just Serviced, because we have to work with QLI later for serviced message
  212. Set<SBQQ__Quote__c> servicedQuotes = new Set<SBQQ__Quote__c>();
  213. for (Opportunity theOpportunity : opportunities) {
  214. if (theOpportunity.RecordTypeId == SERVICED_RECORD_TYPE_ID && opportunityToQuote.containsKey(theOpportunity.Id)) {
  215. servicedQuotes.add(opportunityToQuote.get(theOpportunity.Id));
  216. }
  217. }
  218.  
  219. // get all QLIs for Serviced opportunities
  220. Map<Id, List<SBQQ__QuoteLine__c>> servicedQuoteLines = SBQQ_QuoteService.getQuoteLinesMap(new List<SBQQ__Quote__c>(servicedQuotes));
  221.  
  222. List<String> feedItemsBodies = new List<String>();
  223. for (Opportunity theOpportunity : opportunities) {
  224. SBQQ__Quote__c quote = opportunityToQuote.get(theOpportunity.Id);
  225.  
  226. if (quote != null) {
  227. String message = '';
  228.  
  229. if (theOpportunity.RecordTypeId == SERVICED_RECORD_TYPE_ID) {
  230. List<SBQQ__QuoteLine__c> quoteLines = servicedQuoteLines.get(quote.Id) != null
  231. ? servicedQuoteLines.get(quote.Id)
  232. : new List<SBQQ__QuoteLine__c>();
  233. if (theOpportunity.Product__c == RETAIL_PRODUCT) {
  234. message = OpportunityService.getServicedRetailNotificationMessageText(theOpportunity, quote, quoteLines);
  235. } else {
  236. message = OpportunityService.getServicedNotificationMessageText(theOpportunity, quote, quoteLines);
  237. }
  238. } else {
  239. message = OpportunityService.getNotificationMessageText(theOpportunity, quote);
  240. }
  241.  
  242. feedItemsBodies.add(message);
  243. }
  244. }
  245.  
  246. ChatterService.pushFeedItems(feedItemsBodies, ChatterService.findChatterGroupByName(Constants.OPPORTUNITY_NOTIFICATION_GROUP_NAME));
  247. }
  248.  
  249. private static String getNotificationMessageText(Opportunity theOpportunity, SBQQ__Quote__c quote) {
  250. String opportunityUrl = URL.getSalesforceBaseUrl().toExternalForm() + '/' + theOpportunity.Id;
  251. String quoteUrl = quote != null ? URL.getSalesforceBaseUrl().toExternalForm() + '/' + quote.Id : '';
  252. String contractUrl = quote.Contract__c != null ? URL.getSalesforceBaseUrl().toExternalForm() + '/' + quote.Contract__c : null;
  253.  
  254. return '<p>' + (theOpportunity.Completion_Notification__c != null
  255. ? theOpportunity.Completion_Notification__c + '</p>'
  256. : 'I am pleased to announce the deal to ' + theOpportunity.Account.Name + ' at ' + quote.Property_Name__c + ' has now ' + theOpportunity.StageName + '.</p><p> Further details below:</p>')
  257. + '<p>&nbsp;</p>' +
  258. +'<p> <b>Opportunity Owner:</b> ' + theOpportunity.Owner.Name + '</p>' +
  259. +'<p> <b>Customer:</b> ' + StringUtils.convertNullToEmptySpace(quote.Account_Name__c) + '</p>' +
  260. +'<p> <b>Property:</b> ' + StringUtils.convertNullToEmptySpace(quote.Property_Name__c) + '</p>' +
  261. +'<p> <b>Inventory:</b> ' + StringUtils.convertNullToEmptySpace(quote.Inventory__r.Name) + '</p>' +
  262. +'<p> <b>Lead Source:</b> ' + StringUtils.convertNullToEmptySpace(theOpportunity.LeadSource) + '</p>' +
  263. +'<p> <b>Net Fill:</b> ' + NumberUtils.convertDecimalToNumberWithPrecision(quote.Net_Fill_Sq_ft__c, 0) + ' sq ft</p>' +
  264. +'<p> <b>Total Deal Size:</b> ' + NumberUtils.convertDecimalToNumberWithPrecision(quote.Total_deal_size_Sq_ft__c, 0) + ' sq ft</p>' +
  265. +'<p> <b>Deal Type:</b> ' + StringUtils.convertNullToEmptySpace(theOpportunity.Type) + '</p>' +
  266. +'<p> <b>Term (Months):</b> ' + NumberUtils.convertDecimalToNumber(quote.Term__c) + '</p>'
  267. + '<p> <b>Term Certain (Months):</b> ' + NumberUtils.convertDecimalToNumber(quote.Term_Certain__c) + '</p>' +
  268. +'<p> <b>Rent per sq ft:</b> ' + NumberUtils.convertCurrencyIntoString(quote.Rent_per_Sq_Ft_annual__c) + '</p>' +
  269. +'<p> <b>Discount Term Certain:</b> ' + NumberUtils.convertDecimalToNumber(quote.Discount_Term_Certain_Percent__c.setScale(2)) + '%</p>' +
  270. +'<p> <b>Total parking spaces:</b> ' + NumberUtils.convertDecimalToNumberWithPrecision(quote.Total_Parking_Spaces__c, 0) + '</p>' +
  271. +'<p>&nbsp;</p>' +
  272. +'<p> <b>Opportunity:</b> ' + opportunityUrl + '</p>' +
  273. +'<p> <b>Quote:</b> ' + quoteUrl + '</p>' +
  274. +(contractUrl != null ? '<p><b>Contract:</b> ' + contractUrl + '</p>' : '');
  275. }
  276.  
  277. private static String getServicedNotificationMessageText(Opportunity theOpportunity, SBQQ__Quote__c quote, List<SBQQ__QuoteLine__c> quoteLines) {
  278. String contractUrl = theOpportunity.ContractId != null ? URL.getSalesforceBaseUrl().toExternalForm() + '/' + theOpportunity.ContractId : null;
  279. List<String> msg = new List<String>();
  280. msg.add('<p>' + (theOpportunity.Completion_Notification__c != null
  281. ? theOpportunity.Completion_Notification__c
  282. : 'I am pleased to announce the deal to ' + theOpportunity.Account.Name + ' at ' + quote.Property_Name__c + ' has now ' + theOpportunity.StageName + '.</p><p> Further details below:') + '</p>');
  283. msg.add('<p>&nbsp;</p>');
  284. msg.add('<p> <b>Opportunity Owner:</b> ' + theOpportunity.Owner.Name + '</p>');
  285. msg.add('<p><b>Customer:</b> ' + StringUtils.convertNullToEmptySpace(quote.Account_Name__c) + '</p>');
  286. msg.add('<p><b>Property:</b> ' + StringUtils.convertNullToEmptySpace(quote.Property_Name__c) + '</p>');
  287. msg.add('<p><b>Inventory:</b> ' + StringUtils.convertNullToEmptySpace(quote.Inventory__r.Name) + '</p>');
  288. msg.add('<p><b>Deal Type:</b> ' + StringUtils.convertNullToEmptySpace(quote.SBQQ__Type__c) + '</p>');
  289. msg.add('<p><b>Number of workstations:</b> ' + NumberUtils.convertDecimalToNumberWithPrecision(quote.Total_deal_size_Workstations__c, 0) + '</p>');
  290. msg.add('<p><b>Net Fill Workstations:</b> ' + NumberUtils.convertDecimalToNumberWithPrecision(quote.Net_Fill_Workstations__c, 0) + '</p>');
  291.  
  292. SBQQ__QuoteLine__c headLine;
  293. SBQQ__QuoteLine__c depositLine;
  294. SBQQ__QuoteLine__c internetLine;
  295. SBQQ__QuoteLine__c handSetLine;
  296.  
  297. for (SBQQ__QuoteLine__c qLine : quoteLines) {
  298. if (ProductService.isServicedOrDeskHeadline(qLine.SBQQ__ProductCode__c)) {
  299. headLine = qLine;
  300. }
  301. if (qLine.SBQQ__ProductCode__c == ProductService.PRODUCT_CODE_DEPOSIT) {
  302. depositLine = qLine;
  303. }
  304. if (qLine.SBQQ__ProductCode__c == ProductService.PRODUCT_CODE_INCLUSIVE_INTERNET
  305. || qLine.SBQQ__ProductCode__c.startsWith('BSDM')) {
  306. internetLine = qLine;
  307. }
  308. if (qLine.SBQQ__ProductCode__c == ProductService.PRODUCT_CODE_HANDSETS
  309. || qLine.SBQQ__ProductCode__c == ProductService.PRODUCT_CODE_HANDSETS_INCLUSIVE) {
  310. handSetLine = qLine;
  311. }
  312. }
  313.  
  314. msg.add('<p><b>Headline Monthly Rent:</b> ' + NumberUtils.convertCurrencyIntoString(quote.Rent_Per_Workstation__c) + '</p>');
  315. msg.add('<p><b>Average Workstation Rate (PCM):</b> ' + NumberUtils.convertCurrencyIntoString(quote.Average_Workstation_Rate__c) + '</p>');
  316. msg.add(
  317. '<p><b>Start Date:</b> ' +
  318. (headLine != null && headLine.Start_Date__c != null ? headLine.Start_Date__c.format() : '') +
  319. '</p>'
  320. );
  321.  
  322. msg.add('<p><b>Term (Months):</b> ' + NumberUtils.convertDecimalToNumber(headLine.Term__c) + '</p>');
  323. msg.add('<p><b>Deposit:</b> ' + NumberUtils.convertCurrencyIntoString(depositLine.Net_Subtotal__c) + '</p>');
  324. msg.add('<p><b>Deposit Already Held:</b> ' + NumberUtils.convertCurrencyIntoString(depositLine.Deposit_Already_Held__c) + '</p>');
  325. msg.add(
  326. '<p><b>Internet Product Name:</b> '
  327. + (internetLine != null && internetLine.SBQQ__Product__c != null ? internetLine.SBQQ__Product__r.Name : '')
  328. + '</p>'
  329. );
  330.  
  331. msg.add(
  332. '<p><b>Number of Telephone Handsets:</b> '
  333. + (handSetLine != null && handSetLine.SBQQ__Quantity__c != null ? handSetLine.SBQQ__Quantity__c.format() : '0')
  334. + '</p>'
  335. );
  336. msg.add('<p><b>Number of Parking within Licence Agreement:</b> '
  337. + NumberUtils.convertDecimalToNumberWithPrecision(quote.Total_Parking_Spaces__c, 0) + '</p>');
  338.  
  339. msg.add('<p><b>Total Deal Value:</b> ' + NumberUtils.convertCurrencyIntoString(headLine.Net_Total__c) + '</p>');
  340. msg.add('<p>&nbsp;</p>');
  341. msg.add('<p><b>Opportunity:</b> ' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + theOpportunity.Id + '</p>');
  342. msg.add('<p><b>Quote:</b> ' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + quote.Id + '</p>');
  343. msg.add(contractUrl != null ? '<p><b>Contract:</b> ' + contractUrl + '</p>' : '');
  344.  
  345. return String.join(msg, '');
  346. }
  347.  
  348. private static String getServicedRetailNotificationMessageText(Opportunity theOpportunity, SBQQ__Quote__c quote, List<SBQQ__QuoteLine__c> quoteLines) {
  349. List<String> msg = new List<String>();
  350.  
  351. SBQQ__QuoteLine__c headLine;
  352. SBQQ__QuoteLine__c depositLine;
  353.  
  354. for (SBQQ__QuoteLine__c qLine : quoteLines) {
  355. if (ProductService.isServicedOrDeskHeadline(qLine.SBQQ__ProductCode__c)) {
  356. headLine = qLine;
  357. }
  358. if (qLine.SBQQ__ProductCode__c == ProductService.PRODUCT_CODE_DEPOSIT) {
  359. depositLine = qLine;
  360. }
  361. }
  362.  
  363. msg.add('<p>' + theOpportunity.Completion_Notification__c + '</p>');
  364. msg.add('<p>&nbsp;</p>');
  365. msg.add('<p> <b>Opportunity Owner: </b>' + theOpportunity.Owner.Name + '</p>');
  366. msg.add('<p> <b>Customer: </b>' + StringUtils.convertNullToEmptySpace(quote.Account_Name__c) + '</p>');
  367. msg.add('<p> <b>Property: </b>' + StringUtils.convertNullToEmptySpace(quote.Property_Name__c) + '</p>');
  368. msg.add('<p> <b>Inventory: </b> ' + StringUtils.convertNullToEmptySpace(quote.Inventory__r.Name) + '</p>');
  369. msg.add('<p> <b>Lead Source: </b>' + StringUtils.convertNullToEmptySpace(theOpportunity.LeadSource) + '</p>');
  370. msg.add('<p> <b>Net Fill: </b>' + NumberUtils.convertDecimalToNumberWithPrecision(quote.Net_Fill_Sq_ft__c, 0) + ' sq ft</p>');
  371. msg.add('<p> <b>Total Deal Size: </b>' + NumberUtils.convertDecimalToNumberWithPrecision(quote.Total_deal_size_Sq_ft__c, 0) + ' sq ft</p>');
  372. msg.add('<p> <b>Deal Type: </b>' + StringUtils.convertNullToEmptySpace(theOpportunity.Type) + '</p>');
  373. msg.add('<p> <b>Headline Weekly Rent: </b>' + NumberUtils.convertCurrencyIntoString(quote.Serviced_Retail_Cost_Per_Week__c) + '</p>');
  374. msg.add('<p> <b>Start Date: </b>' + headLine.Start_Date__c.format() + '</p>');
  375. msg.add('<p> <b>Term (Months): </b>' + NumberUtils.convertDecimalToNumber(quote.Term__c) + '</p>');
  376. msg.add('<p> <b>Deposit: </b>' + NumberUtils.convertCurrencyIntoString(depositLine.Net_Subtotal__c) + '</p>');
  377. msg.add('<p> <b>Deposit Already Held: </b>' + NumberUtils.convertCurrencyIntoString(depositLine.Deposit_Already_Held__c) + '</p>');
  378. msg.add('<p> <b>Total Deal Value: </b>' + NumberUtils.convertCurrencyIntoString(headLine.Net_Total__c) + '</p>');
  379.  
  380. return String.join(msg, '');
  381. }
  382.  
  383. public static Opportunity getOpportunityWithAllFieldsExceptNotValidById(String opportunityId, List<String> fieldsNotNeedToSelect) {
  384. List<String> opportunityFieldsForSelect = new List<String>();
  385. Map<String, SObjectField> opportunityFieldsMap = Opportunity.SObjectType.getDescribe().fields.getMap();
  386. for (SObjectField field : opportunityFieldsMap.values()) {
  387. DescribeFieldResult describeFieldResult = field.getDescribe();
  388. if (describeFieldResult.accessible &&
  389. !fieldsNotNeedToSelect.contains(describeFieldResult.name)) {
  390. opportunityFieldsForSelect.add(describeFieldResult.name);
  391. }
  392. }
  393. Opportunity clonedOpportunity = getOpportunityWithSelectedFieldsById(opportunityId, opportunityFieldsForSelect).clone(false, false);
  394. return clonedOpportunity;
  395. }
  396.  
  397. private static Opportunity getOpportunityWithSelectedFieldsById(String opportunityId, List<String> selectedFields) {
  398. String soqlGetAllFieldsFromOpportunity = ''
  399. + ' SELECT ' + String.join(selectedFields, ', ')
  400. + ' FROM Opportunity'
  401. + ' WHERE Id = \'' + opportunityId + '\'';
  402.  
  403. List<Opportunity> opportunities = Database.query(soqlGetAllFieldsFromOpportunity);
  404. if (opportunities.size() != 0) {
  405. return opportunities.get(0);
  406. }
  407. return null;
  408. }
  409. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement