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
IraIra 

How to add a trigger to write to a file the currently accessed Account ID

I would like to be able to write to a file on the local computer, the Account ID of the account the user is currently accessing.

 

I found the AJAX code that will write to a file, but I don't know how to add this code to a Trigger.

The Trigger being: User has loaded an account.

 

 

Any help would be great. Thanks.

Ira

 

Sample AJAX code:

 

function WriteFile()
{

var fh = fopen("c:\\MyFile.txt", 3); // Open the file for writing

if(fh!=-1) // If the file has been successfully opened
{
    var str = Account.ID; 
    fwrite(fh, str); // Write the string to a file
    fclose(fh); // Close the file
}

}

WriteFile();

AvromAvrom

This would kind of break MVC--trigger code is really for model-related stuff, not for stuff that goes on on the user's machine. Think of it this way: There are all *sorts* of ways a new account might get added: The user using a VF page, workflow, *another* trigger, etc. In most of these contexts, "write a file on the user's machine" doesn't make any sense, because there may *be* no current user.

 

Better, I think, to tie this to the Save button on the page, or onLoad for wherever the Save button goes on success, etc.

 

 

ShikibuShikibu

I heartily second what Avrom said. But I would like to ask why do you want to do this? 

If you are trying to debug something, consider Setup/Monitoring/Debug logs.

 

If you are trying to track the history of changes, consider enable track changes to fields of interest on Account. 

IraIra

Shikibu, Thank you for responding.

 

Here is the scenerio:

 

A user will access VF and select an Account to be displayed.

 

My program, a VB application running on the same machine, will need to know which Account the user just selected.

 

Once the VB app knows which Account was selected, it will be able to Query, via the Web API, the SF database to get all the associated telephone numbers for that Account.

 

The VB app will now be able offer any found telephones to the user to be used to make callouts via their Call Management System (my VB app will be able to command the CMS to make calls for the user) and subsquently keep statistics on those calls to be logged in the SF database; Time of call, number called, duration, ...

 

So, what trying to get is the Account.ID and User.Name placed in a record in a table that my VB app will monitor (query every few seconds).

 

OR

 

Since the VB app is running on the same user's machine, have a file created locally with the same information.

I could also create an ActiveX componet in the VB app that possibly APEX or JAVA could use to send that information to the VB app.

 

OR

 

If you or anyone has a better idea.

 

Please keep in mind, I know very little about SF, APEX, JAVA, ...

I can get VB to do everything else. All I need is to get the Account.ID and User.Name

 

If something needs to be writen in APEX, JAVA, ..., and added to VF, I have no idea how to do that. 

 

Thanks for taking the time to assist,

 

Ira

Message Edited by Ira on 01-26-2010 10:03 AM
AvromAvrom

Full disclosure: I'm not a VB or ActiveX programmer, so I know only the basics of how those technologies work. But it sounds like you have that part handled.

 

VF pages, in general, tolerate any non-namespaced XML you put in them. So you could certainly put an ActiveX reference inside your VB page.

 

I think that, in this case, you probably want to call the ActiveX reference from Javascript; in particular, the onload method of the page. If you use apex:inputHidden tags (such as <apex:inputHidden value="{!Account_id}" id="accId" />) to load your acct ID and username in to the form, you can refer to these fields in Javascript when you call your ActiveX control.

 

Note that there are security restrictions on calling ActiveX components from pages (depending on the user's security settings), but I assume you know about those as an ActiveX programmer.

 

But I think this is probably a better strategy than writing to a file and polling that file, unless you are assuming really weird massive-numbers-of-sessions-from-the-same-machine usage patterns.

 

Hope this helps,

Avrom

 

ShikibuShikibu

I don't do VB, but a quick google tells me that you can write web services in VB. So you should be able to use VF to create a page that displays the account and some content served by VB. Or, add a vf page as a mini page to a standard account layout.

 

Then the VB accepts the web service call and delivers, as html, the content you want to display. VF displays it on one page along with the SFDC content.

 

Very little VF skill needed, but you will need to figure out how to make VB provide a web service, and create a call out (probably just an url) that hands vb a unique id for the account.

 

By the way, I'm agreeing again with all that Avrom said, just offering some clarifying ideas. 

Message Edited by Shikibu on 01-26-2010 10:50 AM
IraIra

OK, this looks like it could work.

 

 

Yes, I can create an ActiveX VB project. (DLL or EXE) that will get the phone numbers from SFDB

 

No, I can't write in APEX to create the referaence to the ActiveX object in my VB appliction.

Perhaps you could help me with that if you know how I would do it in VB.

 

In VB I would access the ActiveX this way:

 

Supose my registered DLL is named "SendSF.DLL". My class is named "clsSFInfo". With a function

 

"GetTelNumbers(AccountID as String, UserID as String) as Boolean"

 

I would bind to the object this way:

 

Dim obGetTelnumbers as Object

 

Set obGetTelnumbers = CreateObject( "SendSF.clsSFInfo" )

 

It looks like in your apex code the accountID is "!Account_ID" which I assume contains the Account ID the user has just accessed?

Let say in my example, the account ID is assigned to Account_ID and the User ID is User_ID

 

I would then pass the Account_ID and User_ID to the DLL by:

 

Dim Success as Boolean

Success = obGetTelnumbers(Account_ID, User_ID)

 

 

Now, if someone could help rewriting this VB example into APEX code and how to add this to VF, I think we would solved this issue.

  

Thanks,

Ira

Message Edited by Ira on 01-27-2010 10:09 AM