You need to sign in to do that
Don't have an account?
golu
attachment cloning
Hi,
i am cponverting my lead to person account using the below code. I want to clone the attachment in lead to person account as well. How do i do it?
i am cponverting my lead to person account using the below code. I want to clone the attachment in lead to person account as well. How do i do it?
trigger LeadCreateAccount on Lead (Before Insert) { Public List<Account> lstAccts = new List<Account>(); Public List<Account> lstNewAccts = new List<Account>(); Public set<String> setLeadNames = new set<String>(); public String name = ''; Id personAccountRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId(); for(Lead l: trigger.new) { Account acct = new account(); acct.FirstName = l.firstname; acct.LastName = l.lastname; acct.Email__c = l.Email; acct.RecordTypeId = personAccountRecordTypeId; lstNewAccts.add(acct); } if (lstNewAccts.size() > 0) insert lstNewAccts; }
trigger LeadCreateAccount on Lead (after Insert) {
Public List<Account> lstAccts = new List<Account>();
Public List<Account> lstNewAccts = new List<Account>();
Public set<String> setLeadNames = new set<String>();
public String name = '';
Id personAccountRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId();
List<Account> listAcc=new List<Account>();
Map<String,Account> mapAccount=new Map<String,Account>();
Map<Id,String> mapLead=new Map<Id,String>();
List<Attachment> listAtt=new List<Attachment>();
for(Lead l: trigger.new)
{
Account acct = new account();
acct.FirstName = l.firstname;
acct.LastName = l.lastname;
acct.Email__c = l.Email;
acct.RecordTypeId = personAccountRecordTypeId;
lstNewAccts.add(acct);
mapLead.put(l.ID,l.Email);
//insert acct ;
/*List<Attachment> fileAttachment = [SELECT SELECT Id,
Body,
Name,
Description,
ParentId
FROM Attachment
WHERE ParentId=:l.Id]*/
/*for( Attachment a :fileAttachment){
Attachment newFile = a.clone();
newFile.ParentId = acct.Id;
//insert newFile;
}*/
}
if(!lstNewAccts.isEmpty()){
insert lstNewAccts;
}
for(Account instAcc:lstNewAccts){
mapAccount.put(instAcc.Email__c,instAcc);
}
for(Attachment instAcc:[SELECT SELECT Id,
Body,
Name,
Description,
ParentId
FROM Attachment
WHERE ParentId in :mapLead.keyset()] ){
Attachment newFile = a.clone();
newFile.ParentId = mapAccount.get(mapLead.get(instAcc.parentID)).Id;
listAtt.add(newFile);
}
if(!listAtt.isEmpty()){
insert listAtt;
}
}
Thanks ! If its work pls mark as best answer.
I tried with the below code but it dosent work