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
Gabe Rothman 8Gabe Rothman 8 

Help: getting "list has no rows for assignment" error, but debug log says otherwise...

Hey all, I have two custom objects: Feature__c and Feature_Request__c.  Feature__c is the parent object in a master-detail relationship with Feature_Request__c.  When a Feature__c's status is update to "Accepted" I need to update two lookups on all of the Feature__c's child Feature_Request__c's. First I need to clear out the the Proposed_Feature__c lookup and then I need to populate the Feature__c master-detail with the id of the record that was previously populated in the Proposed_Feature__c lookup. As far as I can tell my code should work, but I keep getting a "list has no rows for assignment" error despite the debug log saying that all of my lists are populated. I've posted the code and the debug log below.  Any help would be greatly appreciated.

Trigger:
trigger Feature on Feature__c (after update) {

    if(trigger.isAfter && trigger.isUpdate){
        for(Feature__c f : trigger.new){
            if(f.Status__c == 'Accepted'){
	   updateFrsFromApprovedFeature.updateFeatureRequests(updateFrsFromApprovedFeature.filterFeature(trigger.oldmap,trigger.new));                
            }
        } 
    }
    
}

Helper Class:
public class updateFrsFromApprovedFeature {

    public static list<Feature__c> filterFeature(map<id, Feature__c> oldMap, list<Feature__c> newList) {
        list<Feature__c> temp=new list<Feature__c>();
        for (Feature__c newFeat : newList)    {
            if (oldMap.get(newFeat.id).Status__c != newFeat.Status__c && newFeat.Status__c == 'Accepted'){
                temp.add(newFeat);
            }
        }
        return temp;
    }

    public static void updateFeatureRequests(list<Feature__c> frUpdateList) {
        Feature__c featproxy = [SELECT Id, Status__c
                                FROM Feature__c
                                WHERE Id in: frUpdateList];
system.debug(featproxy);
        List<Feature_Request__c> frs = [SELECT Feature__c, Proposed_Feature__c
                                        FROM Feature_Request__c
                                        WHERE Proposed_Feature__c =: featproxy.id];
system.debug(frs);        
        List<Feature_Request__c> updateFrs = new list<Feature_Request__c>();
        for(Feature_Request__c updatefr : frs){
            updatefr.Feature__c = featproxy.Id;
            updatefr.Proposed_Feature__c = null;
            updateFrs.add(updatefr);
        }
system.debug(updateFrs);        
        If(updateFrs.size()>0){
	        update updateFrs;               
        } 
    }
    	
}

Debug Statements:
09:10:30:109 USER_DEBUG [17]|DEBUG|Feature__c:{Id=a11i000000CcIJYAA3}
09:10:30:114 USER_DEBUG [21]|DEBUG|(Feature_Request__c:{Feature__c=a11i000000CdxuPAAR, Proposed_Feature__c=a11i000000CcIJYAA3, Id=a10e0000002L7K4AAK}, Feature_Request__c:{Feature__c=a11i000000CdxuPAAR, Proposed_Feature__c=a11i000000CcIJYAA3, Id=a10e0000002L7K9AAK})
09:10:30:115 USER_DEBUG [28]|DEBUG|(Feature_Request__c:{Feature__c=a11i000000CcIJYAA3, Proposed_Feature__c=null, Id=a10e0000002L7K4AAK}, Feature_Request__c:{Feature__c=a11i000000CcIJYAA3, Proposed_Feature__c=null, Id=a10e0000002L7K9AAK})

Link to Complete Debug Log: https://docs.google.com/document/d/1S7n2LWqWfG7NU97sJ9E1ZAooIwDdiHiTpgEyWShzHXg/edit?usp=sharing

 
Best Answer chosen by Gabe Rothman 8
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
public class updateFrsFromApprovedFeature {

    public static list<Feature__c> filterFeature(map<id, Feature__c> oldMap, list<Feature__c> newList) {
        list<Feature__c> temp=new list<Feature__c>();
        for (Feature__c newFeat : newList)    {
            if (oldMap.get(newFeat.id).Status__c != newFeat.Status__c && newFeat.Status__c == 'Accepted'){
                temp.add(newFeat);
            }
        }
        return temp;
    }

    public static void updateFeatureRequests(list<Feature__c> frUpdateList) 
	{
	
		Feature__c featproxy;
        List<Feature__c> lstfeatproxy = [SELECT Id, Status__c
                                FROM Feature__c
                                WHERE Id in: frUpdateList];
		if(lstfeatproxy.size() > 0)
		{
			featproxy =lstfeatproxy[0];
        
			List<Feature_Request__c> frs = [SELECT Feature__c, Proposed_Feature__c
											FROM Feature_Request__c
											WHERE Proposed_Feature__c =: featproxy.id];
			List<Feature_Request__c> updateFrs = new list<Feature_Request__c>();
			for(Feature_Request__c updatefr : frs){
				updatefr.Feature__c = featproxy.Id;
				updatefr.Proposed_Feature__c = null;
				updateFrs.add(updatefr);
			}
			system.debug(updateFrs);        
			If(updateFrs.size()>0){
				update updateFrs;               
			}
		}	
    }
    	
}
Please let us know if this will help u
Thanks
Amit Chaudhary
 

All Answers

Gabe Rothman 8Gabe Rothman 8
One more thng.  Here is the relevant section of the complete debug log where it says my list is empty:
 
09:10:30.246 (246839835)|STATEMENT_EXECUTE|[5]
09:10:30.246 (246859285)|SYSTEM_METHOD_ENTRY|[6]|Map<Id,Feature__c>.get(Object)
09:10:30.246 (246875117)|SYSTEM_METHOD_EXIT|[6]|Map<Id,Feature__c>.get(Object)
09:10:30.246 (246893382)|STATEMENT_EXECUTE|[6]
09:10:30.246 (246900442)|SYSTEM_METHOD_ENTRY|[5]|system.ListIterator.hasNext()
09:10:30.246 (246910945)|HEAP_ALLOCATE|[5]|Bytes:5
09:10:30.246 (246918236)|SYSTEM_METHOD_EXIT|[5]|system.ListIterator.hasNext()
09:10:30.246 (246932126)|VARIABLE_ASSIGNMENT|[5]|newFeat|null|
09:10:30.246 (246937573)|STATEMENT_EXECUTE|[10]
09:10:30.246 (246945114)|METHOD_EXIT|[6]|01pe0000000PkIV|updateFrsFromApprovedFeature.filterFeature(Map<Id,Feature__c>, List<Feature__c>)
09:10:30.246 (246953506)|METHOD_ENTRY|[6]|01pe0000000PkIV|updateFrsFromApprovedFeature.updateFeatureRequests(List<Feature__c>)
09:10:30.246 (246958726)|VARIABLE_SCOPE_BEGIN|[13]|frUpdateList|List<Feature__c>|true|false
09:10:30.246 (246973304)|VARIABLE_ASSIGNMENT|[13]|frUpdateList|{"s":1,"v":[]}|0x6a7b025c
09:10:30.246 (246979589)|STATEMENT_EXECUTE|[13]
09:10:30.246 (246982103)|STATEMENT_EXECUTE|[14]
09:10:30.246 (246991930)|HEAP_ALLOCATE|[14]|Bytes:4
09:10:30.247 (247216743)|SOQL_EXECUTE_BEGIN|[14]|Aggregations:0|SELECT Id FROM Feature__c WHERE Id IN :tmpVar1
09:10:30.248 (248542492)|SOQL_EXECUTE_END|[14]|Rows:0
09:10:30.248 (248578946)|HEAP_ALLOCATE|[14]|Bytes:4
09:10:30.248 (248598204)|HEAP_ALLOCATE|[14]|Bytes:0
09:10:30.248 (248614460)|HEAP_ALLOCATE|[14]|Bytes:4
09:10:30.248 (248695845)|HEAP_ALLOCATE|[14]|Bytes:46
09:10:30.248 (248715430)|METHOD_EXIT|[6]|01pe0000000PkIV|updateFrsFromApprovedFeature.updateFeatureRequests(List<Feature__c>)
09:10:30.248 (248853172)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

Class.updateFrsFromApprovedFeature.updateFeatureRequests: line 14, column 1
Trigger.Feature: line 6, column 1
09:10:30.248 (248870666)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

Class.updateFrsFromApprovedFeature.updateFeatureRequests: line 14, column 1
Trigger.Feature: line 6, column 1
09:10:30.248 (248926351)|CUMULATIVE_LIMIT_USAGE
09:10:30.248 (248926351)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 3 out of 100
This is odd to me because as you can see from my debug statement in line 17, featproxy does contain an Id. 
 
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
public class updateFrsFromApprovedFeature {

    public static list<Feature__c> filterFeature(map<id, Feature__c> oldMap, list<Feature__c> newList) {
        list<Feature__c> temp=new list<Feature__c>();
        for (Feature__c newFeat : newList)    {
            if (oldMap.get(newFeat.id).Status__c != newFeat.Status__c && newFeat.Status__c == 'Accepted'){
                temp.add(newFeat);
            }
        }
        return temp;
    }

    public static void updateFeatureRequests(list<Feature__c> frUpdateList) 
	{
	
		Feature__c featproxy;
        List<Feature__c> lstfeatproxy = [SELECT Id, Status__c
                                FROM Feature__c
                                WHERE Id in: frUpdateList];
		if(lstfeatproxy.size() > 0)
		{
			featproxy =lstfeatproxy[0];
        
			List<Feature_Request__c> frs = [SELECT Feature__c, Proposed_Feature__c
											FROM Feature_Request__c
											WHERE Proposed_Feature__c =: featproxy.id];
			List<Feature_Request__c> updateFrs = new list<Feature_Request__c>();
			for(Feature_Request__c updatefr : frs){
				updatefr.Feature__c = featproxy.Id;
				updatefr.Proposed_Feature__c = null;
				updateFrs.add(updatefr);
			}
			system.debug(updateFrs);        
			If(updateFrs.size()>0){
				update updateFrs;               
			}
		}	
    }
    	
}
Please let us know if this will help u
Thanks
Amit Chaudhary
 
This was selected as the best answer
Gabe Rothman 8Gabe Rothman 8
Thanks Amit, this worked great!