• crob1212
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 3
    Replies

Sorry...here is the code in a more legible format (p.s. I don't recommend using Chrome when posting messages including code.  Somehow the formatting of the code gets lost when the message is posted)

 

 

@isTest private class TestHoldAddressedOnCase { public static testMethod void testHoldAddressed() { //set up user User u = [ SELECT id FROM User WHERE alias='auser' LIMIT 1]; //Run as u System.RunAs(u) { //create a Request Request__c r = new Request__c (MRCProject__c='a0F700000028Eb5', Group__c='00G70000001CnPEEA0',Subject__c='a0270000005GLDl', Custodian_Lookup__c='0017000000YN7Mt', Record_Type__c='Academic', Status__c='10-Request Sent', Case_Priority__c='P4', Method_of_Authorization__c='Blank Auth', Source__c='Client'); insert r; //verify the request was created correctly. r = [ SELECT Id, Hold_Addressed__c FROM Request__c WHERE Id = :r.Id LIMIT 1]; system.assertEquals(FALSE, r.Hold_Addressed__c); //Create the Case (Client Directive) string testCase = 'Test Case'; Case c = new case (RecordTypeId='01270000000LtyP', Status = 'Unassigned', Related_Subject__c='a0270000005GLDl', Request__c=r.Id,Hold_Addressed__c = TRUE); //Cause the trigger to execute. insert c; //Verify that the request was updated. r = [ SELECT Id, Hold_Addressed__c FROM Request__c WHERE Id = :c.Id]; System.assertEquals(c.Hold_Addressed__c, r.Hold_Addressed__c); } } }

 

 

 

 

Hello All,

I am new to Apex and I'm pulling my hair out trying to figure out what is wrong with my code.  In a nutshell, there is a field in the Case object called Hold_Addressed__c, which is a checkbox field.  And there is a field with the same name (Hold_Addressed__C) on a custom object called Request__c.  I've written a trigger that populates the field on the custom object with the value of the field on the case.  So, if case.Hold_Addressed__c = TRUE then Request__r.Hold_Addressed__c = TRUE; same for FALSE.  The trigger is working great.  But the test class is not.  I'm getting an error stating "System.QueryException: List has no rows for assignment to SObject".  Can anyone help with this?  Many Thanks.

Here is the test class:

 

 

@isTestprivate class TestHoldAddressedOnCase{ public static testMethod void testHoldAddressed() { //set up user User u = [ SELECT id FROM User WHERE alias='auser' LIMIT 1]; //Run as u System.RunAs(u) { //create a Request Request__c r = new Request__c (MRCProject__c='a0F700000028Eb5', Group__c='00G70000001CnPEEA0',Subject__c='a0270000005GLDl', Custodian_Lookup__c='0017000000YN7Mt', Record_Type__c='Academic', Status__c='10-Request Sent', Case_Priority__c='P4', Method_of_Authorization__c='Blank Auth', Source__c='Client'); insert r; //verify the request was created correctly. r = [ SELECT Id, Hold_Addressed__c FROM Request__c WHERE Id = :r.Id LIMIT 1]; system.assertEquals(FALSE, r.Hold_Addressed__c); //Create the Case (Client Directive) string testCase = 'Test Case'; Case c = new case (RecordTypeId='01270000000LtyP', Status = 'Unassigned', Related_Subject__c='a0270000005GLDl', Request__c=r.Id,Hold_Addressed__c = TRUE); //Cause the trigger to execute. insert c; //Verify that the request was updated. r = [ SELECT Id, Hold_Addressed__c FROM Request__c WHERE Id = :c.Id]; System.assertEquals(c.Hold_Addressed__c, r.Hold_Addressed__c); } } }

 


 

Message Edited by crob1212 on 03-06-2010 06:12 AM
Message Edited by crob1212 on 03-06-2010 06:25 AM
Good news regarding the BR() function: We have changed the behavior so that it inserts a new line character rather than the dreaded _BR_ENCODED_.

You should now be able to compose formulas in Workflow Field Update & Default Value formulas like

Code:
MailingStreet & BR() &
MailingCity & ", " & MailingState & " " & MailingPostalCode & BR() &
MailingCountry

This fix is now live, so give it a try.

Regards,
Eric