You need to sign in to do that
Don't have an account?
TEST CLASS FOR StandardSetController
I have written a piece of code using standardSetController. And also i am writting a test class for it.But the coverage is 0%.Could someone help me.
***********************************Test Class****************************************
@isTest(seeAllData=true)
private class AsssignLead_Test {
static ApexPages.StandardController stdController = null;
static AssignLeadController AssignLeadInstance = null;
static Lead leadObj = new Lead();
static Account customerAccount;
static testMethod void AsssignLead_Test_Platinum() {
User runAsPortalUser = createPortalUser();
system.runAs(runAsPortalUser){
//Create Leads
Lead testLead1;
List<Lead> assignLeadList = new List<Lead>();
User partnerUser = [select Id,ContactId from User where Id=:runAsPortalUser.Id];
Contact partnerCon = [select Id,AccountId from Contact where Id=:partnerUser.ContactId];
Account partnerAcc = [select Id,SFDC_Account_ID__c,name from Account where Id=:partnerCon.AccountId];
String groupName = partnerAcc.Name+':'+partnerAcc.SFDC_Account_ID__c;
Group partnerGroup = [select Id,Name from Group where Type='Queue' and Name=:groupName LIMIT 1];
ALL_NASP_IDs__c naspNew = new ALL_NASP_IDs__c(Name = 'test77',NASP1__c = 'test77',
Branch_Name__c = 'Test Branch AL',GARM_APP_Level__c = 'A16',DUNS_Number__c = '12340007');
Database.insert(naspNew);
//Customer Account Record type
RecordType custaccountRecordType = [select Id,Name from Recordtype where Name = 'Master Account'];
//Create Customer Account
Account customerAccountNew = new Account(Name = 'Test Customer Account 007');
customerAccountNew.Account_NASP_ID__c = naspNew.Id;
customerAccountNew.Organization__c = 'US';
customerAccountNew.billingstreet = 'test Billing Street1';
customerAccountNew.billingcity = 'test Billing City1';
customerAccountNew.billingstate = 'test Billing State1';
customerAccountNew.billingpostalcode = '600080';
customerAccountNew.billingcountry = 'US';
customerAccountNew.Type = 'Customer';
Database.insert(customerAccountNew);
RecordType custLeadRecordType = [select Id,Name from Recordtype where Name = 'PRM Partner Customer Lead'];
testLead1 = new Lead(FirstName = 'Test');
testLead1.LastName = 'Lead1';
testLead1.RecordTypeId = custLeadRecordType.Id;
testLead1.Company = 'Test Company1';
testLead1.Status = 'New';
testLead1.Permission_to_Contact__c = 'Yes';
testLead1.Phone = '9999999976';
testLead1.Street = 'Test street';
testLead1.City = 'Test City';
testLead1.Country = 'Test Country';
testLead1.PostalCode = '123456';
testLead1.Email = 'test@lead1.com';
testLead1.PRM_Routing_Tier__c = 'Platinum';
testLead1.Decision_Maker__c = true;
testLead1.Close_Date__c = system.today();
testLead1.Product_Solution__c = 'Test Pillar';
testLead1.Account__c = customerAccountNew.Id;
assignLeadList.add(testLead1);
Database.insert(assignLeadList);
PageReference pg = Page.AssignLeadPage;
Test.setCurrentPageReference(pg);
for(Lead leadObjNew : assignLeadList){
ApexPages.currentPage().getParameters().put('id',leadObjNew.Id);
stdController = new ApexPages.StandardController(leadObjNew);
AssignLeadInstance = new AssignLeadController(stdController);
}
ApexPages.StandardSetController setController = AssignLeadInstance.setCon;
AssignLeadInstance.first();
AssignLeadInstance.last();
Boolean testVariable;
testVariable = AssignLeadInstance.hasNext;
testVariable = AssignLeadInstance.hasPrevious;
AssignLeadInstance.doUpdateLeadOwner();
}
}
/********************* ***********************/
public static User createPortalUser(){
User portalUser = null;
UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1];
//Interface Profile
Profile profile = [select id from profile where name='Vz Interface Profile'];
//Portal Profile
Profile portalProfile = [select id from profile where name='Vz PRM Super User'];
//Create Interface User
User user = new User(alias = 'testUser',email='test123@noemail.com', emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US', localesidkey='en_US', profileid =profile.Id, country='United States',
timezonesidkey='America/Los_Angeles',Total_Chatter_posts__c='123', username='test123@noemail.com',Enterprise_Id__c='222',GARM_APP_level__c='A168',One_World_ID__c='3333',VZ_ID__c='33333',One_World_Number__c='22222',UserRoleId = portalRole.Id);
Database.insert(user);
//Run as Interface user
System.runAs(user){
//Create NASP for partner Account
ALL_NASP_IDs__c nasp2 = new ALL_NASP_IDs__c(Name = 'test22',NASP1__c = 'test22',
Branch_Name__c = 'testbranch2',GARM_APP_Level__c = 'A168',DUNS_Number__c = '12351235');
Database.insert(nasp2);
//Partner Account Record Type
RecordType accountRecordType = [select Id,Name from Recordtype where Name = 'PRM Partner Account'];
//Create Partner Account
Account account = new Account(name = 'Partner Account Test 007');
account.RecordTypeId = accountRecordType.Id;
account.phone = '9999999999';
account.Organization__c='Partner';
account.ova_id__c = 'test OVAID';
account.ovi_id__c = 'test OVIID';
account.d_u_n_s__c = '100100100';
account.guduns__c = 'test GUDUNS';
account.billingstreet = 'test Billing Street';
account.billingcity = 'test Billing City';
account.billingstate = 'test Billing State';
account.billingpostalcode = '600000';
account.billingcountry = 'US';
account.Module_ID_AEDW__c = 'MMM';
account.Type = 'Partner';
account.Partner_Tier__c = 'Platinum';
account.Partner_Approval_Status__c = 'Approved';
Database.insert(account);
//Partner Checks for the Partner Account
RecordType partnerChecksRecTypeOFAC = [select Id,Name from Recordtype where Name = 'OFAC'];
RecordType partnerChecksRecTypeFinancial = [select Id,Name from Recordtype where Name = 'Financial'];
RecordType partnerChecksRecTypeLegal = [select Id,Name from Recordtype where Name = 'Legal'];
Checks__c partnerChecksOFAC = new Checks__c(Status__c = 'Approved',Check_Type__c = 'OFAC',Account__c = account.Id,Completion_Date__c = system.today());
Checks__c partnerChecksLegal = new Checks__c(Status__c = 'Approved',Check_Type__c = 'Legal',Account__c = account.Id,Completion_Date__c = system.today());
Checks__c partnerChecksFinancial = new Checks__c(Status__c = 'Approved',Check_Type__c = 'Financial',Account__c = account.Id,Completion_Date__c = system.today());
List<Checks__c> partnerChecks = new List<Checks__c>();
partnerChecks.add(partnerChecksOFAC);
partnerChecks.add(partnerChecksLegal);
partnerChecks.add(partnerChecksFinancial);
Database.insert(partnerChecks);
//Partner Contact
RecordType partnerContactRecType = [select Id,Name from Recordtype where Name = 'PRM Partner User'];
//Partner Contact
Contact contact = new Contact(
FirstName = 'Test Partner',
Lastname = 'Contact',
accountId = account.Id,
Email = 'test@partnercontact.com',
RecordTypeId = partnerContactRecType.Id,
Title = 'Programmer'
//Date_of_Birth__c = '06/06/1984',
//Account_Type__c = 'Partner'
);
Database.insert(contact);
//Create Portal User
portalUser = new User(
Username = 'test500077@test.com',
ContactId = contact.Id,
ProfileId = portalProfile.Id,
Alias = 'test123',
Email = 'test12345@test.com',
EmailEncodingKey = 'UTF-8',
LastName = 'Partner Contact',
CommunityNickname = 'test12345',
TimeZoneSidKey = 'America/Los_Angeles',
LocaleSidKey = 'en_US',
LanguageLocaleKey = 'en_US',
Enterprise_ID__c= '0021374513',
VZ_ID__c= '0029333',
One_World_Number__c = '046171256',
GARM_APP_level__c = 'A168',
One_World_ID__c='002335',
IsActive=true,
Sales_Team_Role__c = 'Partner');
Database.insert(portalUser);
system.runAS(portalUser){
portalUser.IsPortalEnabled = true;}
Group objgroup = new Group();
objgroup.Name = account.name +':'+account.SFDC_Account_ID__c;
objgroup.Type = 'Regular';
Database.insert(objgroup);
Group objgroupnew = new Group();
objgroupnew.Name = account.name +':'+account.SFDC_Account_ID__c;
objgroupnew.Type = 'Queue';
Database.insert(objgroupnew);
QueueSObject objQue = new QueueSObject();
objQue.SobjectType='Lead';
objQue.QueueId=objgroupnew.Id;
Database.insert(objQue);
//Partner Authorization Recordtype
RecordType paMSA = [select Id,Name from RecordType where Name = 'MSA'];
Partner_Contract__c contract1 = new Partner_Contract__c(RecordTypeId = paMSA.Id,Partner_Account__c = account.Id,Contract_Start_Date__c = system.today(),Contract_End_Date__c = system.today()+100,
Type_of_Contract__c = 'MSA',
VzB_Signer__c=user.id,
VzW_Signer__c=user.id,
Terremark_Signer__c=user.id);
Database.insert(contract1);
// create a Partner Branch in branch Geo Region
Branch_Geo_Region__c BranchGeo = new Branch_Geo_Region__c(
Name = 'Test Branch AL',
Branch_Name_Unique__c = 'Test Branch AL',
Geo_Region__c = 'US',
Segment__c = 'All');
Database.insert(BranchGeo);
system.debug('BranchGeoRegion***'+BranchGeo);
// Select the above created branch in partner branch object
Partner_Branch__c PartnerBranch = new Partner_Branch__c(
Associated_Partner_Contract__c = contract1.Id,
Partner_Account__c = account.Id,
Branch_Geo_Region__c = BranchGeo.Id);
Database.insert(PartnerBranch);
system.debug('PartnerBranch***'+PartnerBranch);
Partner_Branch__c objPartnerbranch = [Select Id, Branch_Geo_Region__c, Branch_Name__c, Branch_Name_Text__c, Partner_Account__c from Partner_Branch__c where Id =:PartnerBranch.Id];
system.debug('PartnerBranchObject***'+objPartnerbranch);
Partner_Pillar__c partnerPillar = new Partner_Pillar__c(Name = 'Test Pillar');
Database.insert(partnerPillar);
Partner_Product_Pillar__c partnerProductPillar = new Partner_Product_Pillar__c(
Partner_Contract__c = contract1.Id,
Partner_Pillar__c = partnerPillar.Id);
Database.insert(partnerProductPillar);}
return portalUser; }
public static Account createCustomerAccount(){
User portaluser = createPortalUser();
Profile profile = [select id from profile where name='Vz Interface Profile'];
User user = new User(alias = 'testUser',email='test123@noemail.com', emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US', localesidkey='en_US', profileid =profile.Id, country='United States',
timezonesidkey='America/Los_Angeles',Total_Chatter_posts__c='123', username='test123@noemail.com',Enterprise_Id__c='222',GARM_APP_level__c='A168',One_World_ID__c='3333',VZ_ID__c='33333',One_World_Number__c='22222');
Database.insert(user);
system.runAs(user){
//Create NASP for Customer Account
ALL_NASP_IDs__c nasp1 = new ALL_NASP_IDs__c(Name = 'test11',NASP1__c = 'test11',
Branch_Name__c = 'testbranch1',GARM_APP_Level__c = 'A16',DUNS_Number__c = '12341234');
Database.insert(nasp1);
//Customer Account Record type
RecordType custaccountRecordType = [select Id,Name from Recordtype where Name = 'Master Account'];
//Create Customer Account
customerAccount = new Account(Name = 'Test Customer Account');
customerAccount.Account_NASP_ID__c = nasp1.Id;
customerAccount.Organization__c = 'US';
customerAccount.billingstreet = 'test Billing Street';
customerAccount.billingcity = 'test Billing City';
customerAccount.billingstate = 'test Billing State';
customerAccount.billingpostalcode = '600000';
customerAccount.billingcountry = 'US';
customerAccount.Type = 'Customer';
Database.insert(customerAccount);}
return customerAccount;}}