Friday, December 22, 2017

2018 Resolution - More Posts!!!


I use to try and post to this and another blog, frequently and I have definitely let that slip! So, for 2018, I resolve to put a post a week on here. It is a great way to create a knowledge base for myself as well as share that knowledge with others. I am starting to get back into Swift development as well so hopefully there will be a lot of opportunities to share my experiences with Salesforce Development in general, Salesforce Lightning development and iOS development, along with anything else I happen to experience. So, for everyone who has come here in the past and commented, thank you! I look forward to sharing new things with everyone, next year. Have a happy holidays and a Merry Christmas and see you next year!

Tuesday, August 5, 2014

Visualforce Remoting and Standard Page Layouts or cross domain @remoteAction errors....

So, I ran into a problem that is clearly covered in the SFDC Pages documentation.  Hopefully I have this titled and tagged in enough ways, so that other people who run into this issue, don't spend as much time as I did, Googling for an answer.

Anyway, if you are trying to access a remote action from a Standard Layout or some other iFrame in Salesforce, make sure your class and method are both global!!

The answer can be found HERE, about a third of the way down.

Thursday, May 1, 2014

Salesforce1 Developer Week Challenge walk-through....

Hopefully Salesforce doesn't mind me posting this but I was working on it with someone and it was getting late and I said I'd post my solution.  Anyway, I went to the Salesforce1 developer week Meetup, in Denver, CO, last night and it was awesome!  As usual it was a fun event with a great atmosphere and a lot of cool people to mingle with.  Anyway, onto the code!

Here was the challenge and the requirements:

Challenge 
Take the shipment application page included and integrate it into Salesforce1.  Add the ability to quickly access the page from the mobile app, and use the mobiles app's native functionality to create a shipment request.

Requirements
  1. Install schema package : http://bit.ly/sfdc-shipment
    • If you already have the Warehouse package and the Mobile design Templates installed, this has a few components that will conflict, you may want to get a new org, at least that's what I did.     
  1.  Add a Javascript publisher method to the globalShipmentPage that will enable the 'Submit' button when someone selects a merchandise record from the start page.
  2. Add a Javascript subscription method to the page that will invoke the remote action 'insertShipment' in the included globalShipmentController with the appropriate fields from the form and close the publisher on success.
  3. Create a Visualforce global action for the globalShipmentPage and add it to the global layout.
  
 Example of the completed action.
The Work

Installing the package in your org will create a new App called 'Shipments' with the following tabs : Merchandise and Shipments.  You'll want to go in and add a few Merchandise items first.  Next, I went and skipped ahead to step 4, so that I could do testing while I worked on my code, using /one/one.app appended on to the end of my org url, in Chrome.  (ie : https://na10.salesforce.com/one/one.app)

So, for step 4, I went to Develop > Pages > globalShipmentPage : Edit, and checked the Available for Salesforce mobile apps checkbox, to make it available in Salesforce1.  The next step was to go create a Global Action.  To do this navigate to Create > Global Actions : New Action.  As long as the mobile checkbox has been checked on the VF page, you should have it listed in the Visualforce Page dropdown on the setup screen. Here is an example :
 

Once you are done with this, click Save.  Now navigate to Chatter > Publisher Layouts and Edit the Global Publisher Layout.  Drag your newly created Publisher Action to the Publisher Actions area and click SaveAny Page layout that is using the Global Layout will now have this Action Available when clicking the "+" in the lower corner of the screen.

Now back to step 2, adding the code to enable the "Select" button!  Open the developer console and from there : File > Open > Pages : globalShipmentPage.  To enable the submit button or any of the other publisher events, the first thing you have to do is include the following javascript library UPDATED

Apparently, this script link no longer works, or I was getting errors in my dev org while using it for something else.
<script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script> 

The new link is :

<script type='text/javascript' src='/canvas/sdk/js/29.0/publisher.js'></script>

This has actually already been included on line 18 of the provided code!

You can find all of the publisher Events in the SF1 Cheat sheet, which can be found here.
To enable the 'Submit' button you need to include the following code somewhere in your code :

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

Since we don't want the publisher button to be available before a piece of Merchandise has been selected, I placed the code in the function that gets appended to the link created for each merchandise item in the search results, at line 112 : newLink.click(function(e) { ...  

 newLink.click(function(e) {
                                e.preventDefault();
                                           
                                $("#merchName_result").text(mName);
                                $("#merchId_result").text(mId);
                                $("#searchPage").hide();
                                $("#resultPage").show();
                                Sfdc.canvas.publisher.publish({ name : "publisher.setValidForSubmit", payload:"true"});
                            });


Now when a user selects a merchandise item, it will enable the submit button.

The next step is to add the code which  will run when the user clicks the "Submit" button.  I added this at line 38, inside of the jquery.ready function 

Sfdc.canvas.publisher.subscribe({name: "publisher.post", onData:function(e) {submitShipment(); }});  

The submitShipment function, is the callback that is called when the button is clicked.  This is where we will capture our values and then call our remote action from, in the following step!

Step 3!  Inside the submitShipment function, the first thing we need to do is grab our values from the user input.  I created some variables to store the data in and then went ahead and just used jQuery selectors to assign them.  There are a few ways that it could be done though...

 var merchId, quantity, status, receivedAt;           
           
 //get doc id values and assign to variables...
        merchId = $("#merchId_result").text();
        quantity = $('input[id$=shipment_quantity]').val();
        status = $('select[id$=shipment_status] option:selected').val();
        receivedAt = $('input[id$=shipment_receivedAt]').val();
Next, I checked to make sure the quantity, status, and received date, all had values.  If they do not, I alert the user.  If they do, I call my remote action from the globalShipmentController.

if(quantity == '' || status == '' || receivedAt == '')
            {
                alert("All values must be entered to submit a shipment!");
             } else {
               
        //visulaforce remote action call with parameters passed to it
        Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.globalShipmentController.insertShipment}',
        merchId, quantity, status, receivedAt,
        function(result, event){
            if (event.status) {
               
                //if the result is good, this will close the publisher action
                Sfdc.canvas.publisher.publish({ name : "publisher.close", payload : { refresh:"true" }});
            } else if (event.type === 'exception') {
                alert(event.message);
               
            } else {
                alert(event.message);
              
            }
        },
        {escape: true}
    );
       
      } 

If you are unfamiliar with  VF remote Actions, you can read about them here and there is a nice example here.

You are pretty much done now.  If you haven't been testing this, you can do so either by logging into Salesforce1 on your mobile device or as I said earlier, by going to https://yourinstance.salesforce.com/one/one.app, then by navigating to a record for an object that has the global publisher layout and clicking on the publisher action icon.  An easy place is from the Feed!  Chrome is a nice way to test this since you can use the web dev tools, to see what is going on. Once you create a new shipment, you can click on your Feed from the top of the Salesforce1 navigation Menu, at the left of the screen; and will see a feed item for your new shipment record!

Hopefully this walkthrough has made sense and was fun to use while completing the Salesforce1 Code Challenge!

I want to thank Salesforce for a fun night and event, the free drinks, the shirt, and the SF1 Hoodie!

If you would like to  learn more about how Salesforce1 works and the framework it is developed on, check out this video on Aura.   



          

 



 



Tuesday, July 23, 2013

Writing Unit Tests...For everything in SFDC!

Unit tests have been covered on tons of different blogs by tons of way more qualified developers but I figured I'd write an entry which compiles all the best info I have found around the net.  I really like to reference my own blog as a resource master, so this will help a future me out, as well! :)

 First and foremost is the official Developer force page on writing good unit tests, which can be found HERE.  It talks about structure and what to do and not to do.

Second I would recommend going over the information found HERE, regarding the IsTest annotation.  This covers @isTest(SeeAllData=true) , which is a must have if you have to write code against things like the PriceBook2, which will return no rows during tests.

Next I would check out the usual suspects where good coding examples can be found.  Places like Jeff Douglas's blog.  He has a nice entry on writing Unit Tests f  or Visual Force Controller Extensions, which can be found HERE.  Another really good reference is Tquila Team, and they cover a bunch of cool topics on writing Unit Tests, HERE.

One other thing to be aware of is, test.isRunningTest() for your controller or trigger code.  Sometimes if you don't want a section of code to be hit by a test you can wrap it in an If statement testing this system test method.  The details about it can be found on the test method's page, HERE.  Along with a lot of other useful info regarding the test class and its methods.

I figure I should include some code in this posting so, I'll write a Unit Test for both a standard trigger  and a Visual Force page, which will instantiate its Custom Controller/Extension...I guess I'll put a snippet for both, since an extension has to have the Standard Object passed to it, as seen in JD's blog posting.  More later....






     
            
           
     

Wednesday, June 26, 2013

SFDC WSC Repository : MVN

Salesforce, seems to have moved the WSC builds from GitHub over to MVNRepository.  All builds can be found here:

http://mvnrepository.com/artifact/com.force.api


Tuesday, April 2, 2013

Visualforce : Using Maps in PageBlockTables...

So I had never used a Map in a PageBlockTable before. Today I did. I'll reference this Blog, since this is where I stumbled on the info. Harshesh's Blog Apparently the key is to use Value[var] to access the data in the map, within the visualforce pageblocktable. Here is an example:

     
            
           
     

if you are using a custom class in your controller or extension then it would look something like this:

Now, why would you want to do this? I'll give you a full blown example here. Let's say you want to do some work on the selected row and you need the whole rows data: ..will update later with this!

Friday, March 8, 2013

Testing Google prettyPrint...

This is a test page with some code on it!

Here is the code:


function myFunc(cb){ if($(cb).is(':checked')){ //alert("checked!!!"); $('input[name$="oliCheck"]').prop("checked",true); }else{ $('input[name$="oliCheck"]').prop("checked",false); } //console.log(tName); }