-
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 6 years, 8 months ago by Shaharyar.
- This discussion was modified 6 years, 8 months ago by Forcetalks.
- This discussion was modified 6 years, 8 months ago by Forcetalks.
Log In to reply.
Popular Salesforce Blogs
New release of Salesforce Marketing Cloud went live on June 17
Good news for all those who are eagerly waiting for Salesforce Marketing Cloud new release. With great new features and overall enhancements, the Salesforce Marketing…
Integration Using Named Credentials | Salesforce Developer Guide
The Following are the Benefits of Using Named Credentials: A Named credential specifies the end URL of the callout and its verification parameters required in…
Top 10 Salesforce Apps that Your Company Needs
Enterprise mobile apps are gaining ground as more and more Salesforce teams are taking advantage of the cloud-based services in the enterprise space. This saves…
Popular Salesforce Videos
Salesforce Chatter Tutorial | Chatter Overview And Demo | Chatter In Salesforce
This Salesforce Chatter Tutorial will give an overview of Chatter which includes enabling chatter, configuring chatter groups and creating customer groups. Salesforce Chatter will be…
Break up Salesforce Record Detail into Tabs | Salesforce Lightning Page Layouts
In this video, Signiforce briefs about how to create an Action with a subset of fields from your object and then add this action to…
The 3 Most Common Challenges Associated With B2b Commerce Cloud Implementations
With growing technology businesses are adapting to the new changes. B2B commerce cloud is one of them. But to implement the B2B commerce cloud is…