You need to sign in to do that
Don't have an account?
HTANIRS
Trigger on Attachment to Insert Quote
Hi Friends,
Please help on below Trigger. I am trying to insert Quote when the attachment is added to Opporunity and the file name contains PDF.
trigger oppattachment on Attachment (after insert, after update) {
Set <Id> oppIds = new Set <Id>();
for(Attachment attach : Trigger.new) {
if(attach.ParentId.getSobjectType() == Opportunity.SobjectType) {
if(string.valueOf(attach.Name).contains('.pdf')) {
oppIds.add(attach.ParentId);
}
}
}
List <Quote> quoteList = [SELECT id, name, opportunityid FROM Quote WHERE Id IN: oppIds];
for(Attachment attach : Trigger.new) {
if(quoteList !=null && quoteList.size()>0){
for(quote q : quotelist){
q.name = attach.name;
}
insert quoteList;
}
}
}
Thanks.
Please help on below Trigger. I am trying to insert Quote when the attachment is added to Opporunity and the file name contains PDF.
trigger oppattachment on Attachment (after insert, after update) {
Set <Id> oppIds = new Set <Id>();
for(Attachment attach : Trigger.new) {
if(attach.ParentId.getSobjectType() == Opportunity.SobjectType) {
if(string.valueOf(attach.Name).contains('.pdf')) {
oppIds.add(attach.ParentId);
}
}
}
List <Quote> quoteList = [SELECT id, name, opportunityid FROM Quote WHERE Id IN: oppIds];
for(Attachment attach : Trigger.new) {
if(quoteList !=null && quoteList.size()>0){
for(quote q : quotelist){
q.name = attach.name;
}
insert quoteList;
}
}
}
Thanks.
You want to create a new Quote under that opportunity what I understood ,here you are querying from existing quote and you are again inserting .
Please clarify your requirment ,if you are adding new quote what will be default field values for the new quote .
Let us know your requirmnet with more clarity .Check with below code it may help !!
Please let me know if it helps !!!
Thanks
Manoj
All Answers
You want to create a new Quote under that opportunity what I understood ,here you are querying from existing quote and you are again inserting .
Please clarify your requirment ,if you are adding new quote what will be default field values for the new quote .
Let us know your requirmnet with more clarity .Check with below code it may help !!
Please let me know if it helps !!!
Thanks
Manoj
Thanks for your reply.
My requirement is : When I add the attachment in Opportunity I need to create a New Quote with the Attachment name which has extension .pdf. If it has 3 PDF I need to create 3 Quote.
Also, I need to copy all the attachments to Quote that are related to that opportunity.
Your Code works perfect.
For my 2nd requirement I have written in Quote Object to copy Attachments from Opportunity to Quote.
Please let me know if you have any suugestions to handle this requirement.
Regards,
Srinath.