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
WebNXWebNX 

Getting no rows for assignment to SObject

I am have created a dynamic visualforce email template that  will give a person/lead an email accuring to the clients picklist inofrmation.

The error message that I am getting states;

"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."

 

Does any one know what this means, or what is causing the problem? Here is my code below:

 

Apex code:

 

public class ListWhitePapers {

            public Id thisLeadId { get; set; }

            public List<String> WhitePapers = new List<String>();

            public List<String> getWhitePapers(){

Lead leadRequest = [Select Requested_Research_Papers__c From Lead Where Id =: thisLeadId limit 1];

 List<String> requestWhites = leadRequest.Requested_Research_Papers__c.split(';');

for(String request : requestWhites){

if(request.equals('Analytical formulas')){

WhitePapers.add('Analytical Formulas <br />');

}else if(request.equals('Analytic techniques’)){

WhitePapers.add('Analytical Techniques <br />');

}else if(request.equals('Dynamic model’)){

WhitePapers.add('Dynamic Model <br />');

}else if(request.equals('Generalized Method')){

WhitePapers.add('Generalized Method  <br />');

}else if(request.equals('Projection-Displaced Diffusion')){

WhitePapers.add('Projection onto a Displaced Diffusion<br />');

}else if(request.equals(' Projection onto a Heston model')){

WhitePapers.add('Projection to a Heston Model <br />');

}else if(request.equals('Credit Portfolios')){

WhitePapers.add('Credit Portfolios <br />' );

                                    }//End of if-else statement.

                         }//End of for loop.

                         return WhitePapers;

            }//End of public list string

}//Enod of apex class.

 

 

Component Code:

 

<apex:component controller="ListWhitePapers" access="global">

<apex:attribute name="LeadId" description="This is the requesting Lead's Id." type="Id" assignTo="{!thisLeadId}"/>

<apex:repeat value="{!WhitePapers}" var="paper" id="theRepeat">

<apex:outputText value="{!paper}"/><br />

</apex:repeat>

</apex:component>

 

VisualForce Email Template:

 

<messaging:emailTemplate subject="Here is the URL for the Research Paper you Requested" recipientType="Lead" relatedToType="Lead">

<messaging:htmlEmailBody >

<html>

<body>

Dear {!recipient.FirstName} {!recipient.LastName}: <br /><br />

 

Thank you for your interest in Numerix! <br /><br />

 

As you probably already know, Numerix, an independent software company, is the recognized leader in multi-platform, cross-asset

derivatives pricing and risk management software for fixed income, credit, foreign exchange and equity. More than 200 clients across

25 countries rely on NumeriX for speed and accuracy in valuating and pricing their vanilla and exotic derivatives. <br /><br /> 

 

With the ability to quickly design and price new derivative products, Numerix CrossAsset combines robust analytics with maximum

flexibility. Traders, marketers, quantitative analysts and portfolio managers can quickly assemble and price deals. Numerix CrossAsset

is a generic derivative pricing software package, designed to be fast and simple to use inside of Excel or within an integrated

solution, where heavy use is expected and high accuracy demanded, such as trading and risk management systems. <br /><br /><br /> 

 

 

For your interest the following are papers written by members of the NumeriX Quantitative team. If you wish to access this work done by our world renowned analytics department please follow the links provided below:<br />

 

To download click the links below: <br /><br />

<c:RequestWhitePaper LeadId="{!relatedTo.Id}"/>

<br />

If you wish any further information please contact us at : <br /><br />

Thank you

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Given the error that you are seeing, its highly likely that this is the line causing the problem:

 

Lead leadRequest = [Select Requested_Research_Papers__c From Lead Where Id =: thisLeadId limit 1];

 Everything looks okay from an order of execution point of view, so I'd be inclined to check that thisLeadId isn't null - i.e. that the relatedId from the email template isn't null.

 

You could test this in the code in a fairly straightforward fashion:

 

List<Lead> leadRequests = [Select Requested_Research_Papers__c From Lead Where Id =: thisLeadId limit 1];
if (leadRequests.size()>0)
{
   Lead leadRequest=leadRequests[0];
   // rest of the method goes here
}
else
{
   WhitePapers.add('No leads found for lead id ' + thisLeadId);
}

return whitePapers;

 

 

 

All Answers

bob_buzzardbob_buzzard

Given the error that you are seeing, its highly likely that this is the line causing the problem:

 

Lead leadRequest = [Select Requested_Research_Papers__c From Lead Where Id =: thisLeadId limit 1];

 Everything looks okay from an order of execution point of view, so I'd be inclined to check that thisLeadId isn't null - i.e. that the relatedId from the email template isn't null.

 

You could test this in the code in a fairly straightforward fashion:

 

List<Lead> leadRequests = [Select Requested_Research_Papers__c From Lead Where Id =: thisLeadId limit 1];
if (leadRequests.size()>0)
{
   Lead leadRequest=leadRequests[0];
   // rest of the method goes here
}
else
{
   WhitePapers.add('No leads found for lead id ' + thisLeadId);
}

return whitePapers;

 

 

 

This was selected as the best answer
WebNXWebNX

Thanks bob_buzzard that was the problem.