-
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 9 years, 1 month ago by
Shaharyar.
-
This discussion was modified 9 years, 1 month ago by
Forcetalks.
-
This discussion was modified 9 years, 1 month ago by
Forcetalks.
-
This discussion was modified 9 years, 1 month ago by
Log In to reply.
Popular Salesforce Blogs
Driving engagement and Sales using Salesforce Marketing Cloud and Pardot
Digital marketing has seen explosive growth in the recent years due to the high adoption of digital technologies. According to Mary Meeker’s Internet Trends Report…
What is Einstein Analytics in Salesforce and How it Works?
Each business collects ample amounts of data, the volume of which grows day after day: customer database, analytics of interaction with customers at each stage…
Navigate your Career in Salesforce | Salesforce Guidance
How to start a career in Salesforce as a fresher or how to switch in Salesforce from any technology or domain? Salesforce is a Saas-based…
Popular Salesforce Videos
Salesforce Customer 360 Data Manager
Salesforce Customer 360 Data Manager is a cross-cloud integration capability that allows Salesforce admins and developers to combine and reconcile customer data from their Salesforce…
How To Become a Salesforce Developer [Perfect Guide for Beginners]
Curious about a career in Salesforce development? Our video is your concise guide to getting started. What's inside:→ The average salary for a Salesforce Developer…
What benefits Salesforce Email integration provides for my business?
This video puts light on the benefits of Salesforce Email Integration for Business. Every aspect of Email Integration is provided and discussed in detail along…