function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rbensonrbenson 

Apex Trigger Help Needed - Customizing Find Nearby Accounts

I need some help with customizing a trigger. We use custom fields for addresses and would like to build a trigger to allow us to perform a radius search on zip codes or addresses. There is an app that lets you do this for standard address fields called FindNearbyAccounts. I am trying to rewrite the code to fit our org but i'm having trouble.

 

any thoughts?

 

current code:

trigger FindNearbyAccounts_KeepTidy on Account (before update) {
     for(Integer k=0; k<Trigger.new.size(); k++)
     {
        Boolean reset = false; 
        //If they change which Address to map 
        if(Trigger.new[k].Which_Address__c != Trigger.old[k].Which_Address__c)
        {
            reset = true; 
        }
        
        if(Trigger.new[k].Which_Address__c == 'Billing')
        {
            if(Trigger.new[k].BillingStreet != Trigger.old[k].BillingStreet || Trigger.new[k].Billingcity != Trigger.old[k].BillingCity ||
               Trigger.new[k].BillingPostalCode != Trigger.old[k].BillingPostalCode || Trigger.new[k].BillingState != Trigger.old[k].BillingState || Trigger.new[k].BillingState != Trigger.old[k].BillingState
               || Trigger.new[k].BillingCountry != Trigger.old[k].BillingCountry )
            {   
               reset = true;  
               
            }
        }
        else if(Trigger.new[k].Which_Address__c == 'Shipping')
        {
     
            if(Trigger.new[k].ShippingStreet != Trigger.old[k].ShippingStreet || Trigger.new[k].Shippingcity != Trigger.old[k].ShippingCity
             ||Trigger.new[k].ShippingPostalCode != Trigger.old[k].ShippingPostalCode || Trigger.new[k].ShippingState != Trigger.old[k].ShippingState  ||
             Trigger.new[k].ShippingCountry != Trigger.old[k].ShippingCountry)
            {
                  reset = true;  
            }
        }
        
        if(reset){
            Trigger.new[k].FNA_Status__c = 'Not Located Yet';
            Trigger.new[k].Lat__c = null;
            Trigger.new[k].Lon__c = null;
        }
        
     }//end FOR
}

 what i've tried to write:

trigger FindNearbyAccounts_KeepTidy on Account (before update) {
     for(Integer k=0; k<Trigger.new.size(); k++)
     {
        Boolean reset = false; 
        //If they change which Address to map 
        if(Trigger.new[k].Which_Address__c != Trigger.old[k].Which_Address__c)
        {
            reset = true; 
        }
        if(Trigger.new[k].Which_Address__c == 'Account_Mailing__c')
        {
            if(Trigger.new[k])'Mailing_Address__c';Trigger.old[k];'Mailing_Address__c'; } Trigger.new[k];'Mailing_City__c' != Trigger.old[k];'Mailing_City__c' ||
               Trigger.new[k];'Mailing_Zip_Postal_Code__c' != Trigger.old[k];'Mailing_Zip_Postal_Code__c' || Trigger.new[k];'Mailing_States_Provinces_Territories__c' != Trigger.old[k];'Mailing_States_Provinces_Territories__c' || Trigger.new[k];'Mailing_States_Provinces_Territories__c' != Trigger.old[k];'Mailing_States_Provinces_Territories__c'
               || Trigger.new[k];'Mailing_Country__c' != Trigger.old[k];'Mailing_Country__c';
            {   
               reset = true;  
                           }
        }
              }              
   //end FOR

 

dmchengdmcheng

It looks like your trigger code has lots of typos.  Where did the semi-colons and single quotes come from?  It might be easier for you to debug if you start with just one of your custom fields and get the code working properly, then all you have to do is add fields to the IF statement.

rbensonrbenson

Thanks. I think the problem is I am not sure if it should be a trigger on the contact or the task?

 

The semi colons came from the errors that Salesforce spit back at me. I'm not a developer (obviously) so I'm having a lot of trouble!

dmchengdmcheng

A triggers fires on the object where a change/insert/delete is made.  If you are changing the contact address field, then the trigger should be on the contact object.

 

Have you looked at the tutorials and documentation available on the developer website?

http://wiki.developerforce.com/index.php/Documentation

 

There are also some Apex tutorials available as podcasts on iTunes - search for Salesforce and look at the DEV501 podcasts.

hwcbarryhwcbarry

Hi,

 

I am interested in customizing this to map address from other custom fields.  

 

I am not a developer - any thoughts on how I can find someone that I could hire to do this?

 

thanks