-
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 7 years, 4 months ago by Shaharyar.
- This discussion was modified 7 years, 4 months ago by Forcetalks.
- This discussion was modified 7 years, 4 months ago by Forcetalks.
Log In to reply.
Popular Salesforce Blogs
Taking Its Lead From Siri & Alexa, Salesforce Introduces Einstein Voice!
Incorporating voice assistant into a platform for managing tasks verbally is something which has been around for quite some time now. Apple’s Siri, Microsoft’s Cortana,…
Improve Customer Service Productivity with Salesforce Knowledge Base
After you have sold an app, product, or service to your clients, how much time do your service agents spend with the clients, explaining to…
Salesforce Lightning Experience: Main Reasons Why Salesforce Classic is Fading
Introduction "Salesforce Classic is at its Death-End and s going to be okay!" These things are creating a buzz in the online Salesforce Lightning world.…
Popular Salesforce Videos
How to Delete Preloaded Sample Data in New Salesforce Organizations
When Users begin a trial or subscription with Salesforce, their org comes with a set of sample data. This data includes Accounts, Contacts, and Opportunities.…
Salesforce training video for beginners
Salesforce is an innovative tool that can be very powerful when used properly. That’s why it’s important to find effective and trustworthy ways to learn…
What are lookup filters in Salesforce?
In this video, we will leaarn about Lookup Filters in Salesforce by dividing this topic into 4 basic points, which are: 1. What is a…