You need to sign in to do that
Don't have an account?
Gar Spencer
Trigger has bugs...... Is there a shorter way to do what I am trying to accomplish in APEX?
I have made changes and it is still not compiling or saving to SFDC..... here is my modified code after debugging. Can anyone see what I am missing.
First thing that should happen is when a new buyer record is saved or updated (identified by the Active_Buyers__c) field is search through system for records that have (Active_Seller__c) field checked.
Then it should query the account records and pull the ID, name, List Price, Price Range, Owner Email, and Last Modified Email. from the account object where the List Price <= to the Price range and store the results temporarily.
After matches are returned there should be an email notification sent to the LastModifiedByID.email of the record that has the Active Seller field checked. with the
Subject being New Buyer Found,
Body should contain the account name (hyperlink) owner name and owner email of the account with the Active buyers field checked
trigger BuyerSellerMatchTrigger on Account (after insert,after update){
// Capture all records that have Active_Buyers__c field equals true
List <Account> BuyerList = new List<Account>();
Set<String> nameSet= new Set<String>();
Set<String> emailSet;
Boolean Active_Buyers = true;
for(Account a:trigger.new){
if(Active_Buyers__c) {
buyerList.add(a.);
nameSet.add(a.name);
}
}
//check to determine size and the query fields of accounts for the buyer list
if(buyerList.size()>0 && nameSet.size()>0){
List<Account>listOfAccounts=[ select id, name, owner.email, Maximun_Price_Range__c, Price_range__c
from Account where (name in: nameSet) and Active_Seller__c = True and Listed_Price__c <= Price_Range__c];
//Map the result set of active buyers to active sellers
Map<Id, Set<String>>mapOfAccounts=new Map<Id, Set<String>>();
for(Account a:listOfAccounts){
for(account trgrAccountbuyerList){
if(trgrAccount.Active_Seller__c = True){
if(mapOfAccounts.containsKey(trgrAccount.id)
&&!mapOfAccounts.get(trgrAccount.id).contains(a.owner.email))
}
}
emailSet=mapOfAccounts.remove(trgrAccount.id);
emailSet.add(a.owner.email);
mapOfaccounts.put(trgrAccount.id,emailSet);
}
else {
emailSet=new Set<String>();
emailSet.add(a.owner.email);
mapOfaccounts.put(trgrAccount.LastModifiedByid,emailSet);
}
}
}
}
// Email notification trigger
for(Id idey:mapOfaccounts.keySet()){
String emailMessage='Buyer Email account-https://na7.salesforce.com/'+ idey;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses=new List<String>();
toAddresses.addAll(mapOfaccounts.get(idey));
mail.setToAddresses(toAddresses);
mail.setReplyTo('noreply@salesforce.com');
mail.setSenderDisplayName('Buyer Email');
mail.setSubject('Subject');
mail.setPlainTextBody(emailMessage);
mail.setHtmlBody(emailMessage);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
}
}
}
}
First thing that should happen is when a new buyer record is saved or updated (identified by the Active_Buyers__c) field is search through system for records that have (Active_Seller__c) field checked.
Then it should query the account records and pull the ID, name, List Price, Price Range, Owner Email, and Last Modified Email. from the account object where the List Price <= to the Price range and store the results temporarily.
After matches are returned there should be an email notification sent to the LastModifiedByID.email of the record that has the Active Seller field checked. with the
Subject being New Buyer Found,
Body should contain the account name (hyperlink) owner name and owner email of the account with the Active buyers field checked
trigger BuyerSellerMatchTrigger on Account (after insert,after update){
// Capture all records that have Active_Buyers__c field equals true
List <Account> BuyerList = new List<Account>();
Set<String> nameSet= new Set<String>();
Set<String> emailSet;
Boolean Active_Buyers = true;
for(Account a:trigger.new){
if(Active_Buyers__c) {
buyerList.add(a.);
nameSet.add(a.name);
}
}
//check to determine size and the query fields of accounts for the buyer list
if(buyerList.size()>0 && nameSet.size()>0){
List<Account>listOfAccounts=[ select id, name, owner.email, Maximun_Price_Range__c, Price_range__c
from Account where (name in: nameSet) and Active_Seller__c = True and Listed_Price__c <= Price_Range__c];
//Map the result set of active buyers to active sellers
Map<Id, Set<String>>mapOfAccounts=new Map<Id, Set<String>>();
for(Account a:listOfAccounts){
for(account trgrAccountbuyerList){
if(trgrAccount.Active_Seller__c = True){
if(mapOfAccounts.containsKey(trgrAccount.id)
&&!mapOfAccounts.get(trgrAccount.id).contains(a.owner.email))
}
}
emailSet=mapOfAccounts.remove(trgrAccount.id);
emailSet.add(a.owner.email);
mapOfaccounts.put(trgrAccount.id,emailSet);
}
else {
emailSet=new Set<String>();
emailSet.add(a.owner.email);
mapOfaccounts.put(trgrAccount.LastModifiedByid,emailSet);
}
}
}
}
// Email notification trigger
for(Id idey:mapOfaccounts.keySet()){
String emailMessage='Buyer Email account-https://na7.salesforce.com/'+ idey;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses=new List<String>();
toAddresses.addAll(mapOfaccounts.get(idey));
mail.setToAddresses(toAddresses);
mail.setReplyTo('noreply@salesforce.com');
mail.setSenderDisplayName('Buyer Email');
mail.setSubject('Subject');
mail.setPlainTextBody(emailMessage);
mail.setHtmlBody(emailMessage);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
}
}
}
}
kiranmutturu
May I know what is the issue that you are getting while saving the code?
Gar Spencer
i get an error saying that need to enable email for user profile, but it is enabled.