즐겨찾기Pankaj Jha (AlmaMate Info Tech) 님이 #Apex에 질문했습니다2020년 5월 1일 오전 10:35how to merge duplicate lead with batch apex based on email ?Hi friends,I am new in salesforce, if you know plz reply.thanks in advance.how to merge duplicate lead with batch apex based on email ?global class LeadBatchAviodDuplicacy implements Database.Batchable<sObject> {public String queryString;global Database.QueryLocator start(Database.BatchableContext BC) { queryString = 'SELECT Id, Name, Email FROM Lead '; return Database.getQueryLocator(queryString);} global void execute(Database.BatchableContext BC, List<Lead> obj) {Map<String,List<Lead>> LeadMap = new Map<String,List<Lead>>(); Set<String> LeadName = new Set<String>(); Set<String> LeadEmail = new Set<String>(); for(Lead a :obj){ LeadName.add(a.Name.toLowerCase()); if(String.isnotblank(a.Email)) LeadEmail.add(a.Email.toLowerCase()); } //Get All non formula fields of Lead String sobjectApiName = 'Lead'; Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap(); List<String> fieleList = new List<String>(); for(String fieldName : fieldMap.keySet()){ Schema.DescribeFieldResult fieldResult = fieldMap.get(fieldName).getDescribe(); if(!fieldResult.isCalculated() && fieldResult.isCreateable() && !fieldResult.isExternalId()&& fieldResult.isUpdateable()){ fieleList.add(fieldName); } /*if(fieldName != 'isPartner' && fieldName != 'IsCustomerPortal'){ fieleList.add(fieldName); }*/ } String fetchFields = 'SELECT '+String.join(fieleList,',')+' FROM '+sobjectApiName+' WHERE Email IN :LeadEmail'; integer i = 1; for(Lead a : Database.query(fetchFields)){ String key = a.Email; key = key.toLowerCase(); if(LeadMap.containsKey(key)){ LeadMap.get(key).add(a); }else { LeadMap.put(key,new List<Lead>{a}); } i++; } System.debug('i >'+i);System.debug('LeadMap >> '+LeadMap); List<Lead> mergeList;for(String key : LeadMap.keySet()){ System.debug('Size >>'+ LeadMap.get(key).size()); if(LeadMap.get(key).size()>1 ){ mergeList = new List<Lead>(); Lead masterLead = LeadMap.get(key)[0]; mergeList.addAll(LeadMap.get(key)); mergeList.remove(0); System.debug('mergeList >> '+mergeList); for(Lead a : mergeList){ Database.MergeResult mergeResult = Database.merge(masterLead, a, true); } }}//if(mergeList.size()>0)// update mergeList;}global void finish(Database.BatchableContext BC) {}}I'm unable to map fields and feed fields. 더 보기답변 3개정렬날짜별 정렬가장 유용한 항목별 정렬날짜별 정렬댓글 더 보기...Deepesh Bairathee (Student)2021년 5월 6일 오전 10:54Hello,did you solve this.I am aslo not able to merge field like phone, fax etc while merging contact. if you have solved this problem then kindly help me also.댓글 추가답변을 작성하세요...굵은 글꼴기울인 글꼴밑줄취소선불릿 기호 목록번호가 지정된 목록링크 추가코드 블록이미지 삽입파일 첨부링크 URL취소저장0/9000답글 쓰기
Deepesh Bairathee (Student)2021년 5월 6일 오전 10:54Hello,did you solve this.I am aslo not able to merge field like phone, fax etc while merging contact. if you have solved this problem then kindly help me also.