• Divyesh Dudhat
  • NEWBIE
  • 5 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
For simplicity, one method in my class looks a little like this and it works in manual testing: 
@AuraEnabled
    public static String getCitySuggestions(String input) {
        String response;
        String url = GOOGLE_PLACE_AUTOCOMPLETE_ENDPOINT + 'input=' + EncodingUtil.urlEncode(input, 'UTF-8') + '&types=(cities)' + getKey();
        String key = input.replaceAll('[^a-zA-Z0-9]', '');
        //Input will sometimes include a '.' or space, cannot cache
        if ((key == input) && (key.length() <= 50)) {
            if (!Cache.Org.contains(key)) {
                response = getResponse(url);
                Cache.Org.put(key, response);
            } else {
                response = (String) Cache.Org.get(key);
            }
            if (!response.contains('"status" : "OK"')) {
                Cache.Org.remove(key);
            }
        } else {
            response = getResponse(url);
        }
        return response;
    }
In my test class, I run the same method twice so that I should hit the lines that populate the cache the first time then the lines that access the cache in the second. Only the lines that populate the cache run and if I have an assert to make sure the cache has the value, it fails. 

How do I test Platform Cache in a test class? 
 
Hi Experts,

I need some assitance with a date formula. I trying to calculate the number of months left between two dates, start and end date. I currently have the folloiwng formula:

(Custom_End_Date__c - today ())/30

Which will give me the number of days left and if I divide the number by 30 and I should get the numbner of months. Unfortunately I am short by one month. For example if I have a end date of 12/01/2015 minus today, 30 July, would give me 124 days. If I divide that by 30 I get 4 months, or more exactly 4.13 months. But from July to Dec is 5 months.

Any assistance would be greatly appreciated.

Thank-you

Hi,

 

I am trying to call infoconnect API through apex class and page. But its giving me error "Unsupported media type".

 

Following is my code :

 

Apex class code:

 

public class CalloutSample {   

   public String getData()  {

              Http http = new Http();      

              HttpRequest req = new HttpRequest();      

              req.setEndpoint('https://api.infoconnect.com/v1/companies/615869369?resourcetype=basic&apikey=f4702d2cfc7efcbda07160f3e89b4ea1');      

              req.setMethod('GET');         

              req.setTimeout(30000);             

              req.setHeader('Content-Type', 'application/json');                    

              HttpResponse res = http.send(req);                 

              return res.getStatus();                 

     }

}

 

Apex page code :

 

<apex:page controller="CalloutSample">
     <apex:form >
         <apex:outputLabel value="{!Data}" />:
     </apex:form>
  </apex:page>

The api url works fine when calling directly from browser.

 

Please help me out...

 

Thanks             

  • November 08, 2012
  • Like
  • 0