• Pete Rudd
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies

I am a system admin and not a developer. I need help with test code that is not working.

 

I downloaded a free App off the AppExchange called AttachmentSaver. (This stops users, except system admins, from deleting Attachments.) The test code coverage is only reaching 50% as the test is failing at line 11. Can anyone tell me what needs to be amended so that it works?

 

@isTest
private class TestAttachmentSaver {
 
  /**
  * Verify that Standard User profiles are unable to delete attachments
  */
  static testMethod void testStandardUser() {
   
    // Create a new user with the Standard User profile
    Profile standardProf = [select id from profile where name='Standard User'];
    User su = new User(alias = 'standt', email='standarduser@testorg.com',
      emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
      localesidkey='en_US', profileid = standardProf.Id,
timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com');
     
    // Switch current user to Standard User
    System.runAs(su) {   
   
      // Create test data (a new Account with an Attachment)
      Account acct = new Account(Name = 'Test Account');
      insert acct;
      Blob attachBody = Blob.valueOf('attachment body');
      Attachment attach = new Attachment(Name = 'TestAttachment', ParentId = acct.Id, Body = attachBody);
      insert attach;
   
      // Verify the "Unable to delete attachments" error is thrown when attachment is deleted
      Boolean errorThrown = false;
      try {
        delete attach;
      } catch (Exception e) {
        System.debug(e);
        if (e.getMessage().contains('Unable to delete attachments.')) {
          errorThrown = true;
        }
      }
      System.assert(errorThrown);
        }
  }
 
  static testMethod void testAdminUser() {
   
    // Next make sure that a System Admin *can* delete an attachment
    Profile adminProf = [select id from profile where name='System Administrator'];
    User au = new User(alias = 'admint', email='adminuser@testorg.com',
      emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
      localesidkey='en_US', profileid = adminProf.Id,
      timezonesidkey='America/Los_Angeles', username='adminuser@testorg.com');
   
    // Switch current user to System Admin user
    System.runAs(au) {
     
      // Create test data (a new Account with an Attachment)
      Account acct = new Account(Name = 'Test Account');
      insert acct;
      Blob attachBody = Blob.valueOf('attachment body');
      Attachment attach = new Attachment(Name = 'TestAttachment', ParentId = acct.Id, Body = attachBody);
      insert attach;
     
      // Verify that no error is thrown when the attachment is deleted
      Boolean errorThrown = false;
      try {
        delete attach;
      } catch (Exception e) {
        System.debug(e);
        errorThrown = true;
      }
      System.assert(!errorThrown);
    }
  }

 

 

I have posted this question before but didn't word it very well so didn't get the type of answer I was looking for (though some helpful person did provide an alternative solution.)

 

I have a button on Lead page layout that takes the user to a VF page. The standard controller for the VF page is Lead.

 

One of the fields on Leads is Status (which is a picklist).

 

My end goal is to test if the value of Lead Status on the current record is a certain value ("Pending") and if it is the to change it to a differnt value ("Working On") when the save button on the VF page is clicked

 

I want to know 2 things:

 

1) How do I reference the Lead Status field in my Javascript code? (I am currently trying to write an IF statement that says IF Lead Status ="Pending" change Lead Status to "Working On" but I cannot get the value from the field into my Javascript code. E.g. If I was trying to assign the Status value to a var in the code what would it look like: var currentStatus = ???)

 

2) Can I write an IF statement directly into the Apex tag? (E.g.

 

<apex:selectList value="{!Lead.Status}" >     

<apex:selectOption itemValue="IF ????

 

Thanks.

Peter

I have a button on the standard Leads page that opens a VF page.

 

If (and only if) the Lead Status field is still on the option "Pending" (the default) I would like this value to change to "Working On"

 

How do I do this?

 

Also when I click the save button on my VF page is it possible to get the actions behind a different button on the Leads page to perform it's action? (It opens up a report.)

 

Thanks in advance.

Peter

I have been advised I need an Apex Trigger.

 

I have a custom field on both Accounts and Leads (text field) called Reg Num and I also have another custom field (check-box) on Leads called Reg Num matches an account.

I would like the check-box to show a tick if the Reg Num on the Lead matches the Reg Num of any account.

How / where do I do this?

Thanks in advance.

I have posted this question before but didn't word it very well so didn't get the type of answer I was looking for (though some helpful person did provide an alternative solution.)

 

I have a button on Lead page layout that takes the user to a VF page. The standard controller for the VF page is Lead.

 

One of the fields on Leads is Status (which is a picklist).

 

My end goal is to test if the value of Lead Status on the current record is a certain value ("Pending") and if it is the to change it to a differnt value ("Working On") when the save button on the VF page is clicked

 

I want to know 2 things:

 

1) How do I reference the Lead Status field in my Javascript code? (I am currently trying to write an IF statement that says IF Lead Status ="Pending" change Lead Status to "Working On" but I cannot get the value from the field into my Javascript code. E.g. If I was trying to assign the Status value to a var in the code what would it look like: var currentStatus = ???)

 

2) Can I write an IF statement directly into the Apex tag? (E.g.

 

<apex:selectList value="{!Lead.Status}" >     

<apex:selectOption itemValue="IF ????

 

Thanks.

Peter

I have a button on the standard Leads page that opens a VF page.

 

If (and only if) the Lead Status field is still on the option "Pending" (the default) I would like this value to change to "Working On"

 

How do I do this?

 

Also when I click the save button on my VF page is it possible to get the actions behind a different button on the Leads page to perform it's action? (It opens up a report.)

 

Thanks in advance.

Peter

I have been advised I need an Apex Trigger.

 

I have a custom field on both Accounts and Leads (text field) called Reg Num and I also have another custom field (check-box) on Leads called Reg Num matches an account.

I would like the check-box to show a tick if the Reg Num on the Lead matches the Reg Num of any account.

How / where do I do this?

Thanks in advance.