I am getting FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject. I know that it is because it is not returning any rows in the SOQL query but what I want is that if it returns any row, it should update ALO field on contact object, if it is null then ALO field should be set to null.
Here is my code:
ziptoLOD = [SELECT Id, Name, LOD__c
FROM Zip_3_to_LOD__c
WHERE Name =: contact.Extract_Zipcode__c ];
Zip_3_to_LOD__c ziptoLOD2 = (ziptoLOD != null) ? ziptoLOD : null;
if (ziptoLOD2 == null) {
contact.ALO__c = ' ';
} else {
System.debug(System.LoggingLevel.ERROR, 'Zip to LOD' + ziptoLOD2);
contact.ALO__c = ziptoLOD2.LOD__c;
}
My code gets stuck at the SOQL query and gives me the list has no rows error.