• Duncan_Stewart
  • NEWBIE
  • 10 Points
  • Member since 2013
  • Principal Business Applications Analyst
  • NxStage Medical, Inc.


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies
I'm getting incrementally closer to completing this challenge (thank you to all who have contributed elsewhere), but I don't see this particular issue having been reported.  I've got the AnimalLocator, 'Mock & Test running fine, but hitting this unauthorized endpoint error when I check the challenge: 

System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://th-apex-http-callout.herokuapp.com/animals/99

Remote Site Settings as described in module

I tried cloning the URL as a new Remote Site with '/animals' (or '/animals/') appended, but it keeps getting truncated back to this ^.

My AnimalLocator class is as follows: 
 
public class AnimalLocator {
    
    // Use a GET callout to retrieve an animal name
    public static String getAnimalNameById(Integer animalId) {
        Integer id = animalId;
        String result = '';
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + id);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        // If the request is successful, parse the JSON response.
        if (response.getStatusCode() == 200) {
            // Deserializes the JSON string into collections of primitive data types.
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            System.debug('results = ' + results);
            // Cast the values in the 'animals' key as a list
            Map<String, Object> animal = (Map<String, Object>) results.get('animal');
            System.debug('Received the following animal:' + animal.get('name'));
            result = (String)animal.get('name');
            
        }
        return result;
    }

}


 
In the Service Console, I have a button on Contact that leverages a VF controller & javascript to create a Case, save it, and display the new Case in a subtab.  The Case opens in view mode, the CaseNumber is displayed as the subtab title, and the page layout is the correct layout for the new Case's recordtype.  The custom console components defined for that layout are not displayed, however.

When I go to the Contact's Cases related list and select a Case of that same ^ recordtype, the page opens and displays the components correctly.

I use srcUp() in the button to open my Visualforce page that creates the Case; javascript on the page then opens the subtab to display it.  adding &isdtp=vw or =nv doesn't change the functionality -- case still loads as if it weren't in the console.

Button:
srcUp('apex/NxConsoleCaseCreation?ci={!Contact.Id}&isdtp=nv')

subtab method:
var openSubTabs = function openSubTabs(result) {
        // use the caseId from the controller extension to determine the URL
        sforce.console.openSubTab(result.id, '/' + '{!caseId}', true, 'Select Case RecordType', null);
	}

Thoughts?
I'm trying to replace a custom Console written in VF with just the VF search component and then direct the user into a Service Console app where they can view the Contact details and/or create/edit a Case, etc.  The VF-only console provided a search facility which then dropped you into a Case Edit detail, but now the browsers no longer allow a visual.force.com url to open a salesforce.com url within the same context.

The URL of the console detail page is straightforward, but you can only open a page in the console if you're already in the console.  Does anyone know a way around this?
[Also posted under same title at StackExchange - just covering my bases]
We've had a custom VF console page for some time with a commandButton that opens a new Case in edit mode once a user selects the recordtype and hits [Update].  The method called updates the workFrameURL with the appropriate parameters and the button's rerender attribute refreshes a section of the page with the new Case detail.  Unfortunately, the rerender is no longer working.

Per the StackExchange suggestion, I've added additional ids and changed the rerender from just the id of the outputPanel to the $Component.<parent>.outputPanelId, but there's been no change.  It's probably cleaner to respond directly to the StackExchange post, but to save time I'll post the code snippets here as well:

Controller method:
public void updateCaseRecordType(){
     this.displayCaseIFrame = true;
     if(this.selectedRecordType != null){
        this.workFrameURL = this.workFrameUrlRoot + '&RecordType=' + this.selectedRecordType + '&ent=Case';
     } else {
         this.workFrameURL = this.workFrameUrlRoot;
     }
   }
The VisualForce:
<apex:page showHeader="false" sidebar="false" id="tsConsolePage" title="Tech Support Console" controller="NxTechSupportConsoleController" 
	action="{!doitall}" cache="false" id="consolePage" >

     <!-- related content removed for relevance / space considerations -->   
     
     <apex:define name="workarea" >
        	<apex:actionRegion id="workArea" >
	        	<apex:outputPanel id="recordTypeSelector">
	        		<span style="font-weight:bold;font-size:1.1em;">Record Type: &nbsp;&nbsp;</span>
	        		<apex:selectList value="{!selectedRecordType}" multiselect="false" size="1">
	        			<apex:selectOption itemValue="" itemLabel="Select a Record Type:" />
	        			<apex:selectOptions value="{!caseRecordTypes}" />
	        		</apex:selectList>
	        		&nbsp;&nbsp;
	        		<apex:commandButton value="Update" action="{!updateCaseRecordType}" 
	        							rerender="{$Component.workArea.caseDisplayPanel}" />
	        		<br/>
	        	</apex:outputPanel>
	        	<apex:outputPanel id="caseDisplayPanel">
	        		<apex:outputPanel id="internalWrapper" rendered="{!displayCaseIframe}">
			            <apex:iframe width="950px" id="caseIFrame" src="{!workFrameURL}" height="4000px" ></apex:iframe>
			            <apex:outputPanel id="tempPanel" rendered="{!NOT(displayCaseIframe)}" >
			            	<br/> This section is displayed until a record type is selected for the case. <br/>
			            </apex:outputPanel>
		            </apex:outputPanel>
	            </apex:outputPanel>
            </apex:actionRegion>
        </apex:define>



I'm working on My First REST Service (soon to be released), leveraging all of the howTo's that I can find, starting with Apex REST Basic Code Sample.

I created the MyRestResource class using the example, brought up curl, and was stopped abruptly on this line:

  • Replace sessionId with the <sessionId> element that you noted in the login response.

There isn't anything preceding this line ^ that describes how to get that initial login response that contains the session Id.

 

Trying a different tack, I reviewed the article Setting Up Authentication with OAuth 2.0, installed the OAuth Playground, and set up the Connected App with the OAuth settings that would be used to access my service.

 

Can someone point me to

  1. An Apex code sample for a method that can access an Apex REST service, using the Consumer Key and Secret (or whatever their OAuth 2.0 labels are now) created in the Connected App
  2. An Apex code sample (if different from 1., above ^) that can retrieve and make use of the sessionId described in the REST Basic Code sample
  3. The Salesforce Request Token URL (for the OAuth Playground)
  4. The Salesforce Access Token URL (for the OAuth Playground)

Any and/or all of the above will be greatly appreciated.

 

Thanks!

 

Duncan

(initially posted under Apex -- moving to API discussion thread)

I'm getting incrementally closer to completing this challenge (thank you to all who have contributed elsewhere), but I don't see this particular issue having been reported.  I've got the AnimalLocator, 'Mock & Test running fine, but hitting this unauthorized endpoint error when I check the challenge: 

System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://th-apex-http-callout.herokuapp.com/animals/99

Remote Site Settings as described in module

I tried cloning the URL as a new Remote Site with '/animals' (or '/animals/') appended, but it keeps getting truncated back to this ^.

My AnimalLocator class is as follows: 
 
public class AnimalLocator {
    
    // Use a GET callout to retrieve an animal name
    public static String getAnimalNameById(Integer animalId) {
        Integer id = animalId;
        String result = '';
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + id);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        // If the request is successful, parse the JSON response.
        if (response.getStatusCode() == 200) {
            // Deserializes the JSON string into collections of primitive data types.
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            System.debug('results = ' + results);
            // Cast the values in the 'animals' key as a list
            Map<String, Object> animal = (Map<String, Object>) results.get('animal');
            System.debug('Received the following animal:' + animal.get('name'));
            result = (String)animal.get('name');
            
        }
        return result;
    }

}


 
Getting Below error, component is working fine but cant complete the challenge. Any help is appreciated.

Error- Challenge Not yet complete... here's what's wrong: 
The campingList component either does not have an attribute named 'newItem' or it is not defined correctly. It should default to a Camping_Item__c object with the price and quantity set to 0.

Below is the Markup for camping list:

<aura:component >
    <aura:attribute name="items" type="Camping_Item__c[]"/>    
    
    <aura:attribute name="newItem" type="Camping_Item__c"  
                    default="{'sobjectType':'Camping_Item__c',                              
                                  'Name':'',
                                   'Quantitiy__c':0,
                                  'Price__c':0,                                  
                                  'Packed__c':false }"/>
    
    
    
    <!--<ol>
        <li>Bear Repellant</li>
        <li>Bug Spray</li>
        <li>Goat Food</li>
    
    </ol>-->
    
    <lightning:layout >
        
        <fieldset class="slds-box slds-theme--default slds-container--small">
            
            <legend class="slds-text-heading--small">
                
                Add Camping
            
            </legend>
            
            <form class="slds-form-stacked">
                
                <lightning:input aura:id="campingform"
                                 label="Name"
                                 name="name"
                                 value="{!v.newItem.Name}"
                                 required="true"/>
                
                <lightning:input aura:id="campingform"
                                 type="number"
                                 label="Price"
                                name="price"
                                value="{!v.newItem.Price__c}"
                                min="0.1"
                                formatter="currency"
                                step=".01"
                                 messageWhenRangeUnderflow="Enter amount greater than $.10"/>              
                                
                <lightning:input aura:id="campingform"
                                label="Quantity"
                                name="quantity"
                                value="{!v.newItem.Quantity__c}"
                                min="1"
                                type="number" messageWhenRangeUnderflow="Enter minimuim 1 Quantity"/>
                                
                 <lightning:input aura:id="campingform" 
                                  label="Packed"
                                  name="packed"
                                  value="{!v.newItem.Packed__c}"
                                  type="checkbox"/>
                
                <lightning:button label="Create Camping Item" 
                              class="slds-m-top--medium"
                              variant="brand"
                              onclick="{!c.clickCreateItem }"/>
            
            </form>
        
        
        </fieldset>
    
    
    </lightning:layout>

    <lightning:card title="Camping Item">
        <p class="slds-p-horizontal--small">
            
            <aura:iteration items="{!v.items}" var="item">
                <c:campingListItem item="{!item}"/>
            </aura:iteration>
            
        </p>
     
     </lightning:card>   
    
</aura:component>
 
I'm trying to replace a custom Console written in VF with just the VF search component and then direct the user into a Service Console app where they can view the Contact details and/or create/edit a Case, etc.  The VF-only console provided a search facility which then dropped you into a Case Edit detail, but now the browsers no longer allow a visual.force.com url to open a salesforce.com url within the same context.

The URL of the console detail page is straightforward, but you can only open a page in the console if you're already in the console.  Does anyone know a way around this?

Anyone know of a way to get the Week of the Month (number 1 to 5 depending on month/calendar) in Apex Classes?

If there is custom code that someone has built, please let me know.  THANKS.

 

 

I only found Day of Year for the Salesforce datetime methods.

 

example:  Day of Year

 

Datetime myDate = datetime.newInstance(2008, 2, 5, 8, 30, 12);
system.assertEquals(myDate.dayOfYear(), 36);