2016-05-13 12 views
0

には行いずれかが、このエラーを解決するために私を助けることはできていません:行のリストには、割り当てのための行を持っていないSObjectのリストが割り当て

クラス:

qName = [select Row_Id__c, Name from Ccon__c where Id = :ApexPages.currentPage().getParameters().get('id')].Row_Id__c; 

テストクラスライン:

Controller  controller1  = new Controller(sc1); 

答えて

0

これは、結果が返されないことを意味します(リストが空で、 Sobjectにキャストするときは、取るべき項目はありません)。

qName = [select Row_Id__c, Name from Ccon__c where Id = :ApexPages.currentPage().getParameters().get('id')].Row_Id__c; 

私はそれをこのように(私のIDが有効であればどのような場合には、私は私のクエリから値を取得することを確認する)だろう:あなたはより多くの質問がありましたらお気軽にしてください

Id tempID = null; 
if(ApexPages.currentPage().getParameters().get('id') != null) 
{ 
    tempId = ApexPages.currentPage().getParameters().get('id'); 
} 
else{ //Error management 
} 

List<Ccon__c> recordsToProcess = new List<Ccon__c>(); 

if(tempID != null) 
{ 
    recordsToProcess = [select Row_Id__c, Name from Ccon__c where Id = :tempID]; 
} 
else{ //Error management 
} 


//qName Declaration 
if(!recordsToProcess.isEmpty()) 
{ 
    qName = recordsToProcess[0].Row_Id__c; 
} 
else{ //Error management 
} 

if(qName == null) 
{ 
    //Error management 
} 

を聞いてください。しかし、ベストプラクティスとして、レコードを返す前にリストが空でないことを常に確認することができます。

ありがとう HqSeO