Advertisement
Guest User

Untitled

a guest
May 4th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. public with sharing class ScheduledEventMergeController {
  2.  
  3. public Intake__c thisIntake {get;set;}
  4. public Event thisEvent {get;set;}
  5. public Account thisAccount {get;set;}
  6. public Id relatedAccountId {get;set;}
  7. public Id relatedIntakeId {get;set;}
  8. public Id relatedEventId {
  9. get {
  10. return relatedEventId;
  11. }
  12. set {
  13. relatedEventId = value;
  14. thisEvent = queryEvent('Investigation_Sched_Investigator_Email_N');
  15.  
  16. Id relatedIntakeId = thisEvent.WhatId;
  17. thisIntake = queryIntake('Investigation_Sched_Investigator_Email_N');
  18.  
  19. // relatedAccountId = thisIntake.Client__c;
  20. // thisAccount = queryPerson('Investigation_Sched_Investigator_Email_N');
  21. }
  22. }
  23.  
  24. public ScheduledEventMergeController() {
  25.  
  26. }
  27.  
  28. public static List<FieldSetMember> readFieldSet(String fieldSetName, String ObjectName) {
  29. Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe();
  30. Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName);
  31. Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();
  32. Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName);
  33. return fieldSetObj.getFields();
  34. }
  35.  
  36. public Event queryEvent(String eventFieldSetName) {
  37. List<FieldSetMember> fieldSetMemberList = readFieldSet(eventFieldSetName, 'Event');
  38.  
  39. String query = 'SELECT ';
  40. for(Schema.FieldSetMember f : fieldSetMemberList) {
  41. query += f.getFieldPath() + ', ';
  42. }
  43. query += 'Id, WhatId from Event WHERE Id = ''+relatedEventId+'' LIMIT 1';
  44. try {
  45. List<Event> dummyEvent = Database.query(query);
  46. return dummyEvent[0];
  47. } catch (Exception e) {
  48. return null;
  49. }
  50. }
  51.  
  52. public Intake__c queryIntake(String intakeFieldSetName) {
  53. List<FieldSetMember> fieldSetMemberList = readFieldSet(intakeFieldSetName, 'Intake__c');
  54.  
  55. String query = 'SELECT ';
  56. for(Schema.FieldSetMember f : fieldSetMemberList) {
  57. query += f.getFieldPath() + ', ';
  58. }
  59. query += 'Id, client__c from Intake__c WHERE Id = ''+relatedIntakeId+'' LIMIT 1';
  60. try {
  61. List<Intake__c> dummyIntake = Database.query(query);
  62. return dummyIntake[0];
  63. } catch (Exception e) {
  64. //error
  65. return null;
  66. }
  67. }
  68.  
  69. public Account queryPerson(String accountFieldSetName) {
  70. List<FieldSetMember> fieldSetMemberList = readFieldSet(accountFieldSetName, 'Account');
  71.  
  72. String query = 'SELECT ';
  73. for(Schema.FieldSetMember f : fieldSetMemberList) {
  74. query += f.getFieldPath() + ', ';
  75. }
  76. query += 'Id from Account WHERE Id = ''+relatedAccountId+''';
  77. try {
  78. List<Account> dummyAccount = Database.query(query);
  79. return dummyAccount[0];
  80. } catch (Exception e) {
  81. // System.addError('There is error while Fetching existing Account using Dynamic SOQL in Field Set. Error Detail - '+e.getMessage());
  82. return null;
  83. }
  84.  
  85. }}
  86.  
  87. <apex:component controller="ScheduledEventMergeController" access="global">
  88. <apex:attribute name="theEvent" type="Id" description="the event id" assignTo="{!relatedEventId}" />
  89.  
  90.  
  91. <style type="text/css">
  92. .FS-table {border-collapse:collapse;border-spacing:0;}
  93. .FS-table td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
  94. </style>
  95.  
  96. <table class="FS-table">
  97. <apex:repeat value="{!$ObjectType.Event.FieldSets.Investigation_Sched_Investigator_Email_N}" var="fEvent">
  98. <tr>
  99. <td>
  100. <apex:outputText styleClass="bold" value="{!$ObjectType.Event.Fields[fEvent].label}" />
  101. </td>
  102. <td>
  103. <apex:outputField value="{!thisEvent[fEvent.fieldPath]}" />
  104. </td>
  105. </tr>
  106. </apex:repeat>
  107. </table>
  108. <br/>
  109. <h1><strong>Intake Details</strong></h1>
  110. <table class="FS-table">
  111. <apex:repeat value="{!$ObjectType.Intake__c.FieldSets.Investigation_Sched_Investigator_Email_N}" var="f">
  112. <tr>
  113. <td>
  114. <apex:outputText styleClass="bold" value="{!$ObjectType.Intake__c.Fields[f].label}" />
  115. </td>
  116. <td>
  117. <apex:outputField value="{!thisIntake[f.fieldPath]}" />
  118. </td>
  119. </tr>
  120. </apex:repeat>
  121. </table>
  122. <!-- <br/>
  123. <h1><strong>Client Details</strong></h1>
  124. <table class="FS-table">
  125. <apex:repeat value="{!$ObjectType.Account.FieldSets.Investigation_Sched_Investigator_Email_N}" var="fAccount">
  126. <tr>
  127. <td>
  128. <apex:outputText styleClass="bold" value="{!$ObjectType.Account.Fields[fAccount].label}" />
  129. </td>
  130. <td>
  131. <apex:outputField value="{!thisAccount[fAccount.fieldPath]}" />
  132. </td>
  133. </tr>
  134. </apex:repeat>
  135. </table> -->
  136.  
  137. <messaging:emailTemplate subject="New Scheduled Investigation" recipientType="User" relatedToType="Event">
  138. <messaging:htmlEmailBody >
  139. <html>
  140. <body>
  141. <p>You have been scheduled for the following Investigation:</p>
  142. <c:ScheduledEventMergeComponent theEvent="{!relatedTo.Id}"/>
  143. <br/><br/>
  144. </body>
  145. </html>
  146. </messaging:htmlEmailBody>
  147.  
  148. 12:59:23:126 USER_DEBUG [21]|DEBUG|Intake__c:{Intake_Name__c=James test-Automobile Accident-5/4/2016, Case_Type__c=Automobile Accident, Marketing_Source__c=-com-INTERNET, What_was_the_date_of_the_incident__c=2016-05-04 00:00:00, City_of_incident__c=Orlando, State_of_incident__c=FL, Id=a00q0000008BBYUAA4, Client__c=001q000000RjkzfAAB, RecordTypeId=012q00000000cRiAAI}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement