-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
5Questions
-
7Replies
Urgent requirement Make this highlighted line Reusable in Apex Code
public class DuplicateLeadMergeHandler
{
public static void MergeLead(List<Lead> newLead)
{
Set<String> dupemails = new Set<String>();
Set<String> dupphones = new Set<String>();
Set<String> dupmobiles = new Set<String>();
Set<ID> leadID = new Set<ID>();
Map<String, Lead> masterLeadMap = new Map<String, Lead>();
for(Lead oldLead : newLead)
{
If(oldLead.Email != Null)
dupemails.add(oldLead.Email);
else
If(oldLead.Phone != Null)
dupphones.add(oldLead.Phone);
else
if(oldLead.MobilePhone != Null)
dupmobiles.add(oldLead.MobilePhone);
leadID.add(oldLead.id);
}
List<lead> oldLeadList = [SELECT Id, Name, OwnerId, MobilePhone, Email, Phone, Instagram_Handle__c, Website, Interested_Event_Locations__c, Vendor_Type__c, Items_Interested_in_Selling__c FROM Lead WHERE (Email IN: dupemails OR Phone IN: dupphones OR MobilePhone IN: dupmobiles) AND Id NOT IN: leadId AND IsConverted = false];
List<lead> newleadList = [SELECT Id, OwnerId, MobilePhone, Email, Phone, Instagram_Handle__c, Website, Interested_Event_Locations__c, Vendor_Type__c, Items_Interested_in_Selling__c FROM Lead WHERE (Email IN: dupemails OR Phone IN: dupphones OR MobilePhone IN: dupmobiles) AND Id IN: leadId AND IsConverted = false];
If(!oldLeadList.IsEmpty())
{
for(Lead oldLead: newLeadList)
{
If(oldLead.Email != Null)
masterLeadMap.put(oldLead.Email, oldLead);
else
If(oldLead.Phone != Null)
masterLeadMap.put(oldLead.Phone, oldLead);
else
if(oldLead.MobilePhone != Null)
masterLeadMap.put(oldLead.MobilePhone, oldLead);
}
If(masterLeadMap.size() > 0 && masterLeadMap != null)
{
Lead masterLead = new Lead();
for(Lead oldLead : oldLeadList)
{
If(masterLeadMap.containskey(oldLead.Email))
{
masterLead = masterLeadMap.get(oldLead.Email);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}
}
Else
If(masterLeadMap.containskey(oldLead.Phone))
{
masterLead = masterLeadMap.get(oldLead.Phone);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
}
Else
If(masterLeadMap.containskey(oldLead.MobilePhone))
{
masterLead = masterLeadMap.get(oldLead.MobilePhone);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}
}
}
}
}
}
}
{
public static void MergeLead(List<Lead> newLead)
{
Set<String> dupemails = new Set<String>();
Set<String> dupphones = new Set<String>();
Set<String> dupmobiles = new Set<String>();
Set<ID> leadID = new Set<ID>();
Map<String, Lead> masterLeadMap = new Map<String, Lead>();
for(Lead oldLead : newLead)
{
If(oldLead.Email != Null)
dupemails.add(oldLead.Email);
else
If(oldLead.Phone != Null)
dupphones.add(oldLead.Phone);
else
if(oldLead.MobilePhone != Null)
dupmobiles.add(oldLead.MobilePhone);
leadID.add(oldLead.id);
}
List<lead> oldLeadList = [SELECT Id, Name, OwnerId, MobilePhone, Email, Phone, Instagram_Handle__c, Website, Interested_Event_Locations__c, Vendor_Type__c, Items_Interested_in_Selling__c FROM Lead WHERE (Email IN: dupemails OR Phone IN: dupphones OR MobilePhone IN: dupmobiles) AND Id NOT IN: leadId AND IsConverted = false];
List<lead> newleadList = [SELECT Id, OwnerId, MobilePhone, Email, Phone, Instagram_Handle__c, Website, Interested_Event_Locations__c, Vendor_Type__c, Items_Interested_in_Selling__c FROM Lead WHERE (Email IN: dupemails OR Phone IN: dupphones OR MobilePhone IN: dupmobiles) AND Id IN: leadId AND IsConverted = false];
If(!oldLeadList.IsEmpty())
{
for(Lead oldLead: newLeadList)
{
If(oldLead.Email != Null)
masterLeadMap.put(oldLead.Email, oldLead);
else
If(oldLead.Phone != Null)
masterLeadMap.put(oldLead.Phone, oldLead);
else
if(oldLead.MobilePhone != Null)
masterLeadMap.put(oldLead.MobilePhone, oldLead);
}
If(masterLeadMap.size() > 0 && masterLeadMap != null)
{
Lead masterLead = new Lead();
for(Lead oldLead : oldLeadList)
{
If(masterLeadMap.containskey(oldLead.Email))
{
masterLead = masterLeadMap.get(oldLead.Email);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}
}
Else
If(masterLeadMap.containskey(oldLead.Phone))
{
masterLead = masterLeadMap.get(oldLead.Phone);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}}
Else
If(masterLeadMap.containskey(oldLead.MobilePhone))
{
masterLead = masterLeadMap.get(oldLead.MobilePhone);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}
}
}
}
}
}
}
- SFDCDoctorStrange
- June 01, 2022
- Like
- 0
Apex Trigger for Merge lead with same email or phone and make new lead master lead
Created this Apex class
Thanks & Regards
SFDC Strange
public class DuplicateLeadMergeHandler { public static void MergeLead(List<Lead> newLead) { Set<String> emails = new Set<String>(); Set<String> phones = new Set<String>(); Map<String, Lead> masters = new Map<String, Lead>(); for(Lead ld : newLead) { emails.add(ld.Email); phones.add(ld.Phone); } emails.remove(null); phones.remove(null); for(Lead ld: [SELECT Id,Email,Phone FROM Lead WHERE (Email = :emails OR Phone = :phones) AND Id NOT IN :newLead AND IsConverted = false]) { If(ld.Email != Null) masters.put(ld.Email, ld); else If(ld.Phone != Null) masters.put(ld.Phone, ld); } for(Lead ld : newLead) { Lead master = new Lead(); If(masters != Null && masters.size() > 0 && masters.containskey(ld.Email)) { master = masters.get(ld.Email); } Else If(masters != Null && masters.size() > 0 && masters.containskey(ld.Phone)) { master = masters.get(ld.Phone); } If(master != null) { merge master ld; } } } }but its showing an errorplease help me solve this problem
Thanks & Regards
SFDC Strange
- SFDCDoctorStrange
- May 14, 2022
- Like
- 0
Urgent! Want to Create Apex class for receiving mail and import its attached csv file
hey All,
i have a requriement for make apex class for getting attached excel from mail and import that file in Salesforce object
here is what i found till now
Apex class
apex class for break csv to into parts
apex class
batch apex class
im getting error in this line
private CSVParser m_parser;
invalid type : CSVParser
please explain help me create this
Thanks & regards
Himanshu
i have a requriement for make apex class for getting attached excel from mail and import that file in Salesforce object
here is what i found till now
Apex class
global class ExcelInvoiceUpload implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope envelope) { Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); Messaging.InboundEmail.TextAttachment[] tAttachments = email.textAttachments; Messaging.InboundEmail.BinaryAttachment[] bAttachments = email.BinaryAttachments; String csvbody=''; if(bAttachments !=null) { for(Messaging.InboundEmail.BinaryAttachment btt : bAttachments) { System.debug('this looks like a binary attachment'); if(btt.filename.endsWith('.csv')) { csvbody = btt.body.toString(); } } } else if(tAttachments !=null) { for(Messaging.InboundEmail.TextAttachment ttt : tAttachments) { System.debug('this looks like a text attachment'); if(ttt.filename.endsWith('.csv')) { csvbody = ttt.body; } } } return result; } }for getting inbound mail
apex class for break csv to into parts
apex class
global with sharing class CSVIterator implements Iterator<String>, Iterable<String> { private String m_CSVData; private String m_introValue; public CSVIterator(String fileData, String introValue) { m_CSVData = fileData; m_introValue = introValue; } global Boolean hasNext() { return m_CSVData.length() > 1 ? true : false; } global String next() { String row = m_CSVData.subString(0, m_CSVData.indexOf(m_introValue)); m_CSVData = m_CSVData.subString(m_CSVData.indexOf(m_introValue) + m_introValue.length(),m_CSVData.length()); return row; } global Iterator<String> Iterator() { return this; } }
batch apex class
global with sharing class ReadAndPopulateBatch implements Database.batchable<String>, Database.Stateful { private String m_csvFile; private Integer m_startRow; private CSVParser m_parser; private static final Integer SCOPE_SIZE = 100; public ReadAndPopulateBatch() { } public static ID run() { } global Iterable<String> start(Database.batchableContext batchableContext) { return new CSVIterator(m_csvFile, m_parser.crlf); } global void execute(Database.BatchableContext batchableContext, List<String> scope) { //TODO: Create a map with the column name and the position. String csvFile = ''; for(String row : scope) { csvFile += row + m_parser.crlf; } List<List<String>> csvLines = CSVReader.readCSVFile(csvFile,m_parser); //TODO: csvLines contains a List with the values of the CSV file. //These information will be used to create a custom object to //process it. } global void finish(Database.BatchableContext batchableContext) { } }
im getting error in this line
private CSVParser m_parser;
invalid type : CSVParser
please explain help me create this
Thanks & regards
Himanshu
- SFDCDoctorStrange
- March 24, 2022
- Like
- 0
not Showing all values in Lightning Component Picklist
My lightning component all the picklist values from the related object
Aura Component
Aura Hepler
Aura Controller
please check and help me with the issue
thanks in advance
Himanshu
Aura Component
<div class="four wide column"> <label for="category-dropdown"><b>Select Category</b></label> <select id="category-dropdown" label="Category" class="ui small fluid selection dropdown"> <option value="{!v.defaultCategory}">--None--</option> <aura:iteration items="{!v.categoryOptions}" var="category"> <option value="{!category}">{!category}</option> </aura:iteration> </select> </div>
Aura Hepler
({ enableCategoryValues: function(component){ let action = component.get('c.getCategoryValues'); action.setParams({ 'recordId': component.get('v.recordId') }); action.setCallback(this, function(response){ let state = response.getState(); if(state === 'SUCCESS') { component.set('v.categoryOptions', response.getReturnValue()); component.set('v.catgoryFilterEnabled', true); }else{ console.error(JSON.stringify(response.getError())) } }) $A.enqueueAction(action) }, })
Aura Controller
@AuraEnabled public static List<String> getCategoryValues(String recordId) { List<String> catregories = new List<String>(); Schema.DescribeFieldResult fieldResult = SVMXC__Service_Order__c.Category__c.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry pickListVal : ple){ catregories.add(pickListVal.getValue()); } //catregories.sort(); system.debug('catregories : '+catregories); List<String> hasValueCategory = new List<string>(); Set<String> categorySet = new Set<String>(); List<sharinpix__SharinPixImage__c> sharinPixImageList = [select Id, sharinpix__AlbumID__c, sharinpix__ImagePublicId__c, Landscape_Portrait__c, sharinpix__FileName__c, sharinpix__ImageURLOriginal__c, Image_Thumbnail_F__c, sharinpix__ImageURLFull__c , CreatedDate, sharinpix__Tags__c, Work_Order__c, Work_Order__r.IP_Templates_Type__c, Work_Order__r.SVMXC__Component__c, Work_Order__r.Name, Work_Order__r.Start_Date_Time__c, sharinpix__Width__c, sharinpix__Height__c,sharinpix__Title__c, Image_Name__c, Work_Order__r.Category__c from sharinpix__SharinPixImage__c where sharinpix__AlbumID__c != null AND (NOT sharinpix__Tags__c LIKE '%After%') AND (NOT sharinpix__Tags__c LIKE '%Before%') AND (NOT sharinpix__Tags__c LIKE '%Time-Hrs%') AND Work_Order__r.SVMXC__Component__c =: recordId AND Work_Order__r.Category__c =: catregories ORDER BY Work_Order__r.Start_Date_Time__c, sharinpix__FileName__c, sharinpix__SortPosition__c]; if(sharinPixImageList != null){ for(sharinpix__SharinPixImage__c pix : sharinPixImageList){ if(pix.Work_Order__r.Category__c != null){ categorySet.add(pix.Work_Order__r.Category__c); } } } hasValueCategory.addAll(categorySet); return hasValueCategory; }
please check and help me with the issue
thanks in advance
Himanshu
- SFDCDoctorStrange
- February 19, 2022
- Like
- 0
ABC Firm needs to auto-create Opportunity Products in certain use cases.
- Create a custom checkbox field on Opportunity and name it ‘Add Products?’
- Create a multi-select picklist field on Opportunity that shows list of products one can auto-select.
- Create a picklist field on Opportunity as Pricebook.
- Each time an opportunity record is saved with Ádd Products’ selected as true following should happen
- Throw validation error if pricebook and products are not selected.
- Once opportunity is saved auto insert opportunity products on basis of selection made on pricebook and products.
- Code should be able to handle bulk data; meaning multiple opportunity records can be inserted together using Import Wizard or Data loader
- Code should adhere to programming best practices like
- Standardized Naming conventions
- Apt utilization of collection elements
- Follow of Trigger pattern
- Follow Trigger deactivation mechanism
- Avoiding Trigger recurrence on same object
- Proper Code comments
- Keeping Salesforce Governor limits into consideration
- Create test class to ensure developed code can be deployed; adhere to best practices of testing framework
public class OpportunityProductAndPriceBook_Handler
{
public static void AfterInsertOpportunity(List<Opportunity> records)
{
List<OpportunityLineItem> lineItem = new List<OpportunityLineItem>();
List<Pricebook2> priceBook = new List<Pricebook2>();
if(RecursiveTriggerHandler.isFirstTime)
{
RecursiveTriggerHandler.isFirstTime = false;
for(Opportunity opp : records)
{
if(opp.Add_Products__c)
{
OpportunityLineItem oli = new OpportunityLineItem();
oli.OpportunityId = opp.id;
oli.Product2Id = opp.Select_Product__c;
oli.Quantity = opp.Product_Quantity__c;
lineItem.add(oli);
Pricebook2 pb = new Pricebook2();
pb.Id = opp.Pricebook2Id;
pb.Name = opp.Price_Book__c;
priceBook.add(pb);
}
}
if(!lineItem.IsEmpty() && !priceBook.IsEmpty())
{
insert lineItem;
insert priceBook;
}
}
}
}
and this the error im getting from the code please help me
OpportunityProductAndPriceBook_Trigger: execution of AfterInsert caused by: System.StringException: Invalid id: GenWatt Diesel 1000kW Class.OpportunityProductAndPriceBook_Handler.AfterInsertOpportunity: line 18, column 1 Trigger.OpportunityProductAndPriceBook_Trigger: line 5, column 1
Regards
SFDCDoctorStrange
- SFDCDoctorStrange
- December 29, 2022
- Like
- 0
Urgent requirement Make this highlighted line Reusable in Apex Code
public class DuplicateLeadMergeHandler
{
public static void MergeLead(List<Lead> newLead)
{
Set<String> dupemails = new Set<String>();
Set<String> dupphones = new Set<String>();
Set<String> dupmobiles = new Set<String>();
Set<ID> leadID = new Set<ID>();
Map<String, Lead> masterLeadMap = new Map<String, Lead>();
for(Lead oldLead : newLead)
{
If(oldLead.Email != Null)
dupemails.add(oldLead.Email);
else
If(oldLead.Phone != Null)
dupphones.add(oldLead.Phone);
else
if(oldLead.MobilePhone != Null)
dupmobiles.add(oldLead.MobilePhone);
leadID.add(oldLead.id);
}
List<lead> oldLeadList = [SELECT Id, Name, OwnerId, MobilePhone, Email, Phone, Instagram_Handle__c, Website, Interested_Event_Locations__c, Vendor_Type__c, Items_Interested_in_Selling__c FROM Lead WHERE (Email IN: dupemails OR Phone IN: dupphones OR MobilePhone IN: dupmobiles) AND Id NOT IN: leadId AND IsConverted = false];
List<lead> newleadList = [SELECT Id, OwnerId, MobilePhone, Email, Phone, Instagram_Handle__c, Website, Interested_Event_Locations__c, Vendor_Type__c, Items_Interested_in_Selling__c FROM Lead WHERE (Email IN: dupemails OR Phone IN: dupphones OR MobilePhone IN: dupmobiles) AND Id IN: leadId AND IsConverted = false];
If(!oldLeadList.IsEmpty())
{
for(Lead oldLead: newLeadList)
{
If(oldLead.Email != Null)
masterLeadMap.put(oldLead.Email, oldLead);
else
If(oldLead.Phone != Null)
masterLeadMap.put(oldLead.Phone, oldLead);
else
if(oldLead.MobilePhone != Null)
masterLeadMap.put(oldLead.MobilePhone, oldLead);
}
If(masterLeadMap.size() > 0 && masterLeadMap != null)
{
Lead masterLead = new Lead();
for(Lead oldLead : oldLeadList)
{
If(masterLeadMap.containskey(oldLead.Email))
{
masterLead = masterLeadMap.get(oldLead.Email);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}
}
Else
If(masterLeadMap.containskey(oldLead.Phone))
{
masterLead = masterLeadMap.get(oldLead.Phone);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
}
Else
If(masterLeadMap.containskey(oldLead.MobilePhone))
{
masterLead = masterLeadMap.get(oldLead.MobilePhone);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}
}
}
}
}
}
}
{
public static void MergeLead(List<Lead> newLead)
{
Set<String> dupemails = new Set<String>();
Set<String> dupphones = new Set<String>();
Set<String> dupmobiles = new Set<String>();
Set<ID> leadID = new Set<ID>();
Map<String, Lead> masterLeadMap = new Map<String, Lead>();
for(Lead oldLead : newLead)
{
If(oldLead.Email != Null)
dupemails.add(oldLead.Email);
else
If(oldLead.Phone != Null)
dupphones.add(oldLead.Phone);
else
if(oldLead.MobilePhone != Null)
dupmobiles.add(oldLead.MobilePhone);
leadID.add(oldLead.id);
}
List<lead> oldLeadList = [SELECT Id, Name, OwnerId, MobilePhone, Email, Phone, Instagram_Handle__c, Website, Interested_Event_Locations__c, Vendor_Type__c, Items_Interested_in_Selling__c FROM Lead WHERE (Email IN: dupemails OR Phone IN: dupphones OR MobilePhone IN: dupmobiles) AND Id NOT IN: leadId AND IsConverted = false];
List<lead> newleadList = [SELECT Id, OwnerId, MobilePhone, Email, Phone, Instagram_Handle__c, Website, Interested_Event_Locations__c, Vendor_Type__c, Items_Interested_in_Selling__c FROM Lead WHERE (Email IN: dupemails OR Phone IN: dupphones OR MobilePhone IN: dupmobiles) AND Id IN: leadId AND IsConverted = false];
If(!oldLeadList.IsEmpty())
{
for(Lead oldLead: newLeadList)
{
If(oldLead.Email != Null)
masterLeadMap.put(oldLead.Email, oldLead);
else
If(oldLead.Phone != Null)
masterLeadMap.put(oldLead.Phone, oldLead);
else
if(oldLead.MobilePhone != Null)
masterLeadMap.put(oldLead.MobilePhone, oldLead);
}
If(masterLeadMap.size() > 0 && masterLeadMap != null)
{
Lead masterLead = new Lead();
for(Lead oldLead : oldLeadList)
{
If(masterLeadMap.containskey(oldLead.Email))
{
masterLead = masterLeadMap.get(oldLead.Email);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}
}
Else
If(masterLeadMap.containskey(oldLead.Phone))
{
masterLead = masterLeadMap.get(oldLead.Phone);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}}
Else
If(masterLeadMap.containskey(oldLead.MobilePhone))
{
masterLead = masterLeadMap.get(oldLead.MobilePhone);
If(masterLead != Null)
{
Task leadTask = new Task();
leadTask.WhoId = masterLead.Id;
leadTask.OwnerId = masterLead.OwnerId;
leadTask.Subject = 'Matched Lead - Follow Up';
leadTask.Status = 'In Progress';
leadTask.Priority = 'High';
leadTask.Description = 'Old Matched Lead Info \nLead Record Id :- '+oldLead.Id+'\nLead Name :- '+oldLead.Name+'\nEmail Address :- '+oldLead.Email+'\nMobile Phone :- '+oldLead.MobilePhone+'\nInstagram Handle :- '+oldLead.Instagram_Handle__c+'\nWebsite :- '+oldLead.Website+'\nInterested Event Locations :- '+oldLead.Interested_Event_Locations__c+'\nVendor Type :- '+oldLead.Vendor_Type__c+'\nItems Interested In Selling :- '+oldLead.Items_Interested_in_Selling__c+'';
insert leadTask;
System.debug(masterLead);
Database.MergeResult results = Database.Merge(masterLead, oldLead, false);
System.debug(results);
}
}
}
}
}
}
}
- SFDCDoctorStrange
- June 01, 2022
- Like
- 0
Apex Trigger for Merge lead with same email or phone and make new lead master lead
Created this Apex class
Thanks & Regards
SFDC Strange
public class DuplicateLeadMergeHandler { public static void MergeLead(List<Lead> newLead) { Set<String> emails = new Set<String>(); Set<String> phones = new Set<String>(); Map<String, Lead> masters = new Map<String, Lead>(); for(Lead ld : newLead) { emails.add(ld.Email); phones.add(ld.Phone); } emails.remove(null); phones.remove(null); for(Lead ld: [SELECT Id,Email,Phone FROM Lead WHERE (Email = :emails OR Phone = :phones) AND Id NOT IN :newLead AND IsConverted = false]) { If(ld.Email != Null) masters.put(ld.Email, ld); else If(ld.Phone != Null) masters.put(ld.Phone, ld); } for(Lead ld : newLead) { Lead master = new Lead(); If(masters != Null && masters.size() > 0 && masters.containskey(ld.Email)) { master = masters.get(ld.Email); } Else If(masters != Null && masters.size() > 0 && masters.containskey(ld.Phone)) { master = masters.get(ld.Phone); } If(master != null) { merge master ld; } } } }but its showing an errorplease help me solve this problem
Thanks & Regards
SFDC Strange
- SFDCDoctorStrange
- May 14, 2022
- Like
- 0
not Showing all values in Lightning Component Picklist
My lightning component all the picklist values from the related object
Aura Component
Aura Hepler
Aura Controller
please check and help me with the issue
thanks in advance
Himanshu
Aura Component
<div class="four wide column"> <label for="category-dropdown"><b>Select Category</b></label> <select id="category-dropdown" label="Category" class="ui small fluid selection dropdown"> <option value="{!v.defaultCategory}">--None--</option> <aura:iteration items="{!v.categoryOptions}" var="category"> <option value="{!category}">{!category}</option> </aura:iteration> </select> </div>
Aura Hepler
({ enableCategoryValues: function(component){ let action = component.get('c.getCategoryValues'); action.setParams({ 'recordId': component.get('v.recordId') }); action.setCallback(this, function(response){ let state = response.getState(); if(state === 'SUCCESS') { component.set('v.categoryOptions', response.getReturnValue()); component.set('v.catgoryFilterEnabled', true); }else{ console.error(JSON.stringify(response.getError())) } }) $A.enqueueAction(action) }, })
Aura Controller
@AuraEnabled public static List<String> getCategoryValues(String recordId) { List<String> catregories = new List<String>(); Schema.DescribeFieldResult fieldResult = SVMXC__Service_Order__c.Category__c.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry pickListVal : ple){ catregories.add(pickListVal.getValue()); } //catregories.sort(); system.debug('catregories : '+catregories); List<String> hasValueCategory = new List<string>(); Set<String> categorySet = new Set<String>(); List<sharinpix__SharinPixImage__c> sharinPixImageList = [select Id, sharinpix__AlbumID__c, sharinpix__ImagePublicId__c, Landscape_Portrait__c, sharinpix__FileName__c, sharinpix__ImageURLOriginal__c, Image_Thumbnail_F__c, sharinpix__ImageURLFull__c , CreatedDate, sharinpix__Tags__c, Work_Order__c, Work_Order__r.IP_Templates_Type__c, Work_Order__r.SVMXC__Component__c, Work_Order__r.Name, Work_Order__r.Start_Date_Time__c, sharinpix__Width__c, sharinpix__Height__c,sharinpix__Title__c, Image_Name__c, Work_Order__r.Category__c from sharinpix__SharinPixImage__c where sharinpix__AlbumID__c != null AND (NOT sharinpix__Tags__c LIKE '%After%') AND (NOT sharinpix__Tags__c LIKE '%Before%') AND (NOT sharinpix__Tags__c LIKE '%Time-Hrs%') AND Work_Order__r.SVMXC__Component__c =: recordId AND Work_Order__r.Category__c =: catregories ORDER BY Work_Order__r.Start_Date_Time__c, sharinpix__FileName__c, sharinpix__SortPosition__c]; if(sharinPixImageList != null){ for(sharinpix__SharinPixImage__c pix : sharinPixImageList){ if(pix.Work_Order__r.Category__c != null){ categorySet.add(pix.Work_Order__r.Category__c); } } } hasValueCategory.addAll(categorySet); return hasValueCategory; }
please check and help me with the issue
thanks in advance
Himanshu
- SFDCDoctorStrange
- February 19, 2022
- Like
- 0