• Write your post
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I am stuck with Data Integration Specialist superbadge challenge #4. While trying to run the test i am getting an error  'Methods defined as TestMethod do not support Web service callouts'. Below are my code:

@IsTest
public class ProjectCalloutServiceMock implements HttpCallOutMock{
   //Implement http mock callout here
    public HttpResponse respond(HttpRequest req)
    {
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setStatus('OK');
        res.setStatusCode(201);
        return res;
    }
}

@Istest
public class ProjectCalloutServiceMockFailure implements HttpCallOutMock {
   //Implement http mock callout failure here
   public HttpResponse respond(HttpRequest req)
    {
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setStatus('Error');
        res.setStatusCode(500);
        return res;
    }
}

@isTest
private class ProjectCalloutServiceTest {
  //Implement mock callout tests here
  @testsetup
  public static void setupdata()
  {
      List<Opportunity> oppsToInsert = new List<Opportunity>();
      
      Account acct = new Account();
      acct.Name='test Account';
      insert acct;
      
      Opportunity opp1 = new Opportunity();
      opp1.Name = 'Opp1';
      opp1.Type='New Customer';
      opp1.AccountId = acct.id;
      opp1.amount=500;
      opp1.CloseDate = date.today();
      opp1.StageName = 'Prospecting';
      oppsToInsert.add(opp1);
      
      Opportunity opp2 = new Opportunity();
      opp2.Name = 'Opp2';
      opp2.Type='New Customer';
      opp2.AccountId = acct.id;
      opp2.amount=2500;
      opp2.CloseDate = date.today().addDays(-3);
      opp2.StageName = 'Prospecting';
      oppsToInsert.add(opp2);
      
      insert oppsToInsert;
      
      ServiceTokens__c st = new ServiceTokens__c();
      st.Name = 'ProjectServiceToken';
      st.Token__c = 'thisistesttoken';
      insert st;
      
  }
    
   @istest
    public static void testSuccessMessage()
    {
        Opportunity oppList = [Select Id from Opportunity where Name='Opp1' limit 1];
        List<Id> oppIds = new List<Id>();
        oppIds.add(oppList.Id);
        Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMock());
        test.startTest();
            ProjectCalloutService.postOpportunityToPMS(oppIds);
        test.stopTest();
        oppList = [Select StageName from Opportunity where Name='Opp1' limit 1];
        system.assertEquals('Submitted Project',oppList.StageName);
    }
    
    @istest
    public static void testFailureMessage()
    {
        Opportunity oppList = [Select Id from Opportunity where Name='Opp2' limit 1];
        List<Id> oppIds = new List<Id>();
        oppIds.add(oppList.Id);
        Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMockFailure());
        test.startTest();
            ProjectCalloutService.postOpportunityToPMS(oppIds);
        test.stopTest();
        oppList = [Select StageName from Opportunity where Name='Opp2' limit 1];
        system.assertEquals('Resubmit Project',oppList.StageName);
    }
}
Hi there :)

i'm currently working on an native Android app for my company and ran into some problems with Salesforce lately.

I hope i can find some help here.

What i want to achieve:
The company has a lot of Accounts in Salesforce with 3 important fields for the app: Name, Business (Workshop or Parts Dealer) and location(latitude, longitude)
I would like to show those Accounts(Workshops/Parts Dealers) as markers on a google map in my Android app based on a radius around the user's current location. So it would be more than sufficient to get the data as JSON or XML(i read about sObjects, which would be nice too)

The app will be freely available on Google Play Store and every user should be able to see all the Workshops/Parts dealers around the world.

The problem i'm facing is that i can't find a way to fetch the data inside my app without authenticating every user with a Salesforce-Login. 
Which API is the best to use in this case?

It would be so awsome if anybody could help me with this problem.

What i tried so far: 
- SalesforceMobileSDK: If i extend SalesForceApplication i always end up with the Salesforce-Login Screen.
It seems that every client has to be authenticated for API-calls to work. I tried using the method "peekUnauthenticatedRestClient", but this method only works on full path URL's(e.g. "https://api.spotify.com/v1/search?q=James%20Brown&type=artist"), which isn't really practically for my Use-case.

- I feel like i read nearly all docs about salesforce api, but can't quite get my head around how to solve this problem, although it seems like to be a pretty common use-case.  

- would a salesforce-apex method which would select all records inside a set radius around the user's location be accessable without authentication?

Thanks for your help in advance!

Roman