You need to sign in to do that
Don't have an account?
Kiran kumar 193
update attachment name as opportunity name?
I want to update attachment name as opportunity name... Please share the code
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
for(Attachment att: Trigger.New){
att.Name = [Select Id,Name from Opportunity where Id=:att.ParentId].Name;
}
}
Opportunity template has already some attachments and with the same name I want to update the name in attachment as well..
How do I do this?
public static void beforeInsert(list<attachment> newrecords)
{
Set<ID> parentIDs = new Set<ID>();
List<attachment> updateAttachmentList = new list<attachment>();
for(attachment oattach : newrecords){
if(oattach.ParentId.getSobjectType() == SBQQ__Quote__c.SobjectType){
parentIDs.add(oattach.ParentID);
}
}
List<SBQQ__QuoteDocument__c> quoteDocuments = [SELECT Id, Name, SBQQ__QuoteTemplate__c, SBQQ__QuoteTemplate__r.Name, SBQQ__Quote__r.Name FROM SBQQ__QuoteDocument__c where SBQQ__Quote__c =:parentIDs];
for(attachment oattach : newrecords){
oattach.Name= quoteDocuments[0].SBQQ__QuoteTemplate__r.Name + ' - ' + quoteDocuments[0].SBQQ__Quote__r.Name;
updateAttachmentList.add(oattach);
}
if(!updateAttachmentList.isEmpty()){
//update updateAttachmentList;
}
}
List<SBQQ__QuoteDocument__c> quoteDocuments = [SELECT Id, Name, SBQQ__QuoteTemplate__c, SBQQ__QuoteTemplate__r.Name, SBQQ__Quote__r.Name FROM SBQQ__QuoteDocument__c where SBQQ__Quote__c IN:parentIDs];
Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AttachmentTrigger: execution of AfterInsert caused by: System.ListException: List index out of bounds: 0 () : []
I want to represent Attachment same name Quote document name
List<SBQQ__QuoteDocument__c> quoteDocuments = [SELECT Id, Name, SBQQ__QuoteTemplate__c, SBQQ__QuoteTemplate__r.Name, SBQQ__Quote__r.Name FROM SBQQ__QuoteDocument__c where Opportunity__c IN:parentIDs];
I am guessing Opportunty__C is a field on Quote__c object.
nsert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AttachmentTrigger: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0 () : []
I want to populate Same quote documents as the Attachments
Just use this if clause instead
Class
public class AttachmentTrigger1
{
public static void beforeInsert(list<attachment> newrecords)
{
Set<ID> parentIDs = new Set<ID>();
List<attachment> updateAttachmentList = new list<attachment>();
for(attachment oattach : newrecords){
if(String.valueOf(oattach.ParentId).startsWith('006')){
parentIDs.add(oattach.ParentID);
}
}
List<SBQQ__QuoteDocument__c> quoteDocuments = [SELECT Id, Name, SBQQ__QuoteTemplate__c, SBQQ__QuoteTemplate__r.Name, SBQQ__Quote__r.Name FROM SBQQ__QuoteDocument__c where SBQQ__Opportunity__c IN:parentIDs];
for(SBQQ__QuoteDocument__c doc : quoteDocuments){
if(doc.SBQQ__QuoteTemplate__c == null ||
doc.SBQQ__Opportunity__c == null ||
doc.SBQQ__QuoteTemplate__r.Name == null){
Attachment a = new Attachment();
a.Name = doc.SBQQ__QuoteTemplate__r.Name + ' - ' + doc.SBQQ__Opportunity__r.Name;
updateAttachmentList.add(a);
}
if(!updateAttachmentList.isEmpty()){
update updateAttachmentList;
}
}
}
}
Trigger :
trigger AttachmentTrigger on Attachment (before insert,after insert) {
if(Trigger.isInsert && Trigger.isBefore){
AttachmentTrigger1.beforeInsert(trigger.new);
}
}
1) When Quote get generated
2) when order get generated
The name of the attachment should be if it is quote - Quote Attachment
The name of the attachment should be if it is Order - Order Attachment
do you have Any solution on this?
Quote document object is child of Quote object.
Attachment also child of Quote Object
so now I have a requirement to change the name of Attachment in the attachment object.
so finally the documents on document object and Attachment object should be the same
try this one too works perfectly for me.
you have to retrieve the Name of the opportunity :
Opportunity opp = [SELECT Name FROM Opportunity WHERE id =: a.id];
Attachment attach = new Attachment(+ opp.Name +System.today() +);
opp.Name ----> it'll retrieve the opportunity name