You need to sign in to do that
Don't have an account?
kiran punuru
List has no rows for assignment to a sobject
Hi Iam trying attach a document which is uploaded in chatter to the email and send that email but iam getting the system.query exception:list has no rows for assignment to sobject.
Trigger:
trigger SendEmailOnFileUploadTrigger2 on ContentDocumentLink (after insert,after update) {
Set<Id> fieldIds = new Set<Id>();
Set<Id> docIdSet = new Set<Id>();
for(ContentDocumentLink content :trigger.new){
fieldIds.add(content.LinkedEntityId);
docIdSet.add(content.ContentDocumentId);
}
system.debug('@@@ Linked Entity Id:'+fieldIds);
system.debug('@@@ Content Document Id:'+docIdSet);
if(trigger.isAfter)
EmailHandler.sendUploadNotificationEmail(docIdSet);
}
Class:
public without sharing class EmailHandler {
public static void sendUploadNotificationEmail(set<Id> docIds){
system.debug('@@@@Document Ids:'+docIds);
Document doc = [select id, name, body, contenttype, developername, type from Document where Id IN :docIds];
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType(doc.contentType);
attach.setFileName(doc.developerName+'.'+doc.type);
attach.setInline(false);
attach.Body = doc.Body; */
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'test@xyz.com'};
String[] ccAddresses = new String[] {'kirankumar.punuru@xyz.com'};
mail.setUseSignature(false);
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
mail.setReplyTo('kirankumar.punuru@eclerx.com');
mail.setSenderDisplayName('Kiran Kumar reddy Punuru');
mail.setSubject('The Below File Has been uploaded : ');
//mail.setHtmlBody('Here is the email you requested: '+doc.name);
//mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
mail.setBccSender(false);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Please correct the above if iam doing in correct.
Thanks
kiran
Trigger:
trigger SendEmailOnFileUploadTrigger2 on ContentDocumentLink (after insert,after update) {
Set<Id> fieldIds = new Set<Id>();
Set<Id> docIdSet = new Set<Id>();
for(ContentDocumentLink content :trigger.new){
fieldIds.add(content.LinkedEntityId);
docIdSet.add(content.ContentDocumentId);
}
system.debug('@@@ Linked Entity Id:'+fieldIds);
system.debug('@@@ Content Document Id:'+docIdSet);
if(trigger.isAfter)
EmailHandler.sendUploadNotificationEmail(docIdSet);
}
Class:
public without sharing class EmailHandler {
public static void sendUploadNotificationEmail(set<Id> docIds){
system.debug('@@@@Document Ids:'+docIds);
Document doc = [select id, name, body, contenttype, developername, type from Document where Id IN :docIds];
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType(doc.contentType);
attach.setFileName(doc.developerName+'.'+doc.type);
attach.setInline(false);
attach.Body = doc.Body; */
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'test@xyz.com'};
String[] ccAddresses = new String[] {'kirankumar.punuru@xyz.com'};
mail.setUseSignature(false);
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
mail.setReplyTo('kirankumar.punuru@eclerx.com');
mail.setSenderDisplayName('Kiran Kumar reddy Punuru');
mail.setSubject('The Below File Has been uploaded : ');
//mail.setHtmlBody('Here is the email you requested: '+doc.name);
//mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
mail.setBccSender(false);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Please correct the above if iam doing in correct.
Thanks
kiran
On which line you are getting error or please provide the error message.
Regards,
Anil
Let us know if this will help you
Thanks
Amit Chaudhary
When i change the class then it is not giving error but i need to send email if listdoc.size() > 0 .The problem is it is showing the size of the list as zero.i did not understand the reason .
thanks,
Kiran
I am getting the error like this for the below line:
Document doc = [select id, name, body, contenttype, developername, type from Document where Id IN :docIds];
Thanks
kiran
Issue is coming because of below line:-
In your code No result is coming in above query so i added List to check if you will get zero record.
Try to update your code like below, Use document only when you will get document record from query
Let us know if that will help you
Thanks
Amit Chaudhary
system.debug('@@@@Document Ids:'+docIds);(here it is giving document id)
This size of the list is coming as zero
List<Document> Lisdoc = [select id, name, body, contenttype, developername, type from Document where Id IN :docIds];
This size of the list is coming as zero
Thanks
kiran