You need to sign in to do that
Don't have an account?

How do I clear a custom field?
Hello,
I've got a trigger that is set to write geocode to a location field on the accounts page when an address is updated.
The trigger code is:
This works great - but what I am running into is the trigger will not fire if the Location__Latitude__s isn't null - that is to say if it already has geocode in it from a previous address, it won't put new geocode in because the field isn't empty.
How can I set this trigger to clear the field whenever the address is updated?
I've got a trigger that is set to write geocode to a location field on the accounts page when an address is updated.
The trigger code is:
// Trigger runs getLocation() on Accounts with no Geolocation trigger SetGeolocation on Account (after insert, after update) { for (Account a : trigger.new) if (a.Location__Latitude__s == null) LocationCallouts.getLocation(a.id); }
This works great - but what I am running into is the trigger will not fire if the Location__Latitude__s isn't null - that is to say if it already has geocode in it from a previous address, it won't put new geocode in because the field isn't empty.
How can I set this trigger to clear the field whenever the address is updated?
If I understand corrcetly, you could just remove the if statemnet so this trigger will always fire, something like this:
Please remember to mark this thread as solved with the answer that best helps you.
Regards
Stephen
Thank you for your response - Unfortunetly that doesn't work, I had already tried that - you would think it would, but since the field already has a variable the way my trigger pulls from an apex class it doesn't overwrite.
I need to have something like
to clear the field before the trigger runs. However, that code doesn't work either....
There has got to be an easy way to clear a field....
Clearing the field is as simple as saying 'Object.FieldName = null' For example, if I wanted to clear the Account Name it would be something acc.Name = null.
Can you post the rest of the trigger so we can see what you are trying to do and better help you.
Regards,
Stephen
The class that the trigger calls on is called LocationCallouts, see the code below:
This converts the address of an account to geocode. The trigger is set to write that geocode to field "Location__c".
However, if someone updates the account address, it won't write to the field because there is already geocode there. I need to set the trigger to clear that field whenever a change to the address on the account is made.
Thank you for your help.
Appologies but I am not sure I understand. From the code you have posted above, there is nothing in place to check if the field is populated or not? From what I can tell, this only occurs in your trigger where you check if the lattitude field equals null. So, if you remove the if statement on line 5, then the code will always execute.