Extremely Critical : I am trying to ammend attachments from lead to custom object , upon conversion. On conversion i have attachment on the leadconverted contact.How do i iset it over to a custom object.
Below is my apex class method Creditwriteup is the custom object into which i want attachment to move over.
@future public static void cloneAttachment(Id cattaList,List<String> cwwList) { Credit_Writeup__c cww = [select id,Credit_Writeup_Account__c from Credit_Writeup__c where id=:cattaList]; List<Credit_Writeup__c> cwList = [select id from Credit_Writeup__c where id IN:cwwList];
List<Contact> cList = new List<Contact>(); List<Lead> lList = new List<Lead>(); List<Attachment> al = new List<Attachment>(); List<Attachment> insertAttList = new List<Attachment>(); Credit_Writeup__c Cw = new Credit_Writeup__c(); //Id cont = String.valueOf(cww.Contact__c).substring(0,15); Id accnt = String.valueOf(cww.Credit_Writeup_Account__c).substring(0, 15); system.debug('account is '+accnt);
if(accnt != null){
clist = [select id , Contact_Id__c from contact where Merged_Contact__c = true AND accountId= :accnt]; } Id contid = cList[0].Contact_Id__c;
if( cList.size() > 0 && cList != null) {
lList = [SELECT convertedContactId FROM Lead WHERE convertedContactId IN: cList]; }
aL = [select id,body,name from Attachment where parentId =:contid Limit 1] ; //************* at this point iam confused unable to retreive the contact id which is the parent id//
} /* else{
aL = [select id,body,name from Attachment where parentId= :lList[0].convertedContactId Limit 1] ;
}*/ if(aL != null&&aL.size()>0){
for(Credit_Writeup__c c: cwList) {
Attachment att = new Attachment(name = aL[0].name, body = aL[0].body, parentid = c.id); insertAttList.add(att);
Creditwriteup is the custom object into which i want attachment to move over.
@future
public static void cloneAttachment(Id cattaList,List<String> cwwList)
{
Credit_Writeup__c cww = [select id,Credit_Writeup_Account__c from Credit_Writeup__c where id=:cattaList];
List<Credit_Writeup__c> cwList = [select id from Credit_Writeup__c where id IN:cwwList];
List<Contact> cList = new List<Contact>();
List<Lead> lList = new List<Lead>();
List<Attachment> al = new List<Attachment>();
List<Attachment> insertAttList = new List<Attachment>();
Credit_Writeup__c Cw = new Credit_Writeup__c();
//Id cont = String.valueOf(cww.Contact__c).substring(0,15);
Id accnt = String.valueOf(cww.Credit_Writeup_Account__c).substring(0, 15);
system.debug('account is '+accnt);
if(accnt != null){
clist = [select id , Contact_Id__c from contact where Merged_Contact__c = true AND accountId= :accnt];
}
Id contid = cList[0].Contact_Id__c;
if( cList.size() > 0 && cList != null) {
lList = [SELECT convertedContactId FROM Lead WHERE convertedContactId IN: cList];
}
if(cList[1].Merged_Contact__c = true)
{
if(lList != null && lList.size()>0)
aL = [select id,body,name from Attachment where parentId =:contid Limit 1] ; //************* at this point iam confused unable to retreive the contact id which is the parent id//
}
/* else{
aL = [select id,body,name from Attachment where parentId= :lList[0].convertedContactId Limit 1] ;
}*/
if(aL != null&&aL.size()>0){
for(Credit_Writeup__c c: cwList)
{
Attachment att = new Attachment(name = aL[0].name, body = aL[0].body, parentid = c.id);
insertAttList.add(att);
}
if(insertAttList.size() > 0)
{
insert insertAttList;
}
}
}
}