• Gar Spencer
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Implementation Manager
  • Spencer & Franco Intl Consulting

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 6
    Replies
Has anyone tried to create a dupe check app using visual flows intead of apex?
Can someone show me how to build a trigger that

When an account record is saved and the field "Active_Buyers__c = True"  lets Call it Record A

that it loops through all accounts in system searching for account records where the field "Active_Seller__c = True" Lets call thes Record B
Then it runs a query of the records found and looks at the field "Max_Prince_Range__c" from record A  >= to the "Listed_Price__c"  field from Record B.

It then sends an email notification to the LastModifiedBy users email notifying them of the potentiam match and gives the user the name of the account, Account owner name and emaill address.
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});                               
            }       
        }   
}
}
I have written a trigger that when an account record is inserted or updated and the Active_buyers__c field equals True, it will search the system for all accounts that have the field Active_seller__c = true and the the List price from the account that has the active seller eqquals true is less than or equal to the price range of the account with the active buyers equal true.

If a match is found it would then send an email notification to the lastmodifiedBy user of the active seller equals true record to notify them of a potential buyer.

I am getting errors with this code and it will not compile..... 

Can someone look at my code and tell me where I went wrong?


trigger BuyerSellerMatchTrigger on Account (after insert, after update) {
        List<Account> buyerList=new List<Account>();
        Set<String> nameSet=new Set<String>();
        Set<String> citySet=new Set<String>();
        Set<String> emailSet;
        for(Account a:trigger.new){
            if(a.Active_buyers__c='True'){
                buyerList.add(a);
                nameSet.add(a.name);
           
            }
        }
        if(buyerList.size()>0 && nameSet.size()>0){
            List<Account> listOfAccounts=[select id,name,BillingCity,owner.email,Price_range__c from account where (name in :nameSet) and Active_seller__c='True'];
            Map<Id,Set<String>> mapOfAccounts=new Map<Id,Set<String>>();
            for(Account a:listOfAccounts){
                for(account trgrAccount:buyerList){
                    if(trgrAccount.Active_Seller__c='True' && trgraccount.list_price__c=a.Price_range__c){
                        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);
                        }
                    }
                }
            }
            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});                               
            }       
        }   
    }
My client is not using record type..... Account can be eith a buyer or seller. or both.
there are two sections on the account page. Buyers need is first section it contains 

Active_Buyer__c   datatype is checkbox (needs to be true)
Price_Range__c datatype is a pick list (containing min-max ranges) (ie; 100-200, 201-300, etc)

so when the Active_buyer__c is checked then the record saved it needs to look at all accounts in the system
and look for

Active_Seller__c = true  datatype is a checkbox and
Price_range__c (picklist)
       >=
to List_Price__c (which is a number field.)

and if there is a match an email notice needs to be sent to the LastModifiedBy user's email where the Active_seller__c = true.

also need a test coverage script for this
Hey can someone help me with a class and trigger?

I need to create a trigger that when record 1 populates fields a, b, c ,d on an account
it will search through all existing accounts and search for fields d,e,f,g that matche record 1's fields a,b,c,d.
then if records are found would populate a list of matching account names (as a hyperlink) to record 1.
and send an email notification to owners of records that were matched to record 1's criteria with the account name of the record 1
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});                               
            }       
        }   
}
}
I have written a trigger that when an account record is inserted or updated and the Active_buyers__c field equals True, it will search the system for all accounts that have the field Active_seller__c = true and the the List price from the account that has the active seller eqquals true is less than or equal to the price range of the account with the active buyers equal true.

If a match is found it would then send an email notification to the lastmodifiedBy user of the active seller equals true record to notify them of a potential buyer.

I am getting errors with this code and it will not compile..... 

Can someone look at my code and tell me where I went wrong?


trigger BuyerSellerMatchTrigger on Account (after insert, after update) {
        List<Account> buyerList=new List<Account>();
        Set<String> nameSet=new Set<String>();
        Set<String> citySet=new Set<String>();
        Set<String> emailSet;
        for(Account a:trigger.new){
            if(a.Active_buyers__c='True'){
                buyerList.add(a);
                nameSet.add(a.name);
           
            }
        }
        if(buyerList.size()>0 && nameSet.size()>0){
            List<Account> listOfAccounts=[select id,name,BillingCity,owner.email,Price_range__c from account where (name in :nameSet) and Active_seller__c='True'];
            Map<Id,Set<String>> mapOfAccounts=new Map<Id,Set<String>>();
            for(Account a:listOfAccounts){
                for(account trgrAccount:buyerList){
                    if(trgrAccount.Active_Seller__c='True' && trgraccount.list_price__c=a.Price_range__c){
                        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);
                        }
                    }
                }
            }
            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});                               
            }       
        }   
    }
Hey can someone help me with a class and trigger?

I need to create a trigger that when record 1 populates fields a, b, c ,d on an account
it will search through all existing accounts and search for fields d,e,f,g that matche record 1's fields a,b,c,d.
then if records are found would populate a list of matching account names (as a hyperlink) to record 1.
and send an email notification to owners of records that were matched to record 1's criteria with the account name of the record 1