You need to sign in to do that
Don't have an account?
APEX TEST SCRIPT for beginners
hello,
I'm a beginner in terms of apex coding in salesforce. And i had a very urgent requirement from the company i'm working with. Now, i managed to create an apex page and class controller but i couldnt have my test class run successfully. There's no error so far, but there's no message in the Run Test either that it was successful in the Apex test runner.
Here's my code:
--- CONTROLLER---
public with sharing class autoAccountSearchController {
public String strDebug1 {get;set;}
public List<Account> accounts {get;set;}
public autoAccountSearchController()
{
accounts = new List<Account>();
Account a = [select Id, Name from Account limit 1];
}
public PageReference populateAccounts()
{
accounts = [select Id, Name from Account where Name like :(strDebug1 + '%')];
return null;
}
}
--- TEST CLASS----
@isTest
private class testAutoAccountSearch {
static testMethod void mytestAutoAccountSearch () {
// TO DO: implement unit test
Account accounts = new Account(Id = '001f0000008M81y', Name = 'Test', OwnerId='005a0000007nDqPAAU', Site='PH NCR (4thDistrict) -City of Makati' );
testAutoAccountSearch test_a = new testAutoAccountSearch ();
}
}
in Debug log this is what i get:
Debug Log:
26.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
18:11:18.350 (1350393000)|EXECUTION_STARTED
18:11:18.350 (1350429000)|CODE_UNIT_STARTED|[EXTERNAL]|01pf0000000D2f8|testAutoAccountSearch.mytestAutoAccountSearch
18:11:18.355 (1355335000)|METHOD_ENTRY|[2]|01pf0000000D2f8|testAutoAccountSearch.testAutoAccountSearch()
18:11:18.355 (1355349000)|METHOD_EXIT|[2]|testAutoAccountSearch
18:11:18.355 (1355746000)|CONSTRUCTOR_ENTRY|[11]|01pf0000000D2f8|<init>()
18:11:18.355 (1355795000)|CONSTRUCTOR_EXIT|[11]|01pf0000000D2f8|<init>()
18:11:17.554 (1355813000)|CUMULATIVE_LIMIT_USAGE
18:11:17.554|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of code statements: 2 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10
18:11:17.554|CUMULATIVE_LIMIT_USAGE_END
18:11:18.355 (1355840000)|CODE_UNIT_FINISHED|testAutoAccountSearch.mytestAutoAccountSearch
18:11:18.355 (1355846000)|EXECUTION_FINISHED
--------------------
i hope someone will help me with this.
thanks,
cat
Do it like this
@isTest
private class testAutoAccountSearch {
static testMethod void mytestAutoAccountSearch () {
testAutoAccountSearch test_a = new testAutoAccountSearch ();
test_a.strDebug1 = 'Test';
Account accounts = new Account(Id = '001f0000008M81y', Name = 'Test%', OwnerId='005a0000007nDqPAAU', Site='PH NCR (4thDistrict) -City of Makati' );
insert accounts;
test_a.populateAccounts();
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Thank you very much J
If this post helps you then please throw Kudos.If this post solves your problem kindly mark it as solution.
because it will help other developers to go through the thread easily and search for answers and important posts.
Thanks
Hello Souvik,
I'm having error with the variable strDebug1 and the test_a.populateAccount() couldn't find it to the controller i've made.
please help.
:)
My bad :(
Now check
@isTest
private class testAutoAccountSearch {
static testMethod void mytestAutoAccountSearch () {
autoAccountSearchController conObj = new autoAccountSearchController ();
conObj.strDebug1 = 'Test';
Account accounts = new Account(Id = '001f0000008M81y', Name = 'Test%', OwnerId='005a0000007nDqPAAU', Site='PH NCR (4thDistrict) -City of Makati' );
insert accounts;
conObj.populateAccounts();
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Hello,
I'm sorry but could you help me again..
this code couldn't call the pagereference in the controller.
conObj.populateAccounts();
thanks,