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
BenPBenP 

Use a trigger to fire a custom url

I have this custom url that is used to get the lat/long for a record.  What I'd like to do is tack that function onto a trigger so that if the address is updated, the lat/long gets updated too.

This url sends the parameters to a VF page which processes that with the help of a class and updates the record.  The page and class are part of a managed package, so I can't see the class code.  I'm in a pinch, so I'm hoping to get something going quick.  I can work with the developer, but that will take weeks when I have days.

/apex/SVMXC__COMM_validateAddress?objID={!SVMXC__Service_Group__c.Id}&objName=SVMXC__Service_Group__c&street=Address__c&city=City__c&state=State__c&country=Country_Code__c&zip=Zip__c&latitude=Latitude__c&longitude=Longitude__c
Best Answer chosen by BenP
Peter_sfdcPeter_sfdc
So what is happening right now? 

Is the code you show here what you are using now? 

Have you tried something and received errors? 

Have you attempted something with a trigger and not gotten it to work? 

Are you just looking for the code to cut/paste into a trigger? 

I'm sorry, but your question is a little vague. I'm sure people would like to help, but it is very difficult to tell where to begin with how you have worded your question. 

I'll take a stab at a few things that might help. 
1. First of all calling a VF page from a trigger is not as straightforward as you might imagine. It has to be done using http callout asynchronously if you want to initiate it from a trigger. Triggers, can be blocking on the completion of a transaction. The platform behaves in a way that is averse to waiting for undetermined amounts of time (like an HTTP response) so we do not allow you to initiate the callout without doing it from a method annotated as @future. This decouples the callout from the trigger context, allowing the db commit to complete while the http callout finishes on its own time. Check out the docs on future annotation (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm" target="_blank) and be sure to pay attention to the bit about enabling HTTP callouts. 
2. You will want to look at the classes: Http, HttpRequest, and HttpResponse in the Apex guide (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_http.htm" target="_blank) to perform your request to the VF page. These are well documented with many examples both in our docs and in blogs by community members, so I'll not waste space here reproducing this. 
3. Finally you will need to enable your salesforce domain for callouts using remote site administration. This wiki addresses this (http://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts" target="_blank), along with a number of other topics relating to callouts (albeit to external services). 

Of course, if you just want to invoke some apex code behind a VF page controller, calling it this way is perhaps not the best. I understand they are wrapping gps coord mapping features, but as this page is perhaps not meant to be exposed in this way, you may be in for unexpected results. 

Let me know if this was of any help. 

All Answers

Peter_sfdcPeter_sfdc
So what is happening right now? 

Is the code you show here what you are using now? 

Have you tried something and received errors? 

Have you attempted something with a trigger and not gotten it to work? 

Are you just looking for the code to cut/paste into a trigger? 

I'm sorry, but your question is a little vague. I'm sure people would like to help, but it is very difficult to tell where to begin with how you have worded your question. 

I'll take a stab at a few things that might help. 
1. First of all calling a VF page from a trigger is not as straightforward as you might imagine. It has to be done using http callout asynchronously if you want to initiate it from a trigger. Triggers, can be blocking on the completion of a transaction. The platform behaves in a way that is averse to waiting for undetermined amounts of time (like an HTTP response) so we do not allow you to initiate the callout without doing it from a method annotated as @future. This decouples the callout from the trigger context, allowing the db commit to complete while the http callout finishes on its own time. Check out the docs on future annotation (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm" target="_blank) and be sure to pay attention to the bit about enabling HTTP callouts. 
2. You will want to look at the classes: Http, HttpRequest, and HttpResponse in the Apex guide (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_http.htm" target="_blank) to perform your request to the VF page. These are well documented with many examples both in our docs and in blogs by community members, so I'll not waste space here reproducing this. 
3. Finally you will need to enable your salesforce domain for callouts using remote site administration. This wiki addresses this (http://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts" target="_blank), along with a number of other topics relating to callouts (albeit to external services). 

Of course, if you just want to invoke some apex code behind a VF page controller, calling it this way is perhaps not the best. I understand they are wrapping gps coord mapping features, but as this page is perhaps not meant to be exposed in this way, you may be in for unexpected results. 

Let me know if this was of any help. 
This was selected as the best answer
BenPBenP
Everything works fine now, it's just manual.  Knowing that calling this from a trigger is not very easy pretty much answers my question.

I thank you for your response.