I am trying to deploy a change-set which contains 12 new fields from my development environment to my production environment. These are all simple fields, 7 for the account screen and 5 for a custom object called Credit History. I get the error:
DefineOppMPANController.testAdd(); DefineOppMPANController.testCancel(); null, Details: System.QueryException: List has no rows for assignment to SObject Class.DefineOppMPANController.<init>: line 12, column 1 Class.DefineOppMPANController.testAdd: line 102, column 1; System.QueryException: List has no rows for assignment to SObject Class.DefineOppMPANController.<init>: line 12, column 1 Class.DefineOppMPANController.testCancel: line 93, column 1; Average test coverage across all Apex Classes and Triggers is 3%, at least 75% test coverage is required.
I don't understand why it won't let me deploy the fields, as they are just fields. There's no apex code or anything, literally just empty string and number fields. What can I do to get these fields copied over without having to make them manually?
Edit: This is the only test that's running, and the only one that exists.
**
* Determine valid list of potential mpans given an opportunities account(s)
*
* Kent Matheson - EDW Technology 20/03/2009
*/
public class DefineOppMPANController {
public Opportunity o { get; set; }
public List<DTOOppMpanSelection> dtos { get; set; }
public DefineOppMPANController () {
o = [select id, accountid, name from Opportunity where id = :ApexPages.currentpage().getParameters().get('id')];
dtos = setUpFormData();
}
private List<DTOOppMpanSelection> setUpFormData(){
List<DTOOppMpanSelection> dtos = new List<DTOOppMpanSelection>();
List<ID> clan = getClan(o.accountid);
List<Site__C> sites = [SELECT s.id, s.name FROM Site__c s WHERE s.account__c IN :clan];
List<MPAN__c> mpans = [SELECT m.id, m.name, m.mpan_descriptor__c FROM MPAN__c m WHERE m.site_number__C IN :sites ORDER BY m.mpan_descriptor__c];
List<Opportunity_MPAN__c> existingMpans = [SELECT om.MPAN__r.id FROM Opportunity_MPAN__c om WHERE om.opportunity__c = :o.id];
Map<ID, Opportunity_MPAN__c> existingMpanIds = new Map<ID,Opportunity_MPAN__c>();
for(Opportunity_MPAN__c oppmpan: existingMpans){
existingMpanIds.put(oppmpan.MPAN__r.id,
oppmpan);
}
for(MPAN__c mpan: mpans){
if(existingMpanIds.containsKey(mpan.id)){
dtos.add(new DTOOppMpanSelection(o.id, mpan.id, true, mpan.name, mpan.mpan_descriptor__c));
} else{
dtos.add(new DTOOppMpanSelection(o.id, mpan.id, false, mpan.name, mpan.mpan_descriptor__c));
}
}
return dtos;
}
private List<ID> getClan(ID currentId){
List<ID> clan = new List<ID>{};
List<Account> al = new List<Account>{};
List<ID> currentParents = new List<ID>{currentId};
Integer level = 0;
Boolean endOfStructure = false;
// Loop though all kids
while (!endOfStructure ){
if(level==0){
al = [SELECT a.Id FROM Account a WHERE a.id IN :currentParents];
} else {
al = [SELECT a.Id FROM Account a WHERE a.ParentID IN :currentParents];
}
if(al.size() == 0){
endOfStructure = true;
}else {
currentParents.clear();
for (Integer i = 0 ; i < al.size(); i++){
Account a = al[i];
currentParents.add(a.id);
clan.add(a.id);
}
level++;
}
}
return clan;
}
public pageReference save() {
Opportunity_MPAN__c[] to_add = new Opportunity_MPAN__c[] {};
List<Opportunity_MPAN__c> existingMpans = [SELECT om.id FROM Opportunity_MPAN__c om WHERE om.opportunity__c = :o.id];
delete existingMpans;
for(DTOOppMpanSelection dto: dtos){
if(dto.selected){
to_add.add(new Opportunity_MPAN__c( Opportunity__c = dto.oppId, Mpan__c = dto.mpanId));
}
}
insert to_add;
pageReference pr = new pageReference('/'+ o.id);
pr.setredirect(true);
return pr;
}
public pageReference cancel() {
pageReference pr = new pageReference('/'+ o.id);
pr.setredirect(true);
return pr;
}
public static testMethod void testCancel() {
pageReference p = Page.defineOppMpans;
p.getParameters().put('id', '006200000086Zqw' );
test.setCurrentPage( p );
DefineOppMPANController defOMC = new DefineOppMPANController();
defOMC.cancel();
}
public static testMethod void testAdd() {
pageReference p = Page.defineOppMpans;
p.getParameters().put('id', '006200000086Zqw' );
test.setCurrentPage( p );
DefineOppMPANController defOMC = new DefineOppMPANController();
defOMC.save();
}
}