You need to sign in to do that
Don't have an account?
Saurabh Smarty
Hi All, I have wrote a trigger that updates a field if an attachment is uploaded in the object, but I want to get the field update only when the attachment's name has certain words in it, how can I accomplish that ?
Below is the trigger :
trigger attach on Attachment (after insert) {
public List<opportunity> oppoList = new List<opportunity>();
public Set<Id> oppIds = new Set<Id>();
for(Attachment att : trigger.New){
//Check if added attachment is related to Account or not
if(att.ParentId.getSobjectType() == Opportunity.SobjectType && att.name ??? ){
oppIds.add(att.ParentId);
}
system.debug('for loop completed');
}
oppoList = [select id from Opportunity where id in :oppIds];
if(oppoList!=null && oppoList.size()>0){
system.debug('in if condition');
for(Opportunity op : oppoList){
op.attach_upload__c = true;
}
system.debug('2nd for loop completed');
update oppoList;
system.debug('update completed');
}
}
trigger attach on Attachment (after insert) {
public List<opportunity> oppoList = new List<opportunity>();
public Set<Id> oppIds = new Set<Id>();
for(Attachment att : trigger.New){
//Check if added attachment is related to Account or not
if(att.ParentId.getSobjectType() == Opportunity.SobjectType && att.name ??? ){
oppIds.add(att.ParentId);
}
system.debug('for loop completed');
}
oppoList = [select id from Opportunity where id in :oppIds];
if(oppoList!=null && oppoList.size()>0){
system.debug('in if condition');
for(Opportunity op : oppoList){
op.attach_upload__c = true;
}
system.debug('2nd for loop completed');
update oppoList;
system.debug('update completed');
}
}
You can use below string method it is a case not sensitive.
Instead of attachname.contains('SFDC'); you can use attachname.containsIgnoreCase('SFDC');
Hope it helps you.
Please let me know in case of other assistance.
Thanks
Varaprasad
All Answers
By default attachment name == document name.
Please check once below code :
hope it helps you.
Please let me know in case of any other help.
Thanks
Varaprasad
You can use below string method it is a case not sensitive.
Instead of attachname.contains('SFDC'); you can use attachname.containsIgnoreCase('SFDC');
Hope it helps you.
Please let me know in case of other assistance.
Thanks
Varaprasad