You need to sign in to do that
Don't have an account?
Mokshada
salesforce flow for whenever a new opportunity is created amount should be updated on opportunity
I have a apex Trigger on contact if we have contact related account the number of opportunities will be updated in amount like amount = no.of contacts*1000
trigger trigoncontact on Contact (after insert, after delete) {
List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
Set<Id> accountIds = new Set<Id>();
if (Trigger.isInsert) {
for (Contact contact : Trigger.new) {
accountIds.add(contact.AccountId);
}
}
if (Trigger.isDelete) {
for (Contact contact : Trigger.old) {
accountIds.add(contact.AccountId);
}
}
List<Account> accounts = [SELECT Id, (SELECT Id, Amount FROM Opportunities), (SELECT Id FROM Contacts) FROM Account WHERE Id IN :accountIds];
for (Account acc : accounts) {
List<Contact> contacts = acc.Contacts;
List<Opportunity> opportunities = acc.Opportunities;
for (Opportunity opportunity : opportunities) {
opportunity.Amount = contacts.size() * 1000;
opportunitiesToUpdate.add(opportunity);
}
}
update opportunitiesToUpdate;
}
now I want to create salesforce flow for whenever a new opportunity is created at that time also amount should be updated on opportunity. can anyone help how to do that ?
Thanks,
trigger trigoncontact on Contact (after insert, after delete) {
List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
Set<Id> accountIds = new Set<Id>();
if (Trigger.isInsert) {
for (Contact contact : Trigger.new) {
accountIds.add(contact.AccountId);
}
}
if (Trigger.isDelete) {
for (Contact contact : Trigger.old) {
accountIds.add(contact.AccountId);
}
}
List<Account> accounts = [SELECT Id, (SELECT Id, Amount FROM Opportunities), (SELECT Id FROM Contacts) FROM Account WHERE Id IN :accountIds];
for (Account acc : accounts) {
List<Contact> contacts = acc.Contacts;
List<Opportunity> opportunities = acc.Opportunities;
for (Opportunity opportunity : opportunities) {
opportunity.Amount = contacts.size() * 1000;
opportunitiesToUpdate.add(opportunity);
}
}
update opportunitiesToUpdate;
}
now I want to create salesforce flow for whenever a new opportunity is created at that time also amount should be updated on opportunity. can anyone help how to do that ?
Thanks,