-
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
Automation in the Insurance Industry: Benefits and Salesforce Use Cases
Unstructured data is the key pain point that drives companies from various industries towards automation, and insurance is no exception. With automation, you'll be able…
Salesforce Revenue Cloud: The All-In-One Solution For Your Business Growth
Throughout the sales life cycle a company faces innumerable challenges. One of the most overwhelming moments takes place at the end of the cycle, when…
The Salesforce-Microsoft Partnership: Paving the Way for Win-Win Business Advantages
Salesforce was founded in early 1999 with a vision to create business applications in a completely different way, delivering software through a model known as…
Popular Salesforce Videos
Accenture Salesforce Training 2022
This video is about -Accenture Salesforce Training 2022 Orientation session and ASE SFDC Salesforce Certification. As the trusted leader in Salesforce implementation and transformation, Accenture can…
4 Tips on How to Build Product Messaging & Positioning That Stands Out | Salesforce on Salesforce
Messaging and positioning work together and should be the North Star for any product launch. If done well, it will set you apart from the…
How Leadership Skills Helps to Shape Your Career? | Salesforce Learning
Leadership is an important skill to have because a good leader is able to bring out the best abilities in his/her team members and motivate…