1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
|
public class Event_Ext {
/**********************************************************
Event controller extensions, used to display two APEX
driven Related lists on Event View and Send Mass Email
to Invitees on click of "Send Visit Report" button on Event.
RList 1. Event Invitees that are Amcor Employees
Rlist 2. Event Invitees that are Non-Amcor Employees
@Patrick Bulacz, Hallman and Associates
************************************************************/
// Declare Event Object and Attendee List Variables
private final Event myEvent;
public final Event myEvent1;
private Set<String> Contacts;
private Set<String> Leads;
private Set<String> Users;
private final List<EventRelation> Attendees;
private List<Employee> Employees = new List<Employee>();
private List<Employee> nonEmployees = new List<Employee>();
private List<Employee> EmailList = new List<Employee>();
List<attachmentwrapper> attachmentList = new List<attachmentwrapper>();
List<Attachment> attachmentToSend= new List<Attachment>();
List<Attachment> selectedAttachments = new List<Attachment>();
String e1;
private Event theEvent;
private Event_Map__c theMap;
// Checkbox for checkall
public Boolean selectAll;
// Id Holder for Visual Force PolyMorphic lookup Field
public String IdHolder;
// Error Message
public String Err = '';
// list complete
public Boolean Complete = false;
public PageReference redirect2(string str)
{
PageReference r= new PageReference(str);
r.setRedirect(true);
return r;
}
// Initiate Attendee and Event Variables based on Event in Question
public Event_Ext(ApexPages.StandardController stdController) {
// String eventI=ApexPages.currentPage().getParameters().get('newid');
// if(eventI.length()>8){
// string str= 'https://c.cs4.visual.force.com/apex/eventview?id='+eventI;
// redirect2(str);
// }else {
// String eventI=ApexPages.currentPage().getParameters().get('newid');
// this.myEvent1 = (Event)stdController.getRecord();
ID str=ApexPages.currentPage().getParameters().get('newid');
ID str1=ApexPages.currentPage().getParameters().get('id');
System.debug(str1+'############'+str);
// if(str != null && str1 != null)
if(str1 != null)
{
myEvent=[Select id from Event where id=:str1];
system.debug('ID>>>>>>'+myevent.id);
// Select attendees based on Event ID
//update LDR 17/01 The EventRelation object replaces the EventAttendee object - (www.salesforce.com/us/developer/docs/api/index_CSH.htm)
//Attendees = [select Attendee.FirstName, Attendee.LastName, AttendeeId from EventAttendee where EventId =: myEvent.Id];
Attendees = [select Id,Relation.Name from EventRelation where EventId =: myEvent.id ];
System.debug('##Attendees =##'+Attendees);
// system.debug('Event id '+eventI);
// Attendees = [select Attendee.FirstName, Attendee.LastName, AttendeeId from EventAttendee where EventId =: eventI];
// Attendee Id Field of Attendees Object is Polymorphic and can be a reference to either
// Leads / Contacts / Users so we need to seperate Id's from the List as we cannot
// Traverse the relationship as we can in other objects
// Create list of only unique Contacts from EventAttendees List
Contacts = UniqueIds('003');
// Create list of only unique Leads from EventAttendees List
Leads = UniqueIds('00Q');
// Create list of only unique Users from EventAttendees List
Users = UniqueIds('005');
// Create Employees and Non-Employees Related Lists
CreateLists();
redirect1();
// }
}
}
public PageReference redirect1()
/*LDR 25/03/2013 preventing from usage of hard-coded url :
Pagereference page = new Pagereference('/apex/MyFirstPage?id='+eid);
page.setRedirect(true);
return page;
*/
{
String eventId=ApexPages.currentPage().getParameters().get('newid');
String eid=ApexPages.currentPage().getParameters().get('id');
string str;
System.debug('#######'+eventId+'@@@@@@@'+eid);
// if((eid.length()<6) && (eventId.length()>10))
if(eid.length()>10)
{
str='/apex/eventview?id='+eid;
//prod : str=/apex/eventview?id='+eid;
system.debug(str);
}
PageReference r= new PageReference('/apex/eventview?id='+eid);
r.setRedirect(true);
//System.debug('##str=https://c.cs4.visual.force.com/apex/eventview?id=+eventId =##'+str);
// return null;
return r;
}
public String replaceStr(String s){
if(s==null) s='';
return s.replace('&', '%26');
}
// update the related to on this event
public PageReference updateRelatedTo(){
Event theEvent1 = [select Id, IsRecurrence, RecurrenceActivityId, What.Name, WhatId, WhoId, Who.Name, StartDateTime, EndDateTime, DisplayDateStart__c, DisplayDateEnd__c, DisplayRelatedTo__c, DisplayRelatedWho__c,Business_Group__c from Event where Id =: myEvent.Id];
List<Event> theEvents = new List<Event>();
if(theEvent1.RecurrenceActivityId != null){
theEvents = [select Id, IsRecurrence, RecurrenceActivityId, What.Name, WhatId, WhoId, Who.Name, StartDateTime, EndDateTime, DisplayDateStart__c, DisplayDateEnd__c, DisplayRelatedTo__c, DisplayRelatedWho__c,Business_Group__c from Event where RecurrenceActivityId =: theEvent1.RecurrenceActivityId];
}
system.debug('HOW MANY EVENTS = '+theEvents.size());
if(theEvents.isEmpty()){
theEvents.add(theEvent1);
}
for(Event theEvent:theEvents){
String startd = theEvent.DisplayDateStart__c;
String endd = theEvent.DisplayDateEnd__c;
String To = theEvent.DisplayRelatedTo__c;
String Who = theEvent.DisplayRelatedWho__c;
// update the event with the correct related to field values
if(theEvent.WhatId != null){
if(String.ValueOf(theEvent.WhatId).startsWith('006')){
Opportunity o = [select Name, Account.Name from Opportunity where Id=: theEvent.WhatId];
system.debug('What.Name = '+o.Name);
theEvent.DisplayRelatedTo__c = o.Name + ', ' + o.Account.Name;
system.debug('The Event DisplayRelatedTo__c 006: '+ theEvent.DisplayRelatedTo__c);
}
else if(String.ValueOf(theEvent.WhatId).startsWith('800')){
Contract c = [select Contract_Name_Region_Location__c, Account.Name from Contract where Id=: theEvent.WhatId];
system.debug('What.Name = '+c.Contract_Name_Region_Location__c);
theEvent.DisplayRelatedTo__c = c.Contract_Name_Region_Location__c + ', ' + c.Account.Name;
system.debug('The Event DisplayRelatedTo__c 800: '+ theEvent.DisplayRelatedTo__c);
}
else{
Account a = [select Name from Account where Id=: theEvent.WhatId];
system.debug('What.Name = '+theEvent.Who.Name);
theEvent.DisplayRelatedTo__c = a.Name;
system.debug('What.Name theEvent.DisplayRelatedTo__c = '+theEvent.DisplayRelatedTo__c);
}
}
else if(theEvent.WhatId == null){theEvent.DisplayRelatedTo__c = '';}
if(theEvent.WhoId != null){
if(String.ValueOf(theEvent.WhoId).startsWith('00Q')){
Lead l = [select Name, Company from Lead where Id=: theEvent.WhoId];
system.debug('Who.Name = '+l.Name);
theEvent.DisplayRelatedWho__c = l.Name + ', ' + l.Company;
system.debug('Who.Name 00Q theEvent.DisplayRelatedWho__c = '+theEvent.DisplayRelatedWho__c);
}
else if(String.ValueOf(theEvent.WhoId).startsWith('003')){
Contact c = [select Name, Account.Name from Contact where Id=: theEvent.WhoId];
system.debug('Who.Name = '+c.Name);
theEvent.DisplayRelatedWho__c = c.Name + ', ' + c.Account.Name;
system.debug('Who.Name 003 theEvent.DisplayRelatedWho__c = '+theEvent.DisplayRelatedWho__c);
}
}
else if(theEvent.WhoId == null){theEvent.DisplayRelatedWho__c = '';}
//Update dates for Event
if(theEvent.StartDateTime != null){theEvent.DisplayDateStart__c = theEvent.StartDateTime.format();}
if(theEvent.EndDateTime != null){theEvent.DisplayDateEnd__c = theEvent.EndDateTime.format();}
if(theEvent.DisplayDateStart__c == startd && theEvent.DisplayDateEnd__c == endd && theEvent.DisplayRelatedTo__c == to && theEvent.DisplayRelatedWho__c == Who){
}
else{
update theEvent;
}
}
return null;
}
// Return attachments List
public Boolean getComplete(){
return Complete;
}
// Return Amcor Employees List
public List<Employee> getEmployees(){
return Employees;
}
// Return Amcor Non-Employees List
public List<Employee> getnonEmployees(){
return nonEmployees;
}
// Return Amcor Non-Employees List Boolean True if List is Empty, False otherwise
public Boolean getnESize(){
return nonEmployees.isEmpty();
}
// Return Amcor Employees List Boolean True if List is Empty, False otherwise
public Boolean getESize(){
return Employees.isEmpty();
}
// Return Errors if Any
public String getErr(){
return Err;
}
// Return Concatenated Lists for Email Send
public List<Employee> getEmailList(){
if(EmailList.isEmpty()){
EmailList.addAll(Employees);
EmailList.addAll(nonEmployees);
}
return EmailList;
}
// Set Email List
public void setEmailList(List<Employee> eEmail){
this.EmailList = eEmail;
}
// return Id Holder for Visual Force Page Lookup Field
public String getIdHolder(){
return IdHolder;
}
// set Id Holder for Visual Force Page Lookup
public void setIdHolder(String sId){
this.IdHolder = sId;
}
// return select All checkbox
public Boolean getselectAll(){
return selectAll;
}
// set Id Holder for Visual Force Page Lookup
public void setselectAll(Boolean eAll){
this.selectAll = eAll;
}
// return list of Unique Ids within EventAttendee list
public Set<String> UniqueIds(String ObjType){
// Create a new Unique Set of Ids
Set<String> Ids = new Set<String>();
//ldr EventAttendee /EventRelation Loop through EventAttendees and adding records to set based on ObjType String passed as parameter
for (EventRelation thisAttendee: Attendees)
{
if(Ids.contains(thisAttendee.RelationId) && String.ValueOf(thisAttendee.RelationId).startsWith(ObjType))
{continue;
}
else if(String.ValueOf(thisAttendee.RelationId).startsWith(ObjType))
{
Ids.add(thisAttendee.RelationId);
}
}
return Ids;
}
// Create Lists for Employees and Non Employees
public void CreateLists(){
// Select required SObject fields within designated Sets
List<Contact> c = [select Id, Account.Name, FirstName, LastName, Title, Email, Phone, RecordType.Name from Contact where Id IN: Contacts];
List<User> u = [select Id, FirstName, LastName, Title, Email, Phone from User where Id IN: Users];
List<Lead> l = [select Id, FirstName, LastName, Title, Email, Company, Phone from Lead where Id IN: Leads];
// Loop through contacts adding to either Employees or Non-Employees based on Record Type
for(Contact thisC:c){
if(thisC.RecordType.Name == 'Amcor Personnel' && thisC.Account.Name == 'Amcor Ltd'){
Employees.add(new Employee(thisC.Id, thisC.FirstName, thisC.LastName, thisC.Email, thisC.Phone, thisC.Title, 'Amcor Ltd', thisC.RecordType.Name, false, 'Yes'));
}
else{
nonEmployees.add(new Employee(thisC.Id, thisC.FirstName, thisC.LastName, thisC.Email, thisC.Phone, thisC.Title, thisC.Account.Name, 'NonP', false, 'No'));
}
}
// Loop through users adding to Employees (assumes all users are internal employees)
for(User thisU:u){
System.debug('##########Value of thisU====>'+thisU);
Employees.add(new Employee(thisU.Id, thisU.FirstName, thisU.LastName, thisU.Email, thisU.Phone, thisU.Title, 'Amcor Ltd', 'Amcor Personnel', false, 'Yes'));
}
// Loop through leads adding to Non-Employees (assumes all leads are not employees)
for(Lead thisL:l){
System.debug('##########Value of thisL====>'+thisL);
nonEmployees.add(new Employee(thisL.Id, thisL.FirstName, thisL.LastName, thisL.Email, thisL.Phone, thisL.Title, thisL.Company, 'NonP', false, 'No'));
}
}
// Return User to the Event View Page on Cancel
public PageReference cancel(){
ID str=ApexPages.currentPage().getParameters().get('id');
// Event myEvent3=new Event();
if(str != null )
{
PageReference pageRef = new PageReference('/'+ str);
pageRef.setRedirect(true);
return pageRef;
// this.myEvent = (Event)stdController.getRecord();
// myEvent3=[Select id from Event where id=:str];
}
else
return null;
}
// Build Queries for the Event and Event Map Object
public void BuildQueries(Map<String, Schema.SObjectField> emSMap, Map<String, Schema.SObjectField> evSMap){
// Initialise variables that will hold the Field Names for eact object
String evQuery = '';
String emQuery = '';
// Start a counter to account for Fence Posts (i.e select field1, field2, field3, from Sobject)
Integer count = 0;
// Cycle through Fields KeyMap and create a query string of Fields
for(String thisKey:emSMap.keySet()){
if(count == emSMap.size()-1){emQuery += emSMap.get(thisKey);}
else{emQuery += emSMap.get(thisKey) + ', ';}
count++;
}
// reset counter to account for Fence Posts
count = 0;
// Cycle through Fields KeyMap and create a query string of Fields
for(String thisKey:evSMap.keySet()){
if(count == evSMap.size()-1){evQuery += evSMap.get(thisKey);}
else{evQuery += evSMap.get(thisKey) + ', ';}
count++;
}
// Get the only Event Map Record in Existence along with all it's fields
theMap = Database.query('select ' + emQuery + ' from Event_Map__c limit 1');
// Convert the ID to a String for a simple query
String id = myEvent.Id;
// Assign the Event in Question
theEvent = Database.query('select ' + evQuery + ' from Event where Id=\''+id+'\' LIMIT 1');
}
// Send an email template to be parsed and have Curly Bracket Strings Replaced replaced.
public String ReplaceStr(String tmp, Map<String, Schema.SObjectField> sMap){
// Set a temporary string as '' so we have no nulls
String tmpStr = '';
// Loop through key map set for an event map
for(String thisKey:sMap.keySet()){
// add curly bracket syntax that appears in templates
tmpStr = '{!Event_Map__c.'+sMap.get(thisKey)+'}';
// check if template contains the curly bracket syntax for the variable in question
if(tmp.contains(tmpStr)){
// Try catch some exceptions if the Field Maps do not align.
try{
// replace it with '' if null otherwise replace the curly bracket syntax with
// the field value
if(String.ValueOf(theEvent.get(String.ValueOf(theMap.get(thisKey)))) == null){tmp = tmp.replace(tmpStr, '');}
else{tmp = tmp.replace(tmpStr, String.ValueOf(theEvent.get(String.ValueOf(theMap.get(thisKey)))));}
}
catch(Exception e){
// Throw an Error
return 'error';
}
}
}
return tmp;
}
public List<attachmentwrapper> getAttachments()
{
ID strsfdc=ApexPages.currentPage().getParameters().get('id');
ID eventIdsfdc=ApexPages.currentPage().getParameters().get('newid');
System.debug('#########'+strsfdc+'$$$$$$$$$'+eventIdsfdc);
if(strsfdc != null)
{
for(Attachment t : [select ParentId, Id, Name from Attachment where ParentId =: strsfdc])
{
System.debug('$$$$$$$$$$$$$$$$Value of T==='+t);
attachmentList.add(new attachmentwrapper(t));
}
System.debug('size of attachment'+attachmentList.size());
return attachmentList;
}
else
return null;
//attachmentList.IsPrivate = true;
}
public PageReference getSelected()
{
selectedAttachments.clear();
for(attachmentwrapper attwrapper : attachmentList)
{
if(attwrapper.selected == true)
selectedAttachments.add(attwrapper.att);
}
return null;
}
public List<Attachment> GetSelectedAttachments()
{
if(selectedAttachments.size()>0)
{
System.debug('###########Seelcted Attachment=======>'+selectedAttachments);
return selectedAttachments;
}
else
return null;
}
public class attachmentwrapper
{
public Attachment att {get;set;}
public Boolean selected {get;set;}
public attachmentwrapper(Attachment t)
{
att = t;
selected = false;
}
}
// Send Mass Email to Selected Users/Contacts/Leads
public PageReference SendEmail()
{
// create an empty list to hold email addresses.
String[] Emails = new List<String>();
String[] toAddresses = new List<String>();
String[] BccAddresses = new List<String>();
String[] ccAddresses = new List<String>();
// create holders for the body and htmlvalue of a template
String Body = '';
String htBody = '';
String Subject = '';
// Select the Email Template to be Merged.
EmailTemplate tmplate;
Event RTname = [Select RecordType.DeveloperName from Event where Id =:myEvent.Id];
if(RTname.RecordType.DeveloperName == 'Galaxy_Visit_Report')
{
tmplate = [select Subject, Body, HtmlValue, Id from EmailTemplate where Name =: 'Special Visit Report' limit 1];
}
else
{
tmplate = [select Subject, Body, HtmlValue, Id from EmailTemplate where Name =: 'Visit Report' limit 1];
}
// Get the sObject describe result for the Event_Map__c object and Event object and
// describe the fields
Map<String, Schema.SObjectField> EM = Schema.SObjectType.Event_Map__c.fields.getMap();
Map<String, Schema.SObjectField> EV = Schema.SObjectType.Event.fields.getMap();
// Build our queries and set our event in question using our Field Map keysets.
BuildQueries(EM, EV);
// replace the curly bracket syntax with field values from the event
Body = ReplaceStr(tmplate.Body, EM);
htBody = ReplaceStr(tmplate.HtmlValue, EM);
Subject = ReplaceStr(tmplate.Subject, EM);
if(Body != 'error' && htBody != 'error')
{
// Create our email list from the selected recipients
for(Employee thisE:EmailList)
{
if(RTname.RecordType.DeveloperName == 'Galaxy_Visit_Report')
{
if(thisE.EmailYes == true && thisE.Email != null && thisE.Send == 'Yes')
{
Emails.add(thisE.Email);
}
}
else
{
if(thisE.EmailYes == true && thisE.Email != null)
{
Emails.add(thisE.Email);
}
}
}
// Initialise an email object to send
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
// split up the addresses for greater than 10 into cc's bcc's and to's.
Integer Count = 0;
if(Emails.size() >10)
{
for(String thisAddy:Emails)
{
if(count<=10)
{
toAddresses.add(thisAddy);
}
else if(count >=11 && count <= 15)
{
ccAddresses.add(thisAddy);
}
else if(count >= 15 && count <= 25)
{
BccAddresses.add(thisAddy);
}
count++;
}
}
else if(!Emails.isEmpty())
{
toAddresses = Emails;
}
/* else
{
toAddresses.add('test@test.com');
}*/
// Assign the addresses for the To lists to the mail object.
email.setToAddresses(toAddresses);
if(!ccAddresses.isEmpty())
{
email.setCcAddresses(ccAddresses);
}
if(!BccAddresses.isEmpty())
{
email.setBccAddresses(BccAddresses);
}
// Assign Html and Text Body Values
email.setHtmlBody(htBody.replace('\n', '<br/>'));
email.setPlainTextBody(Body);
// Set email Subject
email.setSubject(Subject);
//picking up existing attachements
//Defining List to store the attachments to be sent
List<Messaging.EmailFileAttachment> ats = new List<Messaging.EmailFileAttachment>();
//Create a list of selected attachments
//List<Attachment> selectedAttachments = new List<Attachment>();
//Loop through our list of attachments and check if the selected attachment is set to true,
//if it is we add the attachment to the selectedattachment list
if(selectedAttachments !=null)
if(selectedAttachments.size()>0)
{
for(Attachment att : selectedAttachments)
{
for(Attachment attachmentToSend : [select ParentId, Id, Name,Body from Attachment where Id =: att.Id])
{
Messaging.Emailfileattachment eff = new Messaging.Emailfileattachment();
eff.setFileName(attachmentToSend.Name);
eff.setBody(attachmentToSend.Body);
ats.add(eff);
att.Body=null;
}
}
}
// Create an email attachment
//if()
email.setFileAttachments(ats);
// send it, ignoring any errors (-- testing)
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
// Redirect user to the Event View Page
PageReference pageRef = new PageReference('/'+ myEvent.Id);
pageRef.setRedirect(true);
return pageRef;
}
else
{
// Redirect user to the Error Page
PageReference pageRef = new PageReference('/apex/visitreportErr?Id='+myEvent.Id);
pageRef.setRedirect(true);
return pageRef;
}
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
public class atAttachment {
public Attachment attach {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
public atAttachment(Attachment at) {
attach = at;
selected = false;
}
}
// add additional Users to the Email List
public PageReference addTo() {
system.debug(IdHolder);
Integer count = 0;
// Make sure the Email List is unique
for(Employee thisE:EmailList){
system.debug(IdHolder + ' = ' + thisE.Id);
if(thisE.Id.subString(0,15) == IdHolder){
count++;
}
}
// Check what type of Id has been "looked up"
if(IdHolder.StartsWith('003') && count == 0){
// Select relevant fields from this Id
Contact c = [select Id, FirstName, LastName, Account.Name, Title, Phone, Email, RecordType.Name From Contact where Id =: IdHolder];
// Add this Contact to the Email List
if(c.RecordType.Name == 'Amcor Personnel' && c.Account.Name == 'Amcor Ltd'){
EmailList.add(new Employee(c.Id,c.FirstName,c.LastName,c.Email,c.Phone,c.Title,c.Account.Name,c.RecordType.Name, true, 'Yes'));
}
else{
EmailList.add(new Employee(c.Id,c.FirstName,c.LastName,c.Email,c.Phone,c.Title,c.Account.Name,c.RecordType.Name, true, 'No'));
}
}
else if(IdHolder.StartsWith('00Q') && count == 0){
// Select relevant fields from this Id
Lead l = [select Id, FirstName, LastName, Company, Title, Phone, Email From Lead where Id =: IdHolder];
// Add this Lead to the Email List
EmailList.add(new Employee(l.Id,l.FirstName,l.LastName,l.Email,l.Phone,l.Title,l.Company,'NonP', true, 'No'));
}
else if(IdHolder.StartsWith('005') && count == 0){
// Select relevant fields from this Id
User u = [select Id, FirstName, LastName, Title, Phone, Email From User where Id =: IdHolder];
// Add this Lead to the Email List
EmailList.add(new Employee(u.Id,u.FirstName,u.LastName,u.Email,u.Phone,u.Title,'Amcor Ltd','Amcor Personnel', true, 'Yes'));
}
return null;
}
public PageReference attach() {
Complete = true;
return null;
}
// check/uncheck all recipients for sending and display
public PageReference checkAll(){
for(Employee thisE:EmailList){
if(selectAll == true){
thisE.EmailYes = true;
}
else{
thisE.EmailYes = false;
}
}
return null;
}
} |
Partager