-
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, 2 months ago by
Shaharyar.
-
This discussion was modified 9 years, 2 months ago by
Forcetalks.
-
This discussion was modified 9 years, 2 months ago by
Forcetalks.
-
This discussion was modified 9 years, 2 months ago by
Log In to reply.
Popular Salesforce Blogs
What is the Appointment Setter Role?
An appointment setter is the primary factor of contact among a potential patron and a business. Their primary obligation is to time table meetings or…
Salesforce Data Cloud vs. Traditional Data Warehouses: Which wins for AI?
The rise of Artificial Intelligence (AI) has forced a major shift in corporate data strategy. Companies no longer just store data. They now need data…
What is the Grant Management System in Salesforce? | All You Need to Know
Grant Management in Salesforce is a component of the Nonprofit Success Package (NPSP). In this package, Salesforce will award her 10 free licenses to some…
Popular Salesforce Videos
DreamTX Welcome Day 4: Skill Up with Trailhead | Dreamforce 2020 | Salesforce
If you missed DreamTX DAY 4, then live this amazing experience here, we have covered it all for you. Learn about the latest innovation on…
5 Tips: How Events Can Help You Drive Value for Your Business | Salesforce on Salesforce
Events are at the heart of every major launch moment and announcement. They offer opportunities to connect with customers, providing experiences that grow loyalty. And…
Salesforce On-Demand Administrator
Apphienz's On-demand Administrator delivers much more than the company's expectations. It is hands-on, makes the work easy, efficient and productive along with being available to…