Noramally this error can be occured for following scenario. But I couldn't find such scenario in you code. Please check you r code with following scenario.
IF (MDF__c.Submitted__c = true)
this should be
IF (a.Submitted__c == true)
Hit the Kudos button if any post helps you - Mark the answer as solution, It might help others running to into similar problem in future.
Where are you instantiating currentportfolioId? You are using in your first query, but as far as the query is concerned, it doesn't really exist yet...
Noramally this error can be occured for following scenario. But I couldn't find such scenario in you code. Please check you r code with following scenario.
Hit the Kudos button if any post helps you - Mark the answer as solution, It might help others running to into similar problem in future.
Detail_object__c.sub_detail__c = keyTechsolutions;
TO
Detail_object__c objdetailobject = New Detail_object__c();
objdetailobject.sub_detail__c = keyTechsolutions;
Where are you instantiating currentportfolioId? You are using in your first query, but as far as the query is concerned, it doesn't really exist yet...