Advertisement
Guest User

Untitled

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