• Vedika Ghai
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi
I have been trying to pass this challenge (https://trailhead.salesforce.com/en/trails/force_com_dev_intermediate/modules/apex_integration_services/units/apex_integration_webservices):

To pass this challenge, create an Apex REST class that is accessible at '/Accounts/<Account_ID>/contacts'. The service will return the account's ID and Name plus the ID and Name of all contacts associated with the account. Write unit tests that achieve 100% code coverage for the class and run your Apex tests.
The Apex class must be called 'AccountManager'.
The Apex class must have a method called 'getAccount' that is annotated with @HttpGet
The method must return the ID and Name for the requested record and all associated contacts with their ID and Name.
The unit tests must be in a separate Apex class called 'AccountManagerTest'.
The unit tests must cover all lines of code included in the AccountManager class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.

I getting this error:

Challenge Not yet complete... here's what's wrong: 
Executing the 'AccountManager' method failed. Either the service isn't configured with the correct urlMapping, is not global, does not have the proper method name or does not return the requested account and all of its contacts.

This is my code:
 
@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {
	
    @HttpGet
    global static List<sObject> getAccount(){
        RestRequest request = RestContext.request;
        List<String> urlParams = request.requestURI.split('/');
        
        String accountId;	
        for(String param: urlParams){
            if((param != 'Accounts') && (param != 'contacts'))
                accountId = param;
        }
    
        List<Account> lstAccounts = new List<Account>();
        lstAccounts = [SELECT Id, Name FROM Account WHERE Id = :accountId];
        
        List<sObject> result = new List<sObject>();
        result.add(lstAccounts[0]);
        
        List<Contact> lstContacts = [SELECT Id, Name FROM Contact WHERE AccountId = :accountId];
        for(Contact c:lstContacts){
            result.add(c);
        }
        return result;
    }
}

This is my response
 
[ {
  "attributes" : {
    "type" : "Account",
    "url" : "/services/data/v39.0/sobjects/Account/001o0000015hgVBAAY"
  },
  "Id" : "001o0000015hgVBAAY",
  "Name" : "SFDC Computing"
}, {
  "attributes" : {
    "type" : "Contact",
    "url" : "/services/data/v39.0/sobjects/Contact/003o000001DbYc8AAF"
  },
  "Id" : "003o000001DbYc8AAF",
  "Name" : "Pepito Peres"
}, {
  "attributes" : {
    "type" : "Contact",
    "url" : "/services/data/v39.0/sobjects/Contact/003o000001BsUPwAAN"
  },
  "Id" : "003o000001BsUPwAAN",
  "Name" : "Last0"
} ]

Can someone light my way?​

Hi All,

I am trying to load photos into the chatter for around 1000 users. I am using code I found on github. (https://github.com/felixrivas/ChatterUtility). When I run the program, I get the following error

org.apache.http.conn.HttpHostConnectException: Connection to https://test.salesforce.com refused

      at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)

      at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)

      at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)

      at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:573)

      at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)

      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)

      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)

      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)

      at com.salesforce.chatter.provisioner.rest.ChatterRESTOAuthTokenStore.authenticate(ChatterRESTOAuthTokenStore.java:123)

      at com.salesforce.chatter.provisioner.rest.ChatterRESTOAuthTokenStore.initialize(ChatterRESTOAuthTokenStore.java:74)

      at com.salesforce.chatter.provisioner.rest.ChatterRESTOAuthTokenStore.getChatterRestAccessToken(ChatterRESTOAuthTokenStore.java:86)

      at com.salesforce.chatter.provisioner.rest.ChatterRESTOAuthTokenStore.getAccessToken(ChatterRESTOAuthTokenStore.java:96)

      at com.salesforce.chatter.provisioner.rest.ChatterRESTWrapper.performRESTQuery(ChatterRESTWrapper.java:609)

      at com.salesforce.chatter.provisioner.rest.ChatterRESTWrapper.retrieveUserIdFromFilenames(ChatterRESTWrapper.java:181)

      at com.salesforce.chatter.provisioner.rest.ChatterRESTWrapper.processFileUpload(ChatterRESTWrapper.java:89)

      at com.salesforce.chatter.provisioner.ChatterProvisioner.executeUserFileUploadProvisioner(ChatterProvisioner.java:114)

      at com.salesforce.chatter.provisioner.ChatterProvisioner.main(ChatterProvisioner.java:56)

Caused by: java.net.ConnectException: Connection refused: connect

      at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)

      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

      at java.net.PlainSocketImpl.connect(Unknown Source)

      at java.net.SocksSocketImpl.connect(Unknown Source)

      at java.net.Socket.connect(Unknown Source)

      at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)

      at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:375)

      at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)

      ... 16 more

 

I have tried setting the System properties in main but still the code does not work. Can someone please tell me how do I make a connection from Eclipse to access my sandbox.