1

I'm facing an issue with VF Email Template. The error is not very Clear :

"Error Error occurred trying to load the template for preview: List has no rows for assignment to SObject. Please try editing your markup to correct the problem. "

This is my controller :

(Adding the method which returns list has no rows)

// in this method flight Id is returning values, but the FlightService list is empty.

public List<Flight_Service__c> getFlightService()
{
        List<Flight_Service__c> FlightService = new List<Flight_Service__c>();

        for(Flight_Service__c eachFlight : [SELECT id,Vendor_Service__r.Account__c,
                                            Vendor_Service__r.Account__r.Name,
                                            Name , 
                                            Vendor_Service__r.Service_Type__c,
                                            Cleaning_Services__c,
                                            Vendor_Service__r.Account__r.Email__c,
                                            Vendor_Service__r.Account__r.Email_2__c,
                                            Vendor_Service__r.Account__r.Email_3__c,
                                            Flight__r.Airport_Origin_IATA__c,
                                            Flight__r.Airport_Origin_ICAO__c,
                                            Flight_Services__c ,
                                            Vendor_Service__r.Account__r.Phone,
                                            Vendor_Service__r.Account__r.Phone_2__c ,
                                            Vendor_Service__r.Account__r.Phone_3__c ,
                                            Vendor_Service__r.Vendor_Primary_Contact_Phone__c,
                                            Vendor_Service__r.Vendor_Primary_Contact_Email__c,
                                            Vendor_Service__r.Account__r.Primary_Contact__r.Name
                                            FROM Flight_Service__c 
                                            WHERE Flight__c IN :FlightIds
                                            Order by Flight__r.Airport_Origin_IATA__c]){
                                                if(eachFlight != null)
                                                    FlightService.add(eachFlight);    
                                            }

        System.debug('FlightService*** '+FlightService);
        return FlightService;
}

This is my VF Component:

<apex:component controller="CAMMessageController" access="global" >
    <apex:attribute name="OpptyId" type="Id" description="Opportunity Id" assignTo="{!opportunityId}"/>
    <apex:attribute name="cId" type="Id" description="Case Id" assignTo="{!caseId}"/>
    hello
</apex:component>

This is my VF Email Template:

I'm not sure what to provide here for Case Id. Case Id and Opportunity Id are passed in the URL of the VF Page.

<messaging:emailTemplate subject="Sample" recipientType="Contact" relatedToType="Opportunity">
<messaging:htmlEmailBody>
<!-- hard coded contact Id for now -->
<c:CAMMessage OpptyId="{!relatedTo.Id}" cId="5002C000005Cd11QAC">
</c:CAMMessage>
Hello
</messaging:htmlEmailBody>
</messaging:emailTemplate>

Please let me know what should be done to get this working.

1 Answer 1

0

Chinmai,

The issue lies at this statement.

if(eachFlight != null)

FlightService.add(eachFlight);

Instead try doing it like this.

if(eachFlight.size()>0)

FlightService.add(eachFlight);

Please refer to the below article for more information about the error. 'List has no rows for assignment to SObject' error

Thanks

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .