You need to sign in to do that
Don't have an account?
Kathryn Bullock
Need help with a trigger
Hi,
I am trying to write a trigger that will call the class whenever an update is made to the record. I believe I am doing this wrong and I have many problems. How do I write this trigger?
My class:
My trigger:
I am trying to write a trigger that will call the class whenever an update is made to the record. I believe I am doing this wrong and I have many problems. How do I write this trigger?
My class:
public class DrivingDistance1 { public static void m1() { geopointe.API.DistanceService ds = new geopointe.API.DistanceService(); List<Account> accList = [SELECT id, distance1__c, UCO_Service_Provider__r.Geopointe_Geocode__r.geopointe__Latitude__c, UCO_Service_Provider__r.Geopointe_Geocode__r.geopointe__Longitude__c, geopointe__Geocode__r.geopointe__Latitude__c, geopointe__Geocode__r.geopointe__Longitude__c FROM Account LIMIT 1]; List<Account> origins = new List<Account>(); List<Account> destinations = new List<Account>(); for(Integer i = 0; i < accList.size(); i++){ if(Math.mod(i,2) == 0) { origins.add(accList.get(i)); } else { destinations.add(accList.get(i)); } } for(Integer i = 0; i < origins.size(); i++){ ds.add((Double)origins.get(i).geopointe__Geocode__r.geopointe__Latitude__c, (Double)origins.get(i).geopointe__Geocode__r.geopointe__Longitude__c, (Double)destinations.get(i).UCO_Service_Provider__r.Geopointe_Geocode__r.geopointe__Latitude__c, (Double)destinations.get(i).UCO_Service_Provider__r.Geopointe_Geocode__r.geopointe__Longitude__c); } for(Integer i = 0; i < origins.size(); i++){ Double distance = ds.getDistanceAtIndex(i); origins.get(i).distance1__c = distance; destinations.get(i).distance1__c = distance; } update accList; } }
My trigger:
trigger DrivingDistanceTrigger on Account (after update) { geopointe__Geocode__r.geopointe__Latitude__c[] = Trigger.new; DrivingDistance1.m1(distance); }
first since your trigger on Account. Trigger.New will return List of Account so you have to pass list of account from trigger to handler
And your method should accept the list of account