Guest User

Untitled

a guest
Jun 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.51 KB | None | 0 0
  1. public with sharing class ResendEmailCaseController {
  2. // account and selection set/variables
  3. private List<CaseSubClass> CaseSubClassList {get; set;}
  4. private Set<Id> caseSelectedSet;
  5. public Integer caseSelectedCount {get; set;}
  6. public String selectedOneCase {get; set;}
  7. // selection and filter
  8. public List<String> alphaList {get; set;}
  9. public String alphaFilter {get; set;}
  10. public String searchName {get; set;}
  11. public String searchBillingAddress {get; set;}
  12. private String saveSearchName;
  13. private String saveSearchBillingAddress;
  14. private String queryCase;
  15. public String emailCaseList {get;set;}
  16. // display sort and number
  17. public String recPerPage {get; set;}
  18. public List<SelectOption> recPerPageOption{get; set;}
  19. public String sortFieldSave;
  20. public String allString {get;set;}
  21. public List <Email_History__c> listeh = new List <Email_History__c> ();
  22.  
  23. private static final String DEFAULT_REC_PER_PAGE = '10';
  24.  
  25. /***
  26. * TableExampleController - Constructor initialization
  27. ***/
  28. public ResendEmailCaseController(){
  29. CaseSubClassList = new List<CaseSubClass>();
  30. caseSelectedSet = new Set<Id>();
  31.  
  32. //records for page initialization
  33. recPerPageOption = new list<SelectOption>();
  34. recPerPageOption.add(new SelectOption('10','10'));
  35. recPerPageOption.add(new SelectOption('25','25'));
  36. recPerPageOption.add(new SelectOption('50','50'));
  37. recPerPageOption.add(new SelectOption('100','100'));
  38. recPerPageOption.add(new SelectOption('200','200'));
  39. recPerPage = DEFAULT_REC_PER_PAGE; //default records per page
  40.  
  41. // initialization alpha list
  42. alphaList = new List<String> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'};
  43. sortFieldSave = sortField;
  44.  
  45. // alpha filter, use page parameter or set default to all
  46. if (ApexPages.currentPage().getParameters().get('alpha') == null) {
  47. alphaFilter = 'All';
  48. } else {
  49. alphaFilter = ApexPages.currentPage().getParameters().get('alpha');
  50. }
  51.  
  52. // list generation
  53. buildQuery();
  54. }
  55.  
  56. /***
  57. * StdSetControllerAccount - paging through the Account list
  58. ***/
  59. public ApexPages.StandardSetController StdSetControllerCase {
  60. get {
  61. if(StdSetControllerCase == null) {
  62. StdSetControllerCase = new ApexPages.StandardSetController(Database.getQueryLocator(queryCase));
  63. // sets the number of records in each page set
  64. StdSetControllerCase.setPageSize(Integer.valueOf(recPerPage));
  65. }
  66. return StdSetControllerCase;
  67. }
  68. set;
  69. }
  70.  
  71. /***
  72. * getCurrentInvoiceList - return an Account list for the table
  73. ***/
  74. public List<CaseSubClass> getCurrentInvoiceList() {
  75. updatecaseSelectedSet();
  76.  
  77. CaseSubClassList = new List<CaseSubClass>();
  78. **for (Case a : (List<Case>)StdSetControllerCase.getRecords()) { //.deepClone(true)**
  79. CaseSubClassList.add(new CaseSubClass(a, caseSelectedSet.contains(a.Id)));
  80. }
  81. return CaseSubClassList;
  82. }
  83.  
  84. /***
  85. * updatecaseSelectedSet - add/remove accounts from the selected account id list
  86. ***/
  87. public void updatecaseSelectedSet(){
  88. for (CaseSubClass CaseSubClassObj : CaseSubClassList) {
  89. if (CaseSubClassObj.aCheckBox == true) {
  90. caseSelectedSet.add(CaseSubClassObj.aCase.Id);
  91. List<String> arrayemail2 = new List<String>();
  92. List<Case> emaillist = [SELECT Id, AccountId, Account.Primary_Email_Address__c, Account.Secondary_Email_Address_1__c, Account.Secondary_Email_Address_2__c, address_List__c FROM Case WHERE Id = :CaseSubClassObj.aCase.Id];
  93. List<Contact> conlist2 = [SELECT Id, Email, Secondary_Email_1__c, Secondary_Email_2__c FROM Contact WHERE AccountId = :emaillist[0].AccountId];
  94. if (conlist2.size() > 0) {
  95. for (Contact c : conlist2) {
  96. if (String.isNotBlank(c.email)) {
  97. arrayemail2.add(c.email);
  98. }
  99. if (String.isNotBlank(c.Secondary_Email_1__c)) {
  100. arrayemail2.add(c.Secondary_Email_1__c);
  101. }
  102. if (String.isNotBlank(c.Secondary_Email_2__c)) {
  103. arrayemail2.add(c.Secondary_Email_2__c);
  104. }
  105. }
  106. }
  107. if (emaillist[0].Account.Primary_Email_Address__c!=null) {
  108. arrayemail2.add(emaillist[0].Account.Primary_Email_Address__c);
  109. }
  110. if (emaillist[0].Account.Secondary_Email_Address_1__c!=null) {
  111. arrayemail2.add(emaillist[0].Account.Secondary_Email_Address_1__c);
  112. }
  113. if (emaillist[0].Account.Secondary_Email_Address_2__c!=null) {
  114. arrayemail2.add(emaillist[0].Account.Secondary_Email_Address_2__c);
  115. }
  116. allString = String.join(arrayemail2,';');
  117. emailCaseList = allString;
  118. CaseSubClassObj.aCase.Address_List__c = 'allstring';
  119. }
  120. else {
  121. if (caseSelectedSet.contains(CaseSubClassObj.aCase.Id)) {
  122. caseSelectedSet.remove(CaseSubClassObj.aCase.Id);
  123. emailCaseList = '';
  124. CaseSubClassObj.aCase.Address_List__c = '';
  125. }
  126. }
  127. }
  128. caseSelectedCount = caseSelectedSet.size();
  129. }
  130.  
  131. /***
  132. * ClearcaseSelectedSet - remove selected accounts and initialize counter
  133. ***/
  134. public PageReference clearAll(){
  135. CaseSubClassList.clear();
  136. caseSelectedSet.clear();
  137. caseSelectedCount = 0;
  138. searchName = '';
  139. searchBillingAddress = '';
  140. saveSearchName = '';
  141. saveSearchBillingAddress = '';
  142. alphaFilter = 'All';
  143.  
  144. buildQuery();
  145.  
  146. return null;
  147. }
  148.  
  149. /***
  150. * searchAccount - set search criteria fields and refresh Account table
  151. ***/
  152. public PageReference searchAccount() {
  153. saveSearchName = searchName;
  154. saveSearchBillingAddress = searchBillingAddress;
  155.  
  156. buildQuery();
  157.  
  158. return null;
  159. }
  160.  
  161. /***
  162. * BuildQuery - build query command for list selection change
  163. ***/
  164. public void buildQuery() {
  165. StdSetControllerCase = null;
  166. String queryWhere = '';
  167. String Green='Green';
  168.  
  169. if (alphaFilter == null || alphaFilter.trim().length() == 0) {
  170. alphaFilter = 'All';
  171. }
  172.  
  173. queryCase = 'SELECT Id, CaseNumber, Account.name, Priority, Status, Invoice_No__c, Priority_Number__c, Latest_Collection_Log_Status__c, Address_List__c ' +
  174. ' FROM Case';
  175.  
  176. if (alphaFilter == 'Other') {
  177. queryWhere = buildWhere(queryWhere, '(' + String.escapeSingleQuotes(sortField) + ' < 'A' OR ' +
  178. String.escapeSingleQuotes(sortField) + ' > 'Z') AND (NOT ' +
  179. String.escapeSingleQuotes(sortField) + ' LIKE 'Z%') ');
  180. } else if (alphaFilter != 'All') {
  181. queryWhere = buildWhere(queryWhere, '(' + String.escapeSingleQuotes(sortField) + ' LIKE '' + String.escapeSingleQuotes(alphaFilter) + '%')' );
  182. }
  183.  
  184. if (saveSearchName != null) {
  185. queryWhere = buildWhere(queryWhere, ' (CaseNumber LIKE '%' + String.escapeSingleQuotes(saveSearchName) + '%')');
  186. }
  187. if (saveSearchBillingAddress != null) {
  188. queryWhere = buildWhere(queryWhere, '(Account.name LIKE '%' + String.escapeSingleQuotes(saveSearchBillingAddress) + '%')');
  189. }
  190. if (saveSearchName != null || saveSearchBillingAddress != null || saveSearchName == null || saveSearchBillingAddress == null) {
  191. queryWhere = buildWhere(queryWhere, '(Invoice_Indicator__c = ''+ Green + '')') ;
  192. }
  193.  
  194. queryCase += queryWhere;
  195. queryCase += ' ORDER BY ' + String.escapeSingleQuotes(sortField) + ' ' + String.escapeSingleQuotes(sortDirection) + ' LIMIT 10000';
  196.  
  197. System.debug(LoggingLevel.DEBUG, '***queryCase:' + JSON.serializePretty(queryCase));
  198. }
  199.  
  200. /***
  201. * BuildWhere - build soql string for where criteria
  202. ***/
  203. public String buildWhere(String QW, String Cond) {
  204. if (QW == '') {
  205. return ' WHERE ' + Cond;
  206. } else {
  207. return QW + ' AND ' + Cond;
  208. }
  209. }
  210.  
  211. /***
  212. * SortDirection - return sort direction. Default ascending(asc)
  213. ***/
  214. public String sortDirection {
  215. get { if (sortDirection == null) { sortDirection = 'asc'; } return sortDirection; }
  216. set;
  217. }
  218.  
  219. /***
  220. * SortField - return sort by field. Default to Name
  221. ***/
  222. public String sortField {
  223. get { if (sortField == null) {sortField = 'CaseNumber'; } return sortField; }
  224. set;
  225. }
  226.  
  227. /***
  228. * SortToggle - toggles the sorting of query from asc<-->desc
  229. ***/
  230. public void sortToggle() {
  231. sortDirection = sortDirection.equals('asc') ? 'desc NULLS LAST' : 'asc';
  232. // reset alpha filter and sort sequence when sorted field is changed
  233. if (sortFieldSave != sortField) {
  234. sortDirection = 'asc';
  235. alphaFilter = 'All';
  236. sortFieldSave = sortField;
  237. }
  238. // run the query again
  239. buildQuery();
  240. }
  241.  
  242. /***
  243. * DoSomethingOne - do something with one selected account
  244. ***/
  245. public PageReference doSomethingOne() {
  246. System.debug(LoggingLevel.DEBUG, '***selectedOneCase: ' + selectedOneCase);
  247. return null;
  248. }
  249.  
  250. /***
  251. * DoSomethingMany - do something with many selected accounts
  252. ***/
  253. public PageReference doSomethingMany() {
  254. System.debug(LoggingLevel.DEBUG, '***caseSelectedSet.size(): ' + caseSelectedSet.size());
  255.  
  256. for (Id CaseId : caseSelectedSet) {
  257. List<Case> invlist = [SELECT Id, Invoice__c, Account.preferredLanguage__c FROM Case WHERE Id = :CaseId];
  258. List<String> arrayemail = allString.split(';');
  259. System.debug(LoggingLevel.DEBUG, '***invlist: ' + JSON.serializePretty(invlist));
  260. System.debug('***Email Invoice :'+ allString);
  261. System.debug('*****Array Email :'+ arrayemail);
  262. System.debug('***Array Email :'+ JSON.serializePretty(arrayemail));
  263.  
  264. List<Id> ids= new List<Id>();
  265. for(Case inv2:invlist) {
  266. for (Integer i=0; i<arrayemail.size(); i++ ) {
  267. Email_History__c eh = new Email_History__c();
  268. eh.id__c = inv2.id;
  269. eh.Invoice__c = inv2.Invoice__c;
  270. eh.case__c = inv2.id;
  271. eh.Email__c = arrayemail[i];
  272. eh.Preffered_Currency__c = inv2.Account.preferredLanguage__c;
  273. listeh.add(eh);
  274. system.debug('Array : '+arrayemail[i]);
  275. }
  276. }
  277. if(listeh.size()>0) insert listeh;
  278. system.debug('Checked: ' + CaseId);
  279. }
  280. return null;
  281. }
  282.  
  283. /***
  284. * CaseSubClass - Sub-Class to hold Account and checkbox for the table
  285. ***/
  286. public class CaseSubClass {
  287. public Boolean aCheckBox {get;set;}
  288. public Case aCase {get;set;}
  289.  
  290. // sub-class initialization
  291. public CaseSubClass(Case a, Boolean chk){
  292. aCase = a;
  293. aCheckBox = chk;
  294. }
  295. }
  296. }
  297.  
  298. <apex:page controller="ResendEmailCaseController"
  299. lightningStylesheets="true">
  300. <script>
  301. function updateMessage(){
  302. alert('Successfully resend email');
  303. }
  304. </script>
  305. <apex:form id="TheForm">
  306. <!-- ***************************** -->
  307. <!-- Search Criteria -->
  308. <apex:pageBlock mode="maindetail">
  309. <div class="search-block">
  310. <div style="display: inline-table">
  311. <span>Case No:</span>
  312. <apex:inputText value="{!searchName}" />
  313. </div>
  314. <div style="display: inline-table">
  315. <span>Hotel Name:</span>
  316. <apex:inputText value="{!searchBillingAddress}" />
  317. </div>
  318. <apex:commandButton styleClass="search-block-button" value="Search" action="{!searchAccount}" rerender="TablePanel"
  319. status="TableUpdateStatus" />
  320. <apex:actionStatus id="ProcessButtonStatus">
  321. <apex:facet name="stop">
  322. <apex:outputPanel >
  323. <apex:commandButton styleClass="process-block-button" value="Resend Email" action="{!doSomethingMany}"
  324. status="ProcessButtonStatus" rerender="nothing" oncomplete="updateMessage();"/>
  325. <apex:commandButton styleClass="process-block-button" value="Clear All" action="{!ClearAll}"
  326. rerender="TheForm,TablePanel" />
  327. </apex:outputPanel>
  328. </apex:facet>
  329. <apex:facet name="start">
  330. <apex:outputPanel >
  331. <apex:commandButton styleClass="process-block-button" value="Processing..." disabled="true" />
  332. <apex:commandButton styleClass="process-block-button" value="Processing..." disabled="true" />
  333. </apex:outputPanel>
  334. </apex:facet>
  335. </apex:actionStatus>
  336. </div>
  337.  
  338. <div class="process-block">
  339. <!-- <apex:actionStatus id="ProcessButtonStatus">
  340. <apex:facet name="stop">
  341. <apex:outputPanel >
  342. <apex:commandButton styleClass="process-block-button" value="Process Selected" action="{!DoSomethingMany}"
  343. status="ProcessButtonStatus" rerender="nothing" />
  344. <apex:commandButton styleClass="process-block-button" value="Clear All" action="{!ClearAll}"
  345. rerender="TheForm,TablePanel" />
  346. </apex:outputPanel>
  347. </apex:facet>
  348. <apex:facet name="start">
  349. <apex:outputPanel >
  350. <apex:commandButton styleClass="process-block-button" value="Processing..." disabled="true" />
  351. <apex:commandButton styleClass="process-block-button" value="Processing..." disabled="true" />
  352. </apex:outputPanel>
  353. </apex:facet>
  354. </apex:actionStatus> -->
  355. </div>
  356. </apex:pageBlock>
  357.  
  358. <!-- ************************* -->
  359. <!-- search results table -->
  360. <apex:pageBlock id="TablePanel">
  361. <div>
  362. <span class="page-buttons" style="float: left; margin-bottom: 5px;"> <apex:commandButton disabled="{!!StdSetControllerCase.hasprevious}" value="Previous" action="{!StdSetControllerCase.previous}"
  363. rerender="TablePanel" /> <apex:commandButton disabled="{!!StdSetControllerCase.hasnext}" value="Next"
  364. action="{!StdSetControllerCase.next}" rerender="TablePanel" />
  365. </span>
  366. <!-- alphabet selection -->
  367. <span style="float: right; margin: 5px 5px 5px 5px;"> <apex:repeat value="{!AlphaList}" var="a">
  368. <apex:commandLink value="{!a}" action="{!BuildQuery}" rerender="TablePanel"
  369. styleClass="alpha-link{!if(AlphaFilter=a,' alpha-select','')}" status="TableUpdateStatus">
  370. <apex:param name="AlphaFilter" value="{!a}" assignTo="{!AlphaFilter}" />
  371. </apex:commandLink>
  372. </apex:repeat>
  373. </span>
  374. </div>
  375.  
  376. <div style="clear: both;"></div>
  377.  
  378. <apex:actionStatus id="TableUpdateStatus">
  379. <apex:inputHidden value="{!AlphaFilter}" id="hiddenField" />
  380. <!-- loading message -->
  381. <apex:facet name="start">
  382. <apex:outputPanel layout="block" styleClass="message infoM4">
  383. <apex:panelGrid columns="2" styleClass="messageTable" columnClasses="messageCell" style="padding:0px;margin:0px;">
  384. <apex:panelGroup >
  385. <img class="loading-icon" src="/s.gif" />
  386. </apex:panelGroup>
  387. <apex:panelGroup >
  388. <div class="messageText">Please wait...</div>
  389. </apex:panelGroup>
  390. </apex:panelGrid>
  391. </apex:outputPanel>
  392. </apex:facet>
  393.  
  394. <!-- Account table -->
  395. <apex:facet name="stop">
  396. <apex:pageBlockTable value="{!CurrentInvoiceList}" var="a" id="TheBlock">
  397. <!-- <apex:column >
  398. <apex:commandLink styleClass="alpha-link" action="{!DoSomethingOne}">
  399. <apex:param value="{!a.aInvoice.Id}" assignTo="{!SelectedOneAccount}" />Select</apex:commandLink>
  400. </apex:column> -->
  401. <apex:column >
  402. <apex:facet name="header">
  403. <apex:outputPanel id="SelectedCount">
  404. <div style="text-align: center;">
  405. <apex:outputText value="Selected" />
  406. <br />
  407. <apex:outputText value="{!CaseSelectedCount}" />
  408. </div>
  409. </apex:outputPanel>
  410. </apex:facet>
  411. <div style="text-align: center;">
  412. <apex:inputCheckBox value="{!a.aCheckBox}" id="check-box">
  413. <apex:actionSupport event="onchange" rerender="SelectedCount,outputID" action="{!UpdateCaseSelectedSet}" />
  414. </apex:inputcheckbox>
  415. </div>
  416. </apex:column>
  417. <apex:column >
  418. <apex:facet name="header">
  419. <apex:commandLink action="{!SortToggle}" rerender="TablePanel" status="TableUpdateStatus">
  420. <apex:param name="SortField" value="casenumber" assignTo="{!SortField}" />
  421. <apex:outputText value="{!$ObjectType.case.Fields.casenumber.Label}{!IF(SortField=='casenumber',IF(SortDirection='asc','▲','▼'),'')}" />
  422. </apex:commandLink>
  423. </apex:facet>
  424. <apex:outputLink value="/{!a.aCase.Id}" target="_blank">{!a.acase.casenumber}</apex:outputlink>
  425. </apex:column>
  426. <apex:column >
  427. <apex:facet name="header">
  428. <apex:commandLink action="{!SortToggle}" rerender="TablePanel" status="TableUpdateStatus">
  429. <apex:param name="SortField" value="Account.name" assignTo="{!SortField}" />
  430. <apex:outputText value="{!$ObjectType.Case.Fields.Accountid.Label}{!IF(SortField=='Account.name',IF(SortDirection='asc','▲','▼'),'')}" />
  431. </apex:commandLink>
  432. </apex:facet>
  433. <apex:outputField value="{!a.aCase.Account.name}" />
  434. </apex:column>
  435. <apex:column >
  436. <apex:facet name="header">
  437. <apex:commandLink action="{!SortToggle}" rerender="TablePanel" status="TableUpdateStatus">
  438. <apex:param name="SortField" value="Status" assignTo="{!SortField}" />
  439. <apex:outputText value="{!$ObjectType.Case.Fields.Status.Label}{!IF(SortField=='Status',IF(SortDirection='asc','▲','▼'),'')}" />
  440. </apex:commandLink>
  441. </apex:facet>
  442. <apex:outputField value="{!a.aCase.Status}" />
  443. </apex:column>
  444. <apex:column >
  445. <apex:facet name="header">
  446. <apex:commandLink action="{!SortToggle}" rerender="TablePanel" status="TableUpdateStatus">
  447. <apex:param name="SortField" value="Priority" assignTo="{!SortField}" />
  448. <apex:outputText value="{!$ObjectType.Case.Fields.Priority.Label}{!IF(SortField=='Priority',IF(SortDirection='asc','▲','▼'),'')}" />
  449. </apex:commandLink>
  450. </apex:facet>
  451. <apex:outputField value="{!a.aCase.Priority}" />
  452. </apex:column>
  453. <apex:column >
  454. <apex:facet name="header">
  455. <apex:commandLink action="{!SortToggle}" rerender="TablePanel" status="TableUpdateStatus">
  456. <apex:param name="SortField" value="Invoice_No__c" assignTo="{!SortField}" />
  457. <apex:outputText value="{!$ObjectType.Case.Fields.Invoice_No__c.Label}{!IF(SortField=='Invoice_No__c',IF(SortDirection='asc','▲','▼'),'')}" />
  458. </apex:commandLink>
  459. </apex:facet>
  460. <apex:outputField value="{!a.aCase.Invoice_No__c}" />
  461. </apex:column>
  462. <apex:column >
  463. <apex:facet name="header">
  464. <apex:commandLink action="{!SortToggle}" rerender="TablePanel" status="TableUpdateStatus">
  465. <apex:param name="SortField" value="Priority_Number__c" assignTo="{!SortField}" />
  466. <apex:outputText value="{!$ObjectType.Case.Fields.Priority_Number__c.Label}{!IF(SortField=='Priority_Number__c',IF(SortDirection='asc','▲','▼'),'')}" />
  467. </apex:commandLink>
  468. </apex:facet>
  469. <apex:outputField value="{!a.aCase.Priority_Number__c}" />
  470. </apex:column>
  471. <apex:column >
  472. <apex:facet name="header">
  473. <apex:commandLink action="{!SortToggle}" rerender="TablePanel" status="TableUpdateStatus">
  474. <apex:param name="SortField" value="Latest_Collection_Log_Status__c" assignTo="{!SortField}" />
  475. <apex:outputText value="{!$ObjectType.Case.Fields.Latest_Collection_Log_Status__c.Label}{!IF(SortField=='Latest_Collection_Log_Status__c',IF(SortDirection='asc','▲','▼'),'')}" />
  476. </apex:commandLink>
  477. </apex:facet>
  478. <apex:outputField value="{!a.aCase.Latest_Collection_Log_Status__c}" />
  479. </apex:column>
  480. <apex:column >
  481. <apex:facet name="header">
  482. <apex:outputText value="Email" />
  483. </apex:facet>
  484. **<apex:inputTextarea value="{!a.aCase.Address_List__c}" id="outputID" rows="15" html-maxlength="1024" style="width: 80%;height: 15px;" />**
  485. <!-- <apex:inputTextarea value="{!a.aCase.Address_List__c}" id="outputID" rows="15" html-maxlength="1024" style="width: 80%;height: 15px;" /> -->
  486. </apex:column>
  487. </apex:pageBlockTable>
  488. </apex:facet>
  489. </apex:actionStatus>
  490. <div style="margin-top: 5px;">
  491. <apex:outputText value="Number of Records per Page: " />
  492. <apex:selectList value="{!RecPerPage}" size="1">
  493. <apex:selectOptions value="{!RecPerPageOption}" />
  494. <apex:actionSupport event="onchange" action="{!BuildQuery}" reRender="TablePanel" status="TableUpdateStatus" />
  495. </apex:selectList>
  496. </div>
  497. </apex:pageBlock>
  498. </apex:form>
  499.  
  500. </apex:page>
Add Comment
Please, Sign In to add comment