• Mikhail Nitko 6
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi folks,

I'm new to writing test classes and have put together a simple, working apex class but am not sure how to test it.

I am currently working through the Trailhead and am still confused.

How would I write a test for the following?:
 
public class studentQueueUMB {

List<Case> walkin;


public List<Case> getWalkin(){
walkin =  [SELECT Display_Name__c, Display_Screen_Suffix__c FROM Case WHERE Origin = 'Walk-in' and Status != 'Closed' and Remove_From_Screen__c = FALSE ORDER BY CreatedDate ASC NULLS FIRST LIMIT 10];

return walkin;
}
}
Thank you!
Hi folks,

I put a custom button on Salesforce cases that both Accepts a case and checks whether it the case is owned by a User or Queue, and gives an error when one user tries to take the case from another User, and not from a Queue.

The trouble is this button only works if one user opens the case after another has accepted it.  But if both users open an unaccepted case, the button will unfortunately allow the case to first be taken by the first person and then the second, without alerting.

The code:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}



if('{!Case.OwnerId}'.substring(0,3)=='005'){
alert("This case is owned by " +'{!Case.Case_Owner_s__c}'+" and is not in a Queue.");
} else 

{

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!$User.Id}';
caseObj.One_Stop_Counter__c = "{!TEXT($User.Assigned_Counter__c)}";
caseObj.Display_Screen_Suffix__c = "see " + '{!User.FirstName}'+" at Counter  "+'{!TEXT($User.Assigned_Counter__c)}';
var result = sforce.connection.update([caseObj]);

if (result[0].success=='false'){
alert(result[0].errors.message);
} else {
window.parent.location.href="/{!Case.Id}";
}
}

My original solution to this was to have the code in the Accept button refresh the page before running its User owner check, but this does not seem to be working either.

I was adding location.reload(true); before the User check.

Can anyone tell me why the refresh solution isn't working, or if there is another way to either do the refresh, or to execute my intentions?
Hi folks,

I'm new to writing test classes and have put together a simple, working apex class but am not sure how to test it.

I am currently working through the Trailhead and am still confused.

How would I write a test for the following?:
 
public class studentQueueUMB {

List<Case> walkin;


public List<Case> getWalkin(){
walkin =  [SELECT Display_Name__c, Display_Screen_Suffix__c FROM Case WHERE Origin = 'Walk-in' and Status != 'Closed' and Remove_From_Screen__c = FALSE ORDER BY CreatedDate ASC NULLS FIRST LIMIT 10];

return walkin;
}
}
Thank you!