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
VintaraVintara 

sforce.one.editRecord throws an Uncaught SyntaxError: Unexpected token ILLEGAL

Can't seem to get sforce.one.editRecord to work.... anyone have any thoughts as to what I can try? Litterly just passing it the id in the standard controller.
Rajkumar VenkatRajkumar Venkat
my guess is Id in query statement is not passing as string.. ex: its trying to pass as  Id=0EHN0000 instead of id='0EHN0000'.. 
 
VintaraVintara
Nope. Its passed as a string, though I did try it without the quotes as well just as a sanity check, no effect.
Rajkumar VenkatRajkumar Venkat
to make sure there is issue with only in the passing parameter, have you tried to hardcode the id value and tested successful? 
VintaraVintara
No mater the value I pass, I get the same behavior. I can inspect the javascript, and it looks correct. Which is why I'm a bit baffled. It is literally as simple as the following. 

<script>
sforce.one.editRecord('{!Order.Id}');
</script>
Rajkumar VenkatRajkumar Venkat

above method should work and i used to write the code in the below option1 to do more validation which is similar to your code. 

Option 1
var orderid= '{!Order.Id}';
or 
Option 2 ( for test case)
var orderid = '018sN0000000DScL'(some order record id )

sforce.one.editRecord(orderid);
Madhanprabhu Thangadurai 1Madhanprabhu Thangadurai 1
Hi Vintara,

Hope this will be helpful. Here i'm just passing the hard-coded id value instead of that pass the dynamic id. '{!Order.Id}'. I think you should specify the script type in your code.
<script type="text/javascript">
if( (typeof sforce.one != 'undefined') && (sforce.one != null) )
{
     sforce.one.editRecord('{!Order.Id}');
}
</script>

The below script is working for me.
<apex:page showHeader="false" >
<script src="/soap/ajax/33.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">
function navigateToEdit() {
    if( (typeof sforce.one != 'undefined') && (sforce.one != null) ) {
         sforce.one.editRecord('001900000135hg2');
    }
}
</script>
<apex:form >
<apex:commandLink value="Navigate to link" onclick="navigateToEdit();"/>
</apex:form>
</apex:page>

 
VintaraVintara
I think I see the problem... the page this is running on is an override for the default edit action. The idea being to do some validation and give an instruction page before opening the edit view. However, it seems that sforce.one.editRecord is just calling the edit action, which is overridden by the page, so we get into a nice loop of sorts.

Far as I can tell, there is no way to actually open a record for edit. Which seems a bit ridiculous.
VintaraVintara
What I guess I'll need to do is remove the edit action from the layout and make a new edit button that calls the page which in turn calls the default edit action.
Madhanprabhu Thangadurai 1Madhanprabhu Thangadurai 1
No. You can open a record for edit action. I have implemented this kind of scenario before for custom Salesforce1 record detail page. 
IdanieIdanie
@Madhanprabhu Thangadurai 1
Can you please enlight us with a simple example / explanation?
I would like to redirect to the detault SF1 edit.
I overriden the edit with a direction page that in turn decide to wich page to redirct etc.

Many thanks.