• Jamal Rida
  • NEWBIE
  • 5 Points
  • Member since 2016


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 10
    Replies
Hi All,

I'm trying  to complete a challenge related to Apex Rest, but i'm facing a problem when validating it, it's kind of facing an error in the method definition even if i've checked it, below is a snippet of the code and the error message i get from the trailhead : 
 
public class AnimalLocator {
    public static JSON2Apex animalWrapper;
    
    public static String getAnimalNameById(Integer animalId){
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+animalId+':Id');
        request.setMethod('GET');
        System.debug('###request : '+request);
        HttpResponse response = http.send(request);
         System.debug('###response : '+response.getBody() );
        // If the request is successful, parse the JSON response.
        if (response.getStatusCode() == 200) {
            // Deserializes the JSON string into collections of primitive data types.
            animalWrapper  = new JSON2Apex();
            System.debug('Received 1:'+(JSON2Apex)System.JSON.deserializeStrict(response.getBody(), JSON2Apex.Class));
            animalWrapper = (JSON2Apex)System.JSON.deserializeStrict(response.getBody(), JSON2Apex.class);
            
            System.debug('Received the following animals:'+animalWrapper);
            System.debug('###myAnimal : '+animalWrapper.animal.name);
           // return animalWrapper.animal.name;
           
        }
        return animalWrapper.animal.name;
    }  
}
Challenge Not yet complete... here's what's wrong: 
Executing the 'getAnimalNameById' method on 'AnimalLocator' failed. Make sure the method exists with the name 'getAnimalNameById', is public and static, accepts an Integer and returns a String.



 
Basically i want determine whether some values has been chnaged on my VF page so that i can throw a save prompt message whenever user tries to close the page .
Hi All,
I have written batch apex to insert data in Task from two objects.
I am able to get data from Obj1__c. I am not able to get from Obj2__c
Here is my code.
 
global class batchTwo Implements Schedulable, Database.Batchable<sObject>{
global void execute(SchedulableContext sc) {
    Database.executeBatch(this);
}

global database.queryLocator start(Database.BatchableContext BC) {
    
    
        return database.getQueryLocator([SELECT Id,AccountId__c,F1__c,F2__c FROM Obj1__c]);
    
} 

global void execute(Database.BatchableContext BC, list <obj1__c> scope) {

    List <Task> taskList = new List<Task>();

   Map<Id, Obj2__c> mapObj2=new Map<Id, Obj2__c>([SELECT Account_Name__r.Id,Obj2_F2__c FROM Obj2__c]);
    
    for(Obj1__c c : scope) {
            Task tsk             = new Task();
            if(mapObj2.containsKey(c.AccountId__c)) {
             Obj2__c tmpSales = mapObj2.get(c.AccountId__c);
            
             tsk.F1__c=tmpSales.Obj2_F2__c;
             
            }
            
            tsk.WhatId           = c.AccountId__c;
            tsk.ActivityDate     = System.today();
            tsk.Status           = 'Open';
            tsk.Priority         = 'Normal';
            tsk.Subject          = 'call';
            tsk.P1__c=c.F1__c;
            tsk.P2__c=c.F2__c;
            
           taskList.add(tsk);
    } //close for-loop

   
        insert taskList;
    
       
    
} 

global void finish(Database.BatchableContext BC) {


} 
}

I am getting problem in Line no. 21 to 24.
Please suggest me what changes need to be done.
Please help me.
Thanks in Advance
What would happen if I perform a DML update operation on the before update trigger of the same sObject record ?
A long working Test Class of mine is now failing in production due to too many SOQL calls on the second to last call. I tried adding in test.start() and test.stop() functions, which should have reduced the number of calls by 22, but it still fails at what appears to be the exact same place when I try and push the test class. I can't even work on anything else until this resolves, as it causes everything I try to push to fail. Does anyone have any clue what might be happening?
Hi, 

 In below method when i call from visualforce page i am getting Number of SOQL queries: 100 out of 100

 Please suggest me how to modify the code i think query inside the code is the issue please suggest me how to modifiy 
/* calculate disti discount */  
  public static Decimal reCalRslrDisc(Decimal listprice,String productcat, Decimal reslrdistdiscount){
        Boolean isService = false;
        Decimal s;
        
        system.debug('listprice = ' + listprice);
        system.debug('productcat = ' + productcat);
        system.debug('reslrdistdiscount = ' + reslrdistdiscount);
        
        if ( reslrdistdiscount == null || reslrdistdiscount < 1 ){
            reslrdistdiscount = 0;
         } 
        
        if ( productcat=='C' || productcat=='E'|| productcat=='D'|| productcat=='H'|| productcat=='I'|| productcat=='J' ){
            isService = true;
          }
        
        if ( isService == true && Limits.getQueries() <   Limits.getLimitQueries()) { 
            try
            {
            NSP_Margin_Schedule__c NMS =  [ Select Distributor_Discount__c From NSP_Margin_Schedule__c 
                                           where  Reseller_Discount__c = :reslrdistdiscount and 
                                           Service__c = :isService 
                                           and createddate < 2015-01-17T00:00:00-08:00 ];
                                           
            System.debug('Total Number of SOQL Queries allowed in this Apex code context: ' +  Limits.getLimitQueries());                               
            System.debug('1. Number of Queries used in this Apex code so far: ' + Limits.getQueries());
                    
                                        
                s = NMS.Distributor_Discount__c;
                 
             }
            
            catch (System.NullPointerException e) {
             system.debug('Null Exception');
             }
                return s;
         
                                       
        }
        else {
            return 0;
        }      
        
  }

Thanks
Sudhir