• farukh shaikh
  • NEWBIE
  • 17 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Can someone please help me out here , I want the get the verification_status from the below response.I am not able to understand the approach.

[ { "address1":"Rua Padre Antônio D'ângelo 121", "address2":"Casa Verde", "address3":"02516-040 São Paulo SP", "components":{ "administrative_area":"SP", "dependent_locality":"Casa Verde", "country_iso_3":"BRA", "locality":"São Paulo", "postal_code":"02516-040", "postal_code_short":"02516-040", "premise":"121", "premise_number":"121", "thoroughfare":"Rua Padre Antônio D'ângelo", "thoroughfare_name":"Padre Antonio D'angelo", "thoroughfare_type":"Rua" }, "metadata":{ "latitude":-23.50948, "longitude":-46.66073, "geocode_precision":"Premise" }, "analysis":{ "verification_status":"Verified", "address_precision":"Premise" } } ]
I am trying to cover this generic method in Apex class,
public class apexClassGeneric{
 public static HttpResponse methodName(HttpRequest request) {
 HttpResponse response = h.send(request);
return response;

}
}

This is my test class.

public static testmethod void testAccountCallout() {
        SingleRequestMock fakeResponse = new SingleRequestMock(200,
                                                 'Complete',
                                                 '[{"Name": "sForceTest1"}]',
                                                 null);
        Test.setMock(HttpCalloutMock.class, fakeResponse);
        
        string endPoint='https://ap5.salesforce.com/services/apexrest/getAccountOnExternalIdtofetchsinglerecord/';
        HttpRequest req1=new HttpRequest();
        
        req1.setMethod('GET');
        req1.setEndpoint(endPoint);
        HttpResponse resp=apexClassGeneric.methodName(req1);
       
    }


I am not able to cover this I am getting error.

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

Note: If it would have been a method without HttpRequest request i would have cover it easily using,

HttpResponse resp=apexClassGeneric.methodName();
Basically i need to create a record in custom object everytime when Salesforce system is calling external system along with a record for response which I am receiving. Also I need to store information of logs regarding external system when they hit Salesforce system.

Details such as Enpoint, Status ,Response body etc need to be stored.
Please let me know how can i proceeds
I have a requirement to check if Lead is more than 18 years of age before inserting lead. I need to achieve this using validation rule. Can some  help me out here.

The validation needs to be done on Date of birth field
My Colleague and me are getting different view for account though we belongs to Same admin profile in Salesforce lightning. Can someone please help me here.
Can someone please help me out here , I want the get the verification_status from the below response.I am not able to understand the approach.

[ { "address1":"Rua Padre Antônio D'ângelo 121", "address2":"Casa Verde", "address3":"02516-040 São Paulo SP", "components":{ "administrative_area":"SP", "dependent_locality":"Casa Verde", "country_iso_3":"BRA", "locality":"São Paulo", "postal_code":"02516-040", "postal_code_short":"02516-040", "premise":"121", "premise_number":"121", "thoroughfare":"Rua Padre Antônio D'ângelo", "thoroughfare_name":"Padre Antonio D'angelo", "thoroughfare_type":"Rua" }, "metadata":{ "latitude":-23.50948, "longitude":-46.66073, "geocode_precision":"Premise" }, "analysis":{ "verification_status":"Verified", "address_precision":"Premise" } } ]
I am trying to cover this generic method in Apex class,
public class apexClassGeneric{
 public static HttpResponse methodName(HttpRequest request) {
 HttpResponse response = h.send(request);
return response;

}
}

This is my test class.

public static testmethod void testAccountCallout() {
        SingleRequestMock fakeResponse = new SingleRequestMock(200,
                                                 'Complete',
                                                 '[{"Name": "sForceTest1"}]',
                                                 null);
        Test.setMock(HttpCalloutMock.class, fakeResponse);
        
        string endPoint='https://ap5.salesforce.com/services/apexrest/getAccountOnExternalIdtofetchsinglerecord/';
        HttpRequest req1=new HttpRequest();
        
        req1.setMethod('GET');
        req1.setEndpoint(endPoint);
        HttpResponse resp=apexClassGeneric.methodName(req1);
       
    }


I am not able to cover this I am getting error.

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

Note: If it would have been a method without HttpRequest request i would have cover it easily using,

HttpResponse resp=apexClassGeneric.methodName();
My Colleague and me are getting different view for account though we belongs to Same admin profile in Salesforce lightning. Can someone please help me here.