4

We've recently had to start converting all our Javascript OnClick buttons to SF1 actions for the the new lightning UI. This is some of the code I've converted. It allows me to change the 'Status' of this record (which is a read-only custom field), but it redirects me to a new blank 'edit' page. From there I would need to hit the 'Cancel' button and refresh the page to get the value to show up correctly. Please, I need help on correcting the window location and have it redirect to the new 'version' of the record, or just refresh the page record itself. Thanks ahead of time for any input.

Old JavaScript OnClick Code:

{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} 
var newRecords = []; 
var e = new sforce.SObject("Event"); 
e.id ="{!Event.Id}"; 
e.Status__c = "Cancelled"; 
newRecords.push(e); 
result = sforce.connection.update(newRecords); 
window.location.reload();

New JavaScript Code for SF1 Action within a VF Page (issue):

<apex:page standardController="Event" >
<apex:includeScript value="/soap/ajax/35.0/connection.js"/>
<apex:includeScript value="/soap/ajax/35.0/apex.js"/>
    <script>   
        sforce.connection.sessionId = "{!$Api.Session_ID}";        
        var newRecords = []; 
        var e = new sforce.SObject("Event"); 
        e.id ="{!Event.Id}"; 
        e.Status__c = "Cancelled"; 
        newRecords.push(e); 
        result = sforce.connection.update(newRecords); 
    </script>
</apex:page>

Screenshots of the issues I'm encountering:

http://imgur.com/a/XZ507

  • 2
    Salesforce1 navigation dictates you should use sforce.one.navigateToSObject([RECORD_ID_HERE]); for navigation. You might be able to use something along Sfdc.canvas.publisher.publish({name: "publisher.close", payload:{ refresh:"true"}}); to refresh the record. – Antonio Manente Jan 7 '16 at 18:40
  • 2
    @AntonioManente Please add that as an answer .I see that as an answer .Thanks – Mohith Shrivastava Jan 7 '16 at 18:44
  • @MohithShrivastava done – Antonio Manente Jan 7 '16 at 18:47
3

As per the documentation here and here (more useful methods) It dictates that you use the method:

sforce.one.navigateToSObject([RECORD_ID_HERE]);

To navigate to the SObject.

For your case, use:

sforce.one.navigateToSObject(result[0].id);

I've also used:

Sfdc.canvas.publisher.publish({name: "publisher.close", payload:{ refresh:"true"}});

to refresh an object in salesforce1/lightning (should work if you're on the object's detail page, which seems not to be the case for you).

  • Would I use the 1st method or both? I just tried both and with no luck. Now it no longer changes the value. sforce.one.navigateToSObject([00U]); Sfdc.canvas.publisher.publish({name: "publisher.close", payload:{ refresh:"true"}}); – Joshua Davis Jan 7 '16 at 18:55
  • You would use one, the first is what's documented for Salesforce1 so I'd use that. This is updating a single record? Or could this be a bulk operation. @JoshuaDavis – Antonio Manente Jan 7 '16 at 18:58
  • 1
    sforce.one.navigateToSObject([RECORD_ID_HERE],'detail');Use your record Id appropriately . – Mohith Shrivastava Jan 7 '16 at 18:59
  • 1
    @JoshuaDavis Sorry, you'll need to include this <script src="/canvas/sdk/js/publisher.js"/> to use that. – Antonio Manente Jan 7 '16 at 20:27
  • 1
    No problem. Glad I could help! @JoshuaDavis – Antonio Manente Jan 7 '16 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.