You need to sign in to do that
Don't have an account?
Shane Jay Hayes
Little help with test class "Invalid type" error. I'm ALMOST there!
I have a couple of nearly identical Apex classes that I am trying to get test classes done for. Each uses a different object. I was able to the the one that calls on the Account to work perfectly. Now I am just trying to tweak it to get the other one that calls on a custom object to work equally perfect. I keep getting an "invalid type" error. Okay so here is the class I am trying to write the test class for:
Here is the class I successfully wrote the test class for:
Here is the SUCCESSFUL test class (100% coverage)
I am trying to tweak that successful test class for the first class above (the CauseLossControllerEXT)
I got this far, below, but I know I have something wrong with the tweak. Getting "invalid type" error on line 5
Any help is greatly appreciated.
public class CauseLossControllerEXT { public blob picture { get; set; } public String errorMessage { get; set; } public Attachment newAttach {get; set;} private final Claims__c claim; private final String ERROR_IMG_TYPE = 'The image must be in .jpg, .gif or .png format'; private Set<String> imagesTypes = new Set<String> {'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'}; private Set<String> notAllowedTypes = new Set<String> {'application/octet-stream'}; private ApexPages.StandardController stdController; public CauseLossControllerEXT(ApexPages.StandardController stdController) { this.claim = (Claims__c)stdController.getRecord(); this.stdController = stdController; } public PageReference save() { errorMessage = ''; try { upsert claim; if (picture != null) { Attachment attachment = new Attachment(); attachment.body = picture; attachment.name = 'causeofloss_' + claim.id; attachment.Description = 'Cause of Loss Photo'; attachment.parentid = claim.id; insert attachment; claim.CauseofLossURL__c = '/servlet/servlet.FileDownload?file=' + attachment.id; update claim; } return new ApexPages.StandardController(claim).view(); } catch(System.Exception ex) { errorMessage = ex.getMessage(); return null; } } }
Here is the class I successfully wrote the test class for:
public class CompanyLogoControllerEXT { public blob picture { get; set; } public String errorMessage { get; set; } public Attachment newAttach {get; set;} private final Account account; private final String ERROR_IMG_TYPE = 'The image must be in .jpg, .gif or .png format'; private Set<String> imagesTypes = new Set<String> {'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'}; private Set<String> notAllowedTypes = new Set<String> {'application/octet-stream'}; private ApexPages.StandardController stdController; public CompanyLogoControllerEXT(ApexPages.StandardController stdController) { this.account = (Account)stdController.getRecord(); this.stdController = stdController; } public PageReference save() { errorMessage = ''; try { upsert account; if (picture != null) { Attachment newAttach = new Attachment(); newAttach.body = picture; newAttach.name = 'companylogo_' + account.id; newAttach.Description = 'Company Logo'; newAttach.parentid = account.id; insert newAttach; account.CompLogoURL__c = '/servlet/servlet.FileDownload?file=' + newAttach.id; update account; } return new ApexPages.StandardController(account).view(); } catch(System.Exception ex) { errorMessage = ex.getMessage(); return null; } } }
Here is the SUCCESSFUL test class (100% coverage)
@isTest public class CompanyLogoControllerEXTTest { @isTest static void testCompanyLogo() { Account acc=new Account(); acc.Name='testAcc'; ApexPages.StandardController sc = new ApexPages.StandardController( acc ); CompanyLogoControllerEXT comp=new CompanyLogoControllerEXT(sc); String str='testblob'; comp.picture=Blob.valueof(str); comp.save(); delete acc; comp.save(); } }
I am trying to tweak that successful test class for the first class above (the CauseLossControllerEXT)
I got this far, below, but I know I have something wrong with the tweak. Getting "invalid type" error on line 5
@isTest public class CauseLossControllerEXTtest { @isTest static void testCauseLoss() { Claims__C acc=new claim(); acc.Name='testAcc'; ApexPages.StandardController sc = new ApexPages.StandardController( acc ); CauseLossControllerEXT comp=new CauseLossControllerEXT(sc); String str='testblob'; comp.picture=Blob.valueof(str); comp.save(); delete acc; comp.save(); } }
Any help is greatly appreciated.
All Answers
Claims__C acc=new claim();
to
Claims__C acc=new claim__c();
Try:
Claims__C acc=new claims__c(); // it should be the object api name
Try the below version
If you see any errors, due to lack of data, try to accomodate whats missing and you should be fine
Let me know if it fails, and you cant figure it out why!
Thanks,
Balaji