-
How to create unique contacts in Salesforce depending on the value of number of location field in account object?
I have created a trigger on account object and want to insert or update number of contacts depending on the value of number of location field in Account Object.
While using List<Contacts> it's working and gives list of contacts with same name.
But i want to use Set<Contact> to get unique contacts????
#trigger
trigger numberOfLocations on Account (after insert, After Update) {
Set<contact> listContact = new Set<contact>();//When I replace Set<Contact> With List<Contact> it's working and gives the list of contacts which is not unique.
map<id,decimal> mapAcc=new map<id,decimal>();
for(Account acc:trigger.new){
mapAcc.put(acc.id,acc.NumberofLocations__c);
}
if(mapAcc.size()>0 && mapAcc!=null){
for(Id accId:mapAcc.keyset()){
for(integer i=0;i<mapAcc.get(accId);i++){
contact newContact=new contact(AccountId=accId,LastName='MyContact');// I don't want to use 'MyContact'+i bcz i want to check the functionality of Set<Contact>
listContact.add(newContact);
}
}
}
if(listContact.size()>0 && listContact!=null)
upsert listContact;
}#error
DML requires SObject or SObject list type: Set<Contact>
- This discussion was modified 6 years, 8 months ago by Shaharyar.
- This discussion was modified 6 years, 8 months ago by Forcetalks.
- This discussion was modified 6 years, 8 months ago by Forcetalks.
Log In to reply.
Popular Salesforce Blogs
Top 7 Salesforce Trends For 2022
Every technology we know is updating itself rapidly. If you do not keep an eye on the new additions, you might miss some amazing benefits…
The Future Of Development On Salesforce Is With Lightning Experience
As per the Salesforce release of 2017 a number of features has been added to the Salesforce Lightning Platform. The enterprises which are using Salesforce…
Bric Enterprise - Customised Business Card Management Software
Business card scanners / APPS are an important tool for most organizations to effectively manage customer contacts, leads etc. The requirement may vary from one company to…
Popular Salesforce Videos
Guided Selling with Salesforce CPQ
Do you know how to set up guided selling in Salesforce CPQ? In this demo video, we'll show you three easy steps to set up…
How to Enable the New Pardot Email Builder | Salesforce Pardot
Learn how to set up the new Email Builder for Pardot and set up Salesforce CMS for email content storage. Watch this video and do…
Salesforce Service Cloud Overview Demo
Service Cloud is a complete service solution built on the Salesforce platform that lets you quickly adapt to change, to deliver trusted service from anywhere.…