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
Suman ChandraSuman Chandra 

please give me tst class for below code

if (selectedAccount == null && ApexPages.currentPage().getParameters().get('id') != null && ApexPages.currentPage().getParameters().get('id') !='') {
                ID accId = ApexPages.currentPage().getParameters().get('id');system.debug('>>accid'+accId );
                String strQuery = 'SELECT Id,Name,BillingStreet,Phone,BillingCity,BillingState,BillingPostalCode,BillingCountry,BIN__c FROM Account WHERE id='+ '\'' + accId +'\'';
                system.debug('>>strQuery'+strQuery);
                selectedAccount = Database.query(strQuery);
            }
Best Answer chosen by Suman Chandra
Azhar Aziz GAzhar Aziz G
Try This one.
Account acc = new Account();
acc.Name = 'Test Account';
insert acc;

Apexpages.CurrentPage().getParameters().put( 'Id' , acc.Id );

// Then Initialize Controller class of page and call the right method If have. 

Thanks,

All Answers

Azhar Aziz GAzhar Aziz G
Try This one.
Account acc = new Account();
acc.Name = 'Test Account';
insert acc;

Apexpages.CurrentPage().getParameters().put( 'Id' , acc.Id );

// Then Initialize Controller class of page and call the right method If have. 

Thanks,
This was selected as the best answer
Bhanu MaheshBhanu Mahesh

Insert Account inyour test class
then pass that account id to the parameter as below
ApexPages.currentPage().getParameters().put('id',AccountId);
(Instanceofyourcontroller).selectedAccount = null;

And call that method in your test class.
Check the below links 
https://developer.salesforce.com/forums/ForumsMain?id=906F000000098ykIAA

https://developer.salesforce.com/forums/ForumsMain?id=906F000000096COIAY

http://salesforce.stackexchange.com/questions/39978/need-help-with-test-class-with-apexpages-currentpage-getparameters-id

Regards,
Bhanu Mahesh
Suman ChandraSuman Chandra
Thanks guys.