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

Getting the current logged in user and account info

I have created a custom object which is related to Account object.
Whenever I want to create the new custom object record I need to insert the acount id also.
But how can I retrieve the current logged in account info or user info.
What I am trying to do is creating a s-control to override the new entry form with our UI and submitting the data to salesforce using salesforce objects.
Thanks in advance.
If it's related to the Account object then you can just put a related list for it on the Account layout.  When you press the New button for your object on that related list then the Account will automatically be prepopulated in that lookup screen, no Scontrol required.
Or is this custom object intended for the Customer Portal?
I would like to change the UI for the edit and new entry form instead of using the sales force UI, that is the reason I created an scontrol.
Is there any other to customize the UI for that forms.
Yes, as I said, you can override the New and Edit buttons to point to your Scontrol or to your Visualforce page.

Thanks for your response.

I have created a scontrol with textboxes and a submit button and on submit click calling the salesforec object to insert new record as below

<script src="/soap/ajax/12.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">
function add()

var account = new sforce.SObject("PFUDocument__c");
account.Doc_Url= "";
account.Title= "test333";
account.Account = 123;

var result = sforce.connection.create([account]);
if (result[0].getBoolean("success")) {
log("account with id " + result[0].id + " updated");
} else {
log("failed to update account " + result[0]);


<body bgcolor=#f3f3ec>
<input type="text" id="url" value=""/>
<input type="text" id="title" value=""/>
<input type="submit" id="save" onClick="add();"/>

As you see in the code I need to pass the account info to create.
Could you provide me a sample code to change UI of edit or new forms.
Look in Help & Training about merge fields.  To pass in the account in Javascript you just give it a string like '{!Account.Id}' and it will be automatically replaced by the value.
Hello PFU,

The only issues with the merge fields that werewolf explains is if the field contains multiple lines, like a two lined street address. This will cause errors when your s-control runs. The easiest way to work around this is to query the record with the value placing the field in a variable instead of using the merge field. By not displaying it in the code it prevents the \n from messing with it.