You need to sign in to do that
Don't have an account?
Terri Henry
Test Class coverage for code tracking User Record Views
Hi All,
I've amended a solution for tracking page views I found here:
https://success.salesforce.com/answers?id=9063A000000Dq6MQAS
I'm using it to track who has viewed an Opportunity record page - however I have no idea where to start with the test class - I'm currently working through a couple of trailhead modules, though any pointers would be greatly appreciated
Thanks
Terri
I've amended a solution for tracking page views I found here:
https://success.salesforce.com/answers?id=9063A000000Dq6MQAS
I'm using it to track who has viewed an Opportunity record page - however I have no idea where to start with the test class - I'm currently working through a couple of trailhead modules, though any pointers would be greatly appreciated
Thanks
Terri
public without sharing class lastViewedOpportunity{ public Datetime cDT; public String LongDate; public String firstname; public String lastname; public String existinglastviewed; public String userid; private final Opportunity opp; public lastViewedOpportunity(ApexPages.StandardController stdController) { this.opp = (Opportunity)stdController.getRecord(); } public String getLongDate() { cDT = System.now(); //Formats the datetime value to locale LongDate = cDT.format('dd/MM/yyyy HH:mm'); return LongDate; } public void updateField() { //Get the user info from the current user firstname = System.Userinfo.getFirstName(); lastname = System.Userinfo.getLastName(); userid = System.Userinfo.getUserId(); //Get the Opportunity record to be updated Opportunity o = [select Last_Viewed_By__c, Track_Record__c from Opportunity where id = :opp.id limit 1]; //get existing string of the record, so that new view can be appended to the end of this existinglastviewed = o.Last_Viewed_By__c; //check to see if the Opportunity has been flagged for tracking if(o.Track_Record__c){ //Assign values to Last Viewed By field and update the record - only concatenate if there is a value there already if(existinglastviewed != null){ o.Last_Viewed_By__c = (existinglastviewed + '; \n' + firstname + ' ' + lastname + ' ' + getLongDate()); } else o.Last_Viewed_By__c = (firstname + ' ' + lastname + ' ' + getLongDate()); update o; } } }
All Answers
something like this should work.
Using the above I get the error:
Error: Compile Error: Method does not exist or incorrect signature: void isEmpty() from the type String at line 22 column 61
I tried replacing with isBlank(), same error - should I have anything in the parameters there ?