• Aditya Singh 37
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hi, 
 I Created a class for Future callout and trying to create a Test Class for the same. I am invoking this class through an invokeable Apex class which gets called via a process builder. I tested this in Sandbox and it works pefect but i am not sure how to write the test class and migrate it. Below is the entire code, i am not sure , i am wrighting the right code ?

=====================================================================================
public class ApexCallout { // Called Through ProcessBuilder
@InvocableMethod
public static void invokecallout(list<Lead> Leads) {
WS_Webservice.Notification(Leads[0].id, Leads[0].name)
   }
}
------------------------------------------------------------------
@isTest
private class ApexCalloutTest{
    private static testMethod void doTest() {

        Test.startTest();
        Lead l = new Lead(id = '00XXXXXXXXXXXXXX',
                          name = 'User123');
        Test.stopTest();

    }
}


======================================================================================
Global class WS_Webservice {
  @future (callout=true)
   // Receiving the Lead details from Invokable class ApexCallout.
  WebService static void Notification(id lid, String name)
        { 
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('https://google.com');
        
        //Setting Method Content and Body
        req.setMethod('POST');
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        req.setBody(
        'name='+EncodingUtil.urlEncode(name, 'UTF-8')
        
      );
        req.setTimeout(120000);
        try {
         res = http.send(req);
         System.debug(res.getbody());
        
         Dom.Document docx = new Dom.Document();
         docx.load(res.getbody());
         dom.XmlNode xroot = docx.getrootelement();
         String U_Id = xroot.getAttributeValue('U_Id', null);
         system.debug(U_Id );
         Lead le = new Lead(id=lid);
         le.ID__c = U_Id;
         update le;
        } 
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
            res.getbody();
               }
            }
       }

 
I created a custom Java Script button on Lead Object. Should I call a @InvocableMethod Apex class or a futurecallout apex class and pass the Lead ID to the class to further process ?
i am calling futurecall out class with invokeable method using that in a Flow and its working perfectly. Just want to use a custom button too.
This is the code:
{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/35.0/apex.js")} var result = sforce.apex.execute("Futurecallout","ApexWSclass", {Id:'{!Lead.Id}'}, {Email:'{!Lead.Email}'}, {Firstname:'{!Lead.FirstName}'}, ); alert(result); window.location.reload();
Hi Guys, 

I am pretty new to Salesforce Apex development and recently I have created a @futurecallout class in Apex which gets invoked by a Lead Trigger (after Insert). In the class i am doing a POST Call (sending Lead Info) and the external system is returning an XML with a message( I am able to see that in debug log). Now I need to parse the same XML data extract a value (UID) and Update the Lead record i am sending to get updated with the value UID as received in XML. 

Please Help

public class WS FromLead {
   
   @future (callout=true)
    public static void sendNotification(id lid, String username) {
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        req.setEndpoint("Endpoint URL");
        req.setMethod('POST');
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
       req.setBody(
        'username='+EncodingUtil.urlEncode(username, 'UTF-8' );  
        req.setTimeout(120000);
        try {
         res = http.send(req);
         System.debug(res.getbody());
         // Generate the HTTP response as an XML stream
         XmlStreamReader reader = res.getXmlStreamReader();
         // Read through the XML
        System.debug('Event Type:' + reader.getEventType());
        if (reader.getEventType() == XmlTag.START_ELEMENT)
           {
            System.debug(reader.getLocalName());
           }
        } 
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
            res.getbody();
        }
        }
        }
Hi, 
 I Created a class for Future callout and trying to create a Test Class for the same. I am invoking this class through an invokeable Apex class which gets called via a process builder. I tested this in Sandbox and it works pefect but i am not sure how to write the test class and migrate it. Below is the entire code, i am not sure , i am wrighting the right code ?

=====================================================================================
public class ApexCallout { // Called Through ProcessBuilder
@InvocableMethod
public static void invokecallout(list<Lead> Leads) {
WS_Webservice.Notification(Leads[0].id, Leads[0].name)
   }
}
------------------------------------------------------------------
@isTest
private class ApexCalloutTest{
    private static testMethod void doTest() {

        Test.startTest();
        Lead l = new Lead(id = '00XXXXXXXXXXXXXX',
                          name = 'User123');
        Test.stopTest();

    }
}


======================================================================================
Global class WS_Webservice {
  @future (callout=true)
   // Receiving the Lead details from Invokable class ApexCallout.
  WebService static void Notification(id lid, String name)
        { 
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('https://google.com');
        
        //Setting Method Content and Body
        req.setMethod('POST');
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        req.setBody(
        'name='+EncodingUtil.urlEncode(name, 'UTF-8')
        
      );
        req.setTimeout(120000);
        try {
         res = http.send(req);
         System.debug(res.getbody());
        
         Dom.Document docx = new Dom.Document();
         docx.load(res.getbody());
         dom.XmlNode xroot = docx.getrootelement();
         String U_Id = xroot.getAttributeValue('U_Id', null);
         system.debug(U_Id );
         Lead le = new Lead(id=lid);
         le.ID__c = U_Id;
         update le;
        } 
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
            res.getbody();
               }
            }
       }

 
Hi Guys, 

I am pretty new to Salesforce Apex development and recently I have created a @futurecallout class in Apex which gets invoked by a Lead Trigger (after Insert). In the class i am doing a POST Call (sending Lead Info) and the external system is returning an XML with a message( I am able to see that in debug log). Now I need to parse the same XML data extract a value (UID) and Update the Lead record i am sending to get updated with the value UID as received in XML. 

Please Help

public class WS FromLead {
   
   @future (callout=true)
    public static void sendNotification(id lid, String username) {
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        req.setEndpoint("Endpoint URL");
        req.setMethod('POST');
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
       req.setBody(
        'username='+EncodingUtil.urlEncode(username, 'UTF-8' );  
        req.setTimeout(120000);
        try {
         res = http.send(req);
         System.debug(res.getbody());
         // Generate the HTTP response as an XML stream
         XmlStreamReader reader = res.getXmlStreamReader();
         // Read through the XML
        System.debug('Event Type:' + reader.getEventType());
        if (reader.getEventType() == XmlTag.START_ELEMENT)
           {
            System.debug(reader.getLocalName());
           }
        } 
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
            res.getbody();
        }
        }
        }
Hi,
I Installed "LoginFlows" Unmanaged Package in my (Salesforce OEM Edition/License) Sandbox instance.
After Security code verification when it redirects to Home Page an error page is showing "Invalid Page Redirection" with below Message:

"The page you attempted to access has been blocked due to a redirection to an outside website or an improperly coded link or button. Please contact your salesforce.com Administrator for assistance. For more information, see Insufficient Privileges Errors.
Click here to return to the previous page. "

When i Click the "Click here" link it goes to the Home Page.

But when i installed "Login Flow" Package in any development org it is working fine.

Can anyone help me out with this?

Thanks