• venkatesh kotapati
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Requirement
apex class calls webservice to retrieve product information. I have to schedule this class to run at night 10 pm everyday and write test class for the callout.
Solution:
I have written apex class which does the callout and upsert product object. Since I have to schedule this update i called the apex class from schedule class. As I cannot do synchronous callouts in schedule apex i have made the method as asychronous(@future) (asynchronous methods has no return type). When i have to achieve 100% code coverage for apex class which calls webservice i have to mock the callout and generate a fake response. The problem in this solution is that future methods has no return type and the test class that mocks the callout expects response.
Appreciate your responses.

Apex class:
global class Inventorycallout
{
    @future(callout=true)
    global static void inventorycall () 
    {
        Map<String, Object> m1 = new Map<String, Object>();
        List<Product2> productlist = new List<Product2>();
           
        Http http = new Http();    
        HttpRequest request = new HttpRequest();
              
        String endpoint = 'https://th-superbadge-apex.herokuapp.com/equipment';
        request.setMethod('GET');
        request.setEndpoint(endpoint);
        HttpResponse response = http.send(request);
        system.debug(response.getBody());
        List<Object> responselist = (List<Object>) JSON.deserializeUntyped(response.getBody());
        for(Object o : responselist)
        {
            Product2 pr = new Product2();
            m1 = (Map<String, Object>)o;
            pr.Replacement_Part__c= (Boolean)m1.get('replacement');
            pr.Current_Inventory__c = (Decimal)m1.get('quantity');
            pr.Name= (string)m1.get('name');
            pr.Maintenance_Cycle__c= (Decimal)m1.get('maintenanceperiod');
            pr.Lifespan_Months__c= (Decimal)m1.get('lifespan');
            pr.Warehouse_SKU__c= (string)m1.get('sku');
            productlist.add(pr);
        }
if(productlist.size() > 0)
        {
                Schema.SObjectField f = Product2.Fields.Warehouse_SKU__c;
                Database.UpsertResult [] cr =  Database.upsert(productlist,f,false);
}

Test class:
@isTest(seeallData = false)
private class inventorycallouttest
{    
   static testmethod void testrun()
   {
     Test.startTest();
      setMock(HttpCalloutMock.class,new MockHttpcall()); 
             HttpResponse response = Inventorycallout.inventorycall();
              String contentType = response.getHeader('Content-Type');
              System.assert(contentType == 'application/json');
              String actualValue = response.getBody();
              String expectedValue = '[{"fakeresponse":"test"},{"fakeresponse2":"test2"}]';
              System.assertEquals(actualValue, expectedValue);
              System.assertEquals(200, response.getStatusCode());
              Test.stopTest();          
   }
}

 
I created a VF page to use as a subsection on a page layout. The custom fields that I put on it appear in editing mode instead of the same way that they would appear normally. What I need to add to my code in order to get the "normal" Salesforce field look. I have a feeling that it's something super simple that I don't know about as I'm new to VF. Thank you!

<apex:page standardController="Opportunity" tabStyle="Opportunity">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Before the Call">
<apex:inputField value="{!opportunity.ATS__c}"/>
<apex:inputField value="{!opportunity.Job_Boards_Agregators__c}"/>
<apex:inputField value="{!opportunity.Competitor_Watch__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>

 

Does an apex:pageBlockTable value have to be a data table (ie: data from a table / query)?  What I need to do is display a list of records formed in a LIST. 

 

The RecordList is created in my APEX class and I'm trying to display it in the Visualforce Page.  However, this gives me an Visualforce error Error: Unknown property 'conAttendanceTaking.RecordList'.  I'm assuming its because this is a List and not a data table.  How do I make something like this work?  

 

    public List<Event> RecordList = new List<Event>();

 

 

 

    <apex:pageBlock title="Attendance List">
        <apex:pageBlockTable value="{!RecordList}" var="rl" id="ResultsDataTable" styleClass="tableClass list" rowClasses="odd,even">
            <apex:column value="{!rl.OwnerId}"/>
            <apex:column value="{!rl.DurationInMinutes}"/>
            <apex:column value="{!rl.EndDateTime}"/>
            <apex:column value="{!rl.WhoId}"/>
            <apex:column value="{!rl.WhatId}"/>
            <apex:column value="{!rl.ShowAs}"/>
            <apex:column value="{!rl.StartDateTime}"/>
            <apex:column value="{!rl.Subject}"/>
            <apex:column value="{!rl.Type}"/>
            <apex:column value="{!rl.Attendance_Status__c}"/>
            <apex:column value="{!rl.Class_Role__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>

 

The idea behind my VF Page is to capture data (multiple records) then once all is captured, write the data (RecordList).  Trying to collect all the data without writting it in between each record.