-
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, 12 months ago by
Shaharyar.
-
This discussion was modified 8 years, 12 months ago by
Forcetalks.
-
This discussion was modified 8 years, 12 months ago by
Forcetalks.
-
This discussion was modified 8 years, 12 months ago by
Log In to reply.
Popular Salesforce Blogs
The Open Web Application Security Project | Salesforce Developer Guide
OWASP (Zed Attack Proxy) is an Open-Source Web Application Security Extend. It is wanting to be used by both those unused to application security just…
Top Zoho Consulting Services in Australia & Dubai
Zoho Consulting Services in Australia & Dubai: Find the Right Partner for Your Business In today’s fast-paced digital world, businesses need powerful tools to stay…
Make your Salesforce life easy with Salesforce advanced code searcher and ORGanizer for Salesforce
Salesforce advanced code searcher and ORGanizer for Salesforce, both are google chrome's extensions which adds an extra features to your salesforce org. Salesforce advanced code…
Popular Salesforce Videos
Journey To A Salesforce Solution Architect
A Salesforce Solution Architect must master a number of skills to be able to solve complex business requirements. In this session, we will cover 10…
Salesforce Summer 20 Dynamic Forms
Salesforce’s Summer ’20 Release Notes have now been published, we can now dive under the hood to see what the top features are! Historically, Summer…
Connect Marketing Cloud with Salesforce CRM | PART 1
Salesforce Marketing Cloud is a customer relationship management (CRM) platform for marketers that allows them to create and manage marketing relationships and campaigns with customers.…