--------------------------------------VF CODE-------------------------------------------- <apex:page controller="Agents_notes_attachments_report" sidebar="false" showHeader="false" readOnly="true"> <style> .slds-scope .slds-table:not(.slds-no-row-hover) tbody tr:hover>td, .slds-scope .slds-table:not(.slds-no-row-hover) tbody tr:focus>td { background-color: #91babc; } .slds-scope .slds-table:not(.slds-no-row-hover) tbody tr:hover>th, .slds-scope .slds-table:not(.slds-no-row-hover) tbody tr:focus>th{ background-color: transparent; } .slds-scope .slds-icon { width: 24px; height: 2rem; fill: rgb(255, 255, 255); } </style> <head> <meta charset="utf-8" /> <meta http-equiv="x-ua-compatible" content="ie=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <apex:slds /> </head > <body class="slds-scope" id="bdy"> <div class="slds-page-header"> <div class="slds-page-header__row"> <div class="slds-page-header__col-title"> <div class="slds-media"> <div class="slds-media__figure"> <span class="slds-icon_container slds-icon-standard-report" title="opportunity"> <svg class="slds-icon slds-page-header__icon" aria-hidden="true"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/standard-sprite/svg/symbols.svg#report" /> </svg> <span class="slds-assistive-text">opportunity</span> </span> </div> <div class="slds-media__body"> <div class="slds-page-header__name"> <div class="slds-page-header__name-title"> <h1> <span class="slds-page-header__title slds-truncate">Agent Report On Notes And Attachments</span> </h1> </div> </div> </div> </div> </div> </div> </div> <apex:pageBlock > <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered " > <colgroup> <col style="background-color:#2fbdc4"/> <col style="background-color:#b3ecef"/> <col style="background-color:#b3ecef"/> <col style="background-color:#b3ecef"/> <col style="background-color:#b3ecef"/> <col style="background-color:#b3ecef"/> <col style="background-color:#0fd8e2"/> </colgroup> <tr class="slds-line-height_reset slds-truncate" style="background-color:#1c2f6b;"> <th class="slds-text-title_caps" scope="col"> <span style="font-weight:bold;color:white;">Agent Name</span> </th> <th class="slds-text-title_caps" scope="col" ><span style="font-weight:bold;color:white;">Notes Captured</span></th> <th class="slds-text-title_caps" scope="col" ><span style="font-weight:bold;color:white;">Attachments added</span></th> <th class="slds-text-title_caps" scope="col" ><span style="font-weight:bold;color:white;">Attachments on activities</span></th> <th class="slds-text-title_caps" scope="col" ><span style="font-weight:bold;color:white;">Activities</span></th> <th class="slds-text-title_caps" scope="col" ><span style="font-weight:bold;color:white;">Lead History Updates</span></th> <th class="slds-text-title_caps myTable-row-highlight" scope="col" ><span style="font-weight:bold;color:white;">Total</span></th> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px">{!userNames[0]}</span></td> <td class="tg-yw4l">{!noteCount[0]}</td> <td>{!attachCount[0]}</td> <td>{!taskAttachCount[0]}</td> <td>{!leadcommentCount[0]}</td> <td>{!LeadHisCount[0]}</td> <td>{!row0}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px"> {!userNames[1]}</span></td> <td class="tg-yw4l">{!noteCount[1]}</td> <td class="tg-yw4l">{!attachCount[1]}</td> <td class="tg-yw4l">{!taskAttachCount[1]}</td> <td class="tg-yw4l">{!leadcommentCount[1]}</td> <td class="tg-yw4l">{!LeadHisCount[1]}</td> <td class="tg-yw4l">{!row1}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px">{!userNames[2]}</span></td> <td class="tg-yw4l">{!noteCount[2]}</td> <td class="tg-yw4l">{!attachCount[2]}</td> <td class="tg-yw4l">{!taskAttachCount[2]}</td> <td class="tg-yw4l">{!leadcommentCount[2]}</td> <td class="tg-yw4l">{!LeadHisCount[2]}</td> <td class="tg-yw4l">{!row2}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px"> {!userNames[3]}</span></td> <td class="tg-yw4l">{!noteCount[3]}</td> <td class="tg-yw4l">{!attachCount[3]}</td> <td class="tg-yw4l">{!taskAttachCount[3]}</td> <td class="tg-yw4l">{!leadcommentCount[3]}</td> <td class="tg-yw4l">{!LeadHisCount[3]}</td> <td class="tg-yw4l">{!row3}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px"> {!userNames[4]}</span></td> <td class="tg-yw4l">{!noteCount[4]}</td> <td class="tg-yw4l">{!attachCount[4]}</td> <td class="tg-yw4l">{!taskAttachCount[4]}</td> <td class="tg-yw4l">{!leadcommentCount[4]}</td> <td class="tg-yw4l">{!LeadHisCount[4]}</td> <td class="tg-yw4l">{!row4}</td> </tr> <tr> <td class="tg-yw4l"> <span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px">{!userNames[5]}</span></td> <td class="tg-yw4l">{!noteCount[5]}</td> <td class="tg-yw4l">{!attachCount[5]}</td> <td class="tg-yw4l">{!taskAttachCount[5]}</td> <td class="tg-yw4l">{!leadcommentCount[5]}</td> <td class="tg-yw4l">{!LeadHisCount[5]}</td> <td class="tg-yw4l">{!row5}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px">{!userNames[6]}</span></td> <td class="tg-yw4l">{!noteCount[6]}</td> <td class="tg-yw4l">{!attachCount[6]}</td> <td class="tg-yw4l">{!taskAttachCount[6]}</td> <td class="tg-yw4l">{!leadcommentCount[6]}</td> <td class="tg-yw4l">{!LeadHisCount[6]}</td> <td class="tg-yw4l">{!row6}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span> <span style="margin-left:6px">{!userNames[7]}</span></td> <td class="tg-yw4l">{!noteCount[7]}</td> <td class="tg-yw4l">{!attachCount[7]}</td> <td class="tg-yw4l">{!taskAttachCount[7]}</td> <td class="tg-yw4l">{!leadcommentCount[7]}</td> <td class="tg-yw4l">{!LeadHisCount[7]}</td> <td class="tg-yw4l">{!row7}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px">{!userNames[8]}</span></td> <td class="tg-yw4l">{!noteCount[8]}</td> <td class="tg-yw4l">{!attachCount[8]}</td> <td class="tg-yw4l">{!taskAttachCount[8]}</td> <td class="tg-yw4l">{!leadcommentCount[8]}</td> <td class="tg-yw4l">{!LeadHisCount[8]}</td> <td class="tg-yw4l">{!row8}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span> <span style="margin-left:6px">{!userNames[9]}</span></td> <td class="tg-yw4l">{!noteCount[9]}</td> <td class="tg-yw4l">{!attachCount[9]}</td> <td class="tg-yw4l">{!taskAttachCount[9]}</td> <td class="tg-yw4l">{!leadcommentCount[9]}</td> <td class="tg-yw4l">{!LeadHisCount[9]}</td> <td class="tg-yw4l">{!row9}</td> </tr> <tr> <td class="tg-yw4l"><span class="slds-icon_container slds-icon-custom-user" > <svg aria-hidden="true" class="slds-icon"> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#user"> </use> </svg> </span><span style="margin-left:6px"> {!userNames[10]}</span></td> <td class="tg-yw4l">{!noteCount[10]}</td> <td class="tg-yw4l">{!attachCount[10]}</td> <td class="tg-yw4l">{!taskAttachCount[10]}</td> <td class="tg-yw4l">{!leadcommentCount[10]}</td> <td class="tg-yw4l">{!LeadHisCount[10]}</td> <td class="tg-yw4l">{!row10}</td> </tr> </table > </apex:pageblock> </body> </apex:page> -------------------------------- Controller Class------------------------------------------- public class Agents_notes_attachments_report { public String No_of_notes { get; set; } public Integer Note_Count {get;set;} public Integer tempVal =0; public Integer tempVal1 =0; List<AggregateResult> ar; List<AggregateResult> ar1; List<AggregateResult> ar2; public list<integer> First_User_Total{get;set;} list<id> userIds= new list<id>(); public list<Integer> noteCount {get;set;} public list<Integer> attachCount {get;set;} public list<Integer> LeadHisCount {get;set;} public list<Integer> taskAttachCount {get;set;} public list<Integer> leadcommentCount {get;set;} public String lastfriday; public integer row0 {get;set;} public integer row1 {get;set;} public integer row2 {get;set;} public integer row3 {get;set;} public integer row4 {get;set;} public integer row5 {get;set;} public integer row6 {get;set;} public integer row7 {get;set;} public integer row8 {get;set;} public integer row9 {get;set;} public integer row10 {get;set;} public list<string> userNames {get;set;} public map<integer,integer> mapvalues {get;set;} public Agents_notes_attachments_report() { noteCount = new list<Integer>(); attachCount =new list<Integer>(); LeadHisCount =new list<Integer>(); taskAttachCount = new list<Integer>(); leadcommentCount =new list<Integer>(); First_User_Total =new list<Integer>(); mapvalues=new map<integer,integer>(); mapvalues.put(123,5); mapvalues.put(456,6); List<string> Lststr=new List<string>(); string[] agentss = System.label.Agents_List.split(','); system.debug('------agentss---'+agentss.size() ); for(string s :agentss ){ Lststr.add(s); system.debug('------Lststr---'+Lststr ); } userNames = new list<string>(); for(user u : [select name from user where lastname =: Lststr]){ userNames.add(u.name); } Datetime dt = DateTime.newInstance(Date.today(), Time.newInstance(0, 0, 0, 0)); string dayOfWeek = dt.format('EEEE'); string query; // string query2; if (dayOfWeek == 'Monday'){ String date1=String.valueof(Date.Today()-3); String date2=String.valueof(Date.Today()-2); date1=date1+' 02:00:00'; date2=date2+' 02:00:00'; Datetime lastfriday=Datetime.valueof(date1); Datetime next_2_friday=Datetime.valueof(date2); query = ' CreatedDate >= :lastfriday and createdDate < :next_2_friday'; //' CreatedDate >='+lastfriday+' and CreatedDate <'+next_2_friday; }else { query =' CreatedDate = YESTERDAY'; } for(user u : [select id,lastname from user where lastname =: Lststr] ){ system.debug('------++++++++---'+u ); userIds.add(u.id); // system.debug('------user_map---'+user_map); } for(id mapi :userIds){ //notesssssssss system.debug('------mapi---'+mapi); system.debug(dayOfWeek +'dayOfWeek'); string str = 'SELECT count(id) FROM Note where Parent.Type=\'Lead\' AND OwnerId =\''+mapi+'\' and'+query; //and'+query system.debug('------str---'+str); ar = Database.query(str); system.debug('------ar---'+ar); tempVal =(Integer) ar[0].get('expr0'); noteCount.add(tempVal); system.debug('------noteCount---'+noteCount); //attachmentsssssssss string str1= 'SELECT count(Id) FROM Attachment where parent.type=\'Lead\' AND OwnerId =\''+mapi+'\' and'+query; ar1 = Database.query(str1); system.debug('------str1---'+str1); tempVal1 =(Integer) ar1[0].get('expr0'); attachCount.add(tempVal1); system.debug('------attachCount---'+attachCount + mapi ); //leadhistoryyyyyyyyyyyyyyy // Map<String,LeadHistory> lhmap = new Map<String,LeadHistory>(); set<string> setString = new set<string>(); List<LeadHistory> lh; string str2 = 'SELECT Id,Field FROM LeadHistory where CreatedById=\''+mapi+'\' and'+query; lh = Database.query(str2); system.debug('------str2---'+str2); for(LeadHistory h:lh) { setString.add(h.Field); } tempVal = setString.size(); if(tempVal != 0) LeadHisCount.add(tempVal); else LeadHisCount.add(0); System.debug(setString.size()); System.debug(setString+'mappp'); //Attachments on Activities//////////// List<lead> listlead=new list<lead>(); // if(listlead.size() != null){ listlead =[select id,status from Lead where status='Open' and OwnerId =: mapi ]; set<id> leadIds = new set<id>(); for(Lead l : listlead ){ leadIds.add(l.id); } set<id> setid = new set<id>(); List<task> listIdToTask; system.debug('----- listlead7---'+ leadIds); string str3 = 'SELECT id,(SELECT id from attachments where'+query+') from task where whoId IN :leadIds'; system.debug('------str3---'+str3); // Database.query(str3); listIdToTask = Database.query(str3); system.debug(listIdToTask +'jjjj'); for(task t:listIdToTask){ //setid.add(t.id); for(attachment a : t.attachments){ setid.add(a.id); } } tempVal = setid.size(); taskAttachCount.add(tempVal); System.debug(tempVal +'&&&&&&&&&&' ); System.debug(taskAttachCount +'**********' ); /* set<id> setid1 = new set<id>(); List<event> listIdToevent = [SELECT id,(SELECT id from attachments) from event where whoId=:listlead ]; for(event e:listIdToevent ){ setid1.add(e.id); } tempVal = setid1.size(); taskAttachCount.add(tempVal); System.debug(tempVal +'&&&&&&&&&&' ); System.debug(taskAttachCount +'**********' ); lead commentssssssssss */ System.debug(dayOfWeek +'commentssssssss' ); string str4='SELECT count(id) from Lead_Comments__c where OwnerId =\''+mapi+'\' and'+query; ar2 = Database.query(str4); system.debug('------str4---'+str4); tempVal1 =(Integer) ar2[0].get('expr0'); leadcommentCount.add(tempVal1); } row0 = noteCount[0]+attachCount[0]+LeadHisCount[0]+taskAttachCount[0]+leadcommentCount[0]; row1 = noteCount[1]+attachCount[1]+LeadHisCount[1]+taskAttachCount[1]+leadcommentCount[1]; row2 = noteCount[2]+attachCount[2]+LeadHisCount[2]+taskAttachCount[2]+leadcommentCount[2]; row3 = noteCount[3]+attachCount[3]+LeadHisCount[3]+taskAttachCount[3]+leadcommentCount[3]; row4 = noteCount[4]+attachCount[4]+LeadHisCount[4]+taskAttachCount[4]+leadcommentCount[4]; row5 = noteCount[5]+attachCount[5]+LeadHisCount[5]+taskAttachCount[5]+leadcommentCount[5]; row6 = noteCount[6]+attachCount[6]+LeadHisCount[6]+taskAttachCount[6]+leadcommentCount[6]; row7 = noteCount[7]+attachCount[7]+LeadHisCount[7]+taskAttachCount[7]+leadcommentCount[7]; row8 = noteCount[8]+attachCount[8]+LeadHisCount[8]+taskAttachCount[8]+leadcommentCount[8]; row9 = noteCount[9]+attachCount[9]+LeadHisCount[9]+taskAttachCount[9]+leadcommentCount[9]; row10 = noteCount[10]+attachCount[10]+LeadHisCount[10]+taskAttachCount[10]+leadcommentCount[10]; } } ----------------------- Controller Test Class--------------------------------------------- @istest public class Agents_notes_attachments_report_test { public String dayOfWeek; static testmethod void testSendEmail(){ Id pSystemAdminId = [Select Id, Name from Profile where Name = 'System Administrator'].Id; User u = new User(Alias = 'standt', Email='standarduserUS1@testorg1.com',EmailEncodingKey='UTF-8', LastName='Site Guest User', LanguageLocaleKey='en_US',LocaleSidKey='en_US', ProfileId = pSystemAdminId ,TimeZoneSidKey='America/Los_Angeles', UserName='standardUSuser1@testorg.com'); insert u; system.runAs(u){ Lead testLead = new Lead(); testLead.FirstName = 'Test FirstName'; testLead.LastName = 'Test LastName'; testLead.Email = 'email@test.com'; testLead.Update_Status__c='Open'; testLead.Status_Reason__c='Contacted'; testLead.MobilePhone = '+1234'; List<lead> leadList=new List<lead>(); leadList.add(testLead); insert leadList; Task t2=new task(); t2.Priority = 'High'; t2.Status = 'Completed'; Date myDate2 = Date.TODAY(); t2.whoid = testLead.id; t2.Description='testing'; Task t22=new task(); t22.Priority = 'High'; t22.Status = 'Completed'; Datetime dt = DateTime.newInstance(Date.today().adddays(-5), Time.newInstance(0, 0, 0, 0)); Datetime yesterday= (Date.today()); string dayOfWeek; dayOfWeek = dt.format('EEEE'); t22.CreatedDate=Date.newInstance(2018,03,09); // t21.CreatedDate=System.today()- 5; t22.whoid = testLead.id; t22.Description='testing'; insert t22; List<task> Listtask =new List<task>(); Listtask.add(t2); // Listtask.add(t21); insert Listtask; Lead_Comments__c lc = new Lead_Comments__c(Lead__c=testLead.id,Comment__c='test comments',CreatedDate=Date.newInstance(2018,03,09)); insert lc; ApexPages.StandardSetController standardController; ApexPages.currentPage().getParameters().put('rec',leadList[0].id); Agents_notes_attachments_report AG=new Agents_notes_attachments_report(); AG.No_of_notes='test'; ag.Note_Count=2; } } }

Comments
Post a Comment