-
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 8 years, 5 months ago by
Shaharyar.
-
This discussion was modified 8 years, 5 months ago by
Forcetalks.
-
This discussion was modified 8 years, 5 months ago by
Forcetalks.
-
This discussion was modified 8 years, 5 months ago by
Log In to reply.
Popular Salesforce Blogs
Salesforce for Nonprofits – Don’t miss out on these amazing benefits
Giving back has been part of the DNA of Salesforce. Since inception, the Global tech giant has been on a mission to empower Nonprofits through…
Salesforce Security using CRUD , FLS & Sharing Rules | Salesforce Guide
Salesforce is a cloud-based Customer Relationship Management (CRM) platform that allows businesses to manage their sales, marketing, and customer service activities in a more efficient…
The Salesforce Implementation Process: What Is It?
Salesforce implementation is the process of integrating and customizing the Salesforce platform to meet the specific needs of a business or organization. Salesforce is a…
Popular Salesforce Videos
Introduction to Salesforce Orchestrator
Flow Orchestrator was created so admins like you can quickly create sophisticated multi-user, multi-step automated business processes with clicks, not code. Experienced Salesforce Admins will…
Solving the Fizz Buzz (SSJS) in Salesforce Marketing Cloud
Cameron Robert from Datarati uses 2 different approaches to solve the Fizz Buzz programming challenge using SSJS Salesforce Marketing Cloud. What you'll learn: » How…
Marketing for Nonprofits Customer 360 Demo | Salesforce Video
Growing your nonprofit requires building relationships with lifelong supporters. Marketing Cloud for Nonprofits is a purpose-built marketing solution designed to help smaller nonprofits quickly and…