You need to sign in to do that
Don't have an account?
Nirmal Christopher
Bulkify a trigger?
Is this trigger bulkified im unable to bulk inset using data loader only the last recored in the csv file gets the field update properly
trigger urlattachmentupdate on Attachment (after insert,after update) {
list<contact>cc=new list <contact>();
set<attachment>a=new set<attachment>();
Public string attachmentid='';
Public string parentid='';
for(Attachment aa:trigger.new){
attachmentid=aa.id;
parentid=aa.parentid;
System.debug('Attchment IDDD'+attachmentid);
System.debug('ParentIDDDDDDDDDDD'+parentid);
}
cc=[Select id from contact where id =:parentid];
for(contact cc1:cc){
cc1.Member_Photo_URL__c='https://c.cs10.content.force.com/servlet/servlet.FileDownload?file='+attachmentid;
}
update cc;
}
trigger urlattachmentupdate on Attachment (after insert,after update) {
list<contact>cc=new list <contact>();
set<attachment>a=new set<attachment>();
Public string attachmentid='';
Public string parentid='';
for(Attachment aa:trigger.new){
attachmentid=aa.id;
parentid=aa.parentid;
System.debug('Attchment IDDD'+attachmentid);
System.debug('ParentIDDDDDDDDDDD'+parentid);
}
cc=[Select id from contact where id =:parentid];
for(contact cc1:cc){
cc1.Member_Photo_URL__c='https://c.cs10.content.force.com/servlet/servlet.FileDownload?file='+attachmentid;
}
update cc;
}
trigger urlattachmentupdate on Attachment (after insert,after update) {
list<contact>cc=new list <contact>();
Map<id,id> attachmentByParent = new Map<id,id>();
for(Attachment aa:trigger.new){
attachmentByParent.put(aa.parentId,aa.Id);
}
cc=[Select id from contact where id in :attachmentByParent.keySet()];
for(contact cc1:cc){
cc1.Member_Photo_URL__c='https://c.cs10.content.force.com/servlet/servlet.FileDownload?file='+attachmentByParent.get(cc1.Id);
}
update cc;
}
All Answers
trigger urlattachmentupdate on Attachment (after insert,after update) {
list<contact>cc=new list <contact>();
Map<id,id> attachmentByParent = new Map<id,id>();
for(Attachment aa:trigger.new){
attachmentByParent.put(aa.parentId,aa.Id);
}
cc=[Select id from contact where id in :attachmentByParent.keySet()];
for(contact cc1:cc){
cc1.Member_Photo_URL__c='https://c.cs10.content.force.com/servlet/servlet.FileDownload?file='+attachmentByParent.get(cc1.Id);
}
update cc;
}
trigger urlattachmentupdate on Attachment (after insert,after update) {
list<contact>cc=new list <contact>();
set<attachment>a=new set<attachment>();
public map<String,String> attachmentIdMap = new map<SString,tring>();
public set<String> parentIds = new set<String>();
for(Attachment aa:trigger.new){
parentIds.add(aa.parentid);
attachmentIdMap.put(aa.parentid,aa.id);
System.debug('Attchment IDDD'+attachmentid);
System.debug('ParentIDDDDDDDDDDD'+parentid);
}
cc=[Select id from contact where id in : parentIds];
for(contact cc1:cc){
String attachmentid = attachmentIdMap.get(contact.id);
cc1.Member_Photo_URL__c='https://c.cs10.content.force.com/servlet/servlet.FileDownload?file='+attachmentid;
}
update cc;
}