function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Novo_ArtisNovo_Artis 

Apex Custom Controller Testing

Here is my custom controller class, it saves OK untill I add the if statements (just goes below the %75 test threshold when i do.

[The queries have been made blank for the purpose of this pos]

public with sharing class DispatchAdvice {
private final Account account;
private final Orderc__c order;
private final List<Orderc__c> orderList;
private final String vendor;

public DispatchAdvice() {
vendor = 'fail';
account = [];
orderList = Database.query('');
order = Database.query('');

if(account.Name.contains('AAA')) vendor = 'BBB';
else if(account.Name.contains('CCC')) vendor = 'DDD';
}

public Account getAccount() {
return account;
}
public List<Orderc__c> getOrderList() {
return orderList;
}
public Orderc__c getOrder() {
return order;
}
public String getVendor() {
return vendor;
}
}

I have been searching the document/forums/internet and cant figure this out...
Most solutions point to creating a testing class like so.

@isTest
private class DispatchAdviceTester {
static testMethod void testConstructor(){
DispatchAdvice da = new DispatchAdvice();
system.assert(true);
}
}

But when I try save this class I get the error
"Save error: Unable to perform save on all files: An unexpected error has occurred. Please try again, or check the log file for details. DispatchAdviceTester.cls line 1 Force.com save problem"

 

Any help would be great, thanks.

 

David VPDavid VP

If you want your 'if' statements to be covered by the test methods you need to make sure to set up test accounts where name contains 'AAA' and also some where name contains 'BBB' in your test class and insert them (don't worry, they won't be saved in your org).

Also : call your getter methods in your test class. You're only testing the constructor.

 

Check out :

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

 

Novo_ArtisNovo_Artis

Thanks for you help but im starting to think there is a strange problem with my IDE.
A number of classes/triggers are not saving due to "An unexpected error"

Kinda of getting off topic almost, but look...

I get the exact same "unexpected save error"

trigger emailSender on Test_Object__c (after update) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setOrgWideEmailAddressId('XXXXXXXXXXXXXXX');
String[] toAddresses = new String[] {'test@mail.com'};
mail.setToAddresses(toAddresses);
mail.setSenderDisplayName('Test Tester');
mail.setSubject('Yellow');
mail.setPlainTextBody('Hi');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

 

EDIT: OK PROBLEM SOLVED.
Bad case of salesforce throwing usless error descriptions in production environment.

Solution to the email error: Cant set a sender display name when using an org wide email address...

 

So now Im guessing the original post's solution is some simple yet hidden error.

Message Edited by Novo_Artis on 10-11-2009 07:18 PM