You need to sign in to do that
Don't have an account?

test Class
public with sharing class ApexButtonGetDist{
public static Opportunity theOpportunity = new Opportunity();
public static Opportunity theOpportunity2 = new Opportunity();
public static Account getDistributor = new Account();
public ApexButtonGetDist(ApexPages.StandardController stdController){
theOpportunity = (Opportunity)stdController.getRecord();
}
public PageReference dologic() {
theOpportunity2 = [SELECT ID, Name, customfiled__c from Opportunity where Id = :theOpportunity.Id];
getDistributor = [SELECT ID, Name, BillingStreet,BillingState,BillingCity,BillingPostalCode from Account where Id = :theOpportunity2.customfiled__c];
theOpportunity.customfiled1__c = getDistributor.BillingStreet;
theOpportunity.customfiled2__c = getDistributor.BillingCity;
theOpportunity.customfiled3__c= getDistributor.BillingState;
theOpportunity.customfiled4__c = getDistributor.BillingPostalCode;
update theOpportunity;
return new PageReference('/' + theOpportunity.ID);
}
}
Test Class:
@isTest
private class ApexButtonGetDistTest {
static testmethod void testApexButtonGetDist(){
opportunity opps = new opportunity();
Opportunity opp = new Opportunity();
opp.Name = 'Test opp';
opp.StageName = 'Test Stage';
opp.CloseDate = date.today();
insert opp;
PageReference pr = new PageReference(opp.ID);
Test.setCurrentPage(pr);
ApexPages.StandardController controller = new ApexPages.StandardController(opps);
Test.startTest();
ApexButtonGetDist ABG = new ApexButtonGetDist(controller);
Test.stopTest();
}
}
You haven't posted a question - were you just showing us your code or is there something you would like help with ?
I am having trouble to get the test coverage for the doMyApexLogic()
Not sure, how to test the
public PageReference doMyApexLogic() {
theOpportunity2 = [SELECT ID, Name, Distributor_Name__c from Opportunity where Id = :theOpportunity.Id];
getDistributor = [SELECT ID, Name, BillingStreet,BillingState,BillingCity,BillingPostalCode from Account where Id = :theOpportunity2.Distributor_Name__c];
theOpportunity.Dist_street__c = getDistributor.BillingStreet;
theOpportunity.Dist_City__c = getDistributor.BillingCity;
theOpportunity.Dist_State__c = getDistributor.BillingState;
theOpportunity.Dist_PostalCode__c = getDistributor.BillingPostalCode;
update theOpportunity;
return new PageReference('/' + theOpportunity.ID);
}
}
When use ABG.doMyApexLogic(); it's throughing error "LIST has no records" but not sure how to pass the values to the this method.
Can you point me to where I am doing wrong?
Thanks,
You are passing a new instance of an opportunity to the controller, so this won't have an id for your query in the constructor.