Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class ScheduledEventMergeController {
- public Intake__c thisIntake {get;set;}
- public Event thisEvent {get;set;}
- public Account thisAccount {get;set;}
- public Id relatedAccountId {get;set;}
- public Id relatedIntakeId {get;set;}
- public Id relatedEventId {
- get {
- return relatedEventId;
- }
- set {
- relatedEventId = value;
- thisEvent = queryEvent('Investigation_Sched_Investigator_Email_N');
- Id relatedIntakeId = thisEvent.WhatId;
- thisIntake = queryIntake('Investigation_Sched_Investigator_Email_N');
- // relatedAccountId = thisIntake.Client__c;
- // thisAccount = queryPerson('Investigation_Sched_Investigator_Email_N');
- }
- }
- public ScheduledEventMergeController() {
- }
- public static List<FieldSetMember> readFieldSet(String fieldSetName, String ObjectName) {
- Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe();
- Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName);
- Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();
- Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName);
- return fieldSetObj.getFields();
- }
- public Event queryEvent(String eventFieldSetName) {
- List<FieldSetMember> fieldSetMemberList = readFieldSet(eventFieldSetName, 'Event');
- String query = 'SELECT ';
- for(Schema.FieldSetMember f : fieldSetMemberList) {
- query += f.getFieldPath() + ', ';
- }
- query += 'Id, WhatId from Event WHERE Id = ''+relatedEventId+'' LIMIT 1';
- try {
- List<Event> dummyEvent = Database.query(query);
- return dummyEvent[0];
- } catch (Exception e) {
- return null;
- }
- }
- public Intake__c queryIntake(String intakeFieldSetName) {
- List<FieldSetMember> fieldSetMemberList = readFieldSet(intakeFieldSetName, 'Intake__c');
- String query = 'SELECT ';
- for(Schema.FieldSetMember f : fieldSetMemberList) {
- query += f.getFieldPath() + ', ';
- }
- query += 'Id, client__c from Intake__c WHERE Id = ''+relatedIntakeId+'' LIMIT 1';
- try {
- List<Intake__c> dummyIntake = Database.query(query);
- return dummyIntake[0];
- } catch (Exception e) {
- //error
- return null;
- }
- }
- public Account queryPerson(String accountFieldSetName) {
- List<FieldSetMember> fieldSetMemberList = readFieldSet(accountFieldSetName, 'Account');
- String query = 'SELECT ';
- for(Schema.FieldSetMember f : fieldSetMemberList) {
- query += f.getFieldPath() + ', ';
- }
- query += 'Id from Account WHERE Id = ''+relatedAccountId+''';
- try {
- List<Account> dummyAccount = Database.query(query);
- return dummyAccount[0];
- } catch (Exception e) {
- // System.addError('There is error while Fetching existing Account using Dynamic SOQL in Field Set. Error Detail - '+e.getMessage());
- return null;
- }
- }}
- <apex:component controller="ScheduledEventMergeController" access="global">
- <apex:attribute name="theEvent" type="Id" description="the event id" assignTo="{!relatedEventId}" />
- <style type="text/css">
- .FS-table {border-collapse:collapse;border-spacing:0;}
- .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;}
- </style>
- <table class="FS-table">
- <apex:repeat value="{!$ObjectType.Event.FieldSets.Investigation_Sched_Investigator_Email_N}" var="fEvent">
- <tr>
- <td>
- <apex:outputText styleClass="bold" value="{!$ObjectType.Event.Fields[fEvent].label}" />
- </td>
- <td>
- <apex:outputField value="{!thisEvent[fEvent.fieldPath]}" />
- </td>
- </tr>
- </apex:repeat>
- </table>
- <br/>
- <h1><strong>Intake Details</strong></h1>
- <table class="FS-table">
- <apex:repeat value="{!$ObjectType.Intake__c.FieldSets.Investigation_Sched_Investigator_Email_N}" var="f">
- <tr>
- <td>
- <apex:outputText styleClass="bold" value="{!$ObjectType.Intake__c.Fields[f].label}" />
- </td>
- <td>
- <apex:outputField value="{!thisIntake[f.fieldPath]}" />
- </td>
- </tr>
- </apex:repeat>
- </table>
- <!-- <br/>
- <h1><strong>Client Details</strong></h1>
- <table class="FS-table">
- <apex:repeat value="{!$ObjectType.Account.FieldSets.Investigation_Sched_Investigator_Email_N}" var="fAccount">
- <tr>
- <td>
- <apex:outputText styleClass="bold" value="{!$ObjectType.Account.Fields[fAccount].label}" />
- </td>
- <td>
- <apex:outputField value="{!thisAccount[fAccount.fieldPath]}" />
- </td>
- </tr>
- </apex:repeat>
- </table> -->
- <messaging:emailTemplate subject="New Scheduled Investigation" recipientType="User" relatedToType="Event">
- <messaging:htmlEmailBody >
- <html>
- <body>
- <p>You have been scheduled for the following Investigation:</p>
- <c:ScheduledEventMergeComponent theEvent="{!relatedTo.Id}"/>
- <br/><br/>
- </body>
- </html>
- </messaging:htmlEmailBody>
- 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