function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kishore B T 21Kishore B T 21 

How do i send a XML to Tally Server?

Hello Guys,

I have a XML request i need to HIT tally Server, How do I achieve this?
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Export Data</TALLYREQUEST>
</HEADER>
<BODY>
<EXPORTDATA>
<REQUESTDESC>
<REPORTNAME>List of Accounts</REPORTNAME>
<STATICVARIABLES>
<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
<ACCOUNTTYPE>All Inventory Masters</ACCOUNTTYPE>
</STATICVARIABLES>
</REQUESTDESC>
</EXPORTDATA>
</BODY>
</ENVELOPE>


The Request is also I get in XML? 
Please guide me on how to achieve this functionality.
Thanks in Advance.

Andy BoettcherAndy Boettcher
You can use an Apex trigger and class to make a "callout" (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts.htm) from Salesforce to your external server.  You will need to assemble that XML object and send it in the body of the callout.

The inbound request would be an Apex SOAP class (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_web_services.htm) that your external server would consume.
Jayant JadhavJayant Jadhav
Hi Kishore,

You can achive this by using the HTTP requests from SFDC. The response also get on XML from tally system.
Refere below example to get this done.

 
public class ExternalCall
{
    //Static global attribute from external system callouts
    @TestVisible private static final String username;
    @TestVisible private static final String password;
    @TestVisible private static final String endpoint;
    // Initialize all attributes using custom settings.
    // Static is to initialize at the time of class load.
    static
    {
        username=Credentials__c.getInstance('username').Value__c;
        password=Credentials__c.getInstance('password').Value__c;
        endpoint=Credentials__c.getInstance('endpoint').Value__c;
    }
        
   
    @future(callout=true)
    public static void updateStatus()
    {
        Http http = new Http();
        // soapbody string creation to make https callout using SOAP xml.
        String soapBody;
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        try
        {
            req=getRequest();
            soapBody=getHeader();
            soapBody+='<soapenv:Body>';
            soapBody+='<ns7:Update xmlns:ns7="urn:messages.ws.rightnow.com/v1_2">';
            soapBody+='<ns7:RNObjects  xsi:type="ns2:GenericObject" xmlns:ns2="urn:generic.ws.rightnow.com/v1_2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
            soapBody+='<ID id="" xmlns="urn:base.ws.rightnow.com/v1_2"/>';
            soapBody+='<ns2:ObjectType>';
            soapBody+='<ns2:Namespace xsi:nil="1"/>';
            soapBody+='<ns2:TypeName>Incident</ns2:TypeName>';
            soapBody+='</ns2:ObjectType>';
            soapBody+='<ns2:GenericFields dataType="OBJECT" name="StatusWithType">';
            soapBody+='<ns2:DataValue>';
            soapBody+='<ns2:ObjectValue xsi:type="ns2:GenericObject">';
            soapBody+='<ns2:ObjectType>';
            soapBody+='<ns2:TypeName>StatusWithType</ns2:TypeName>';
            soapBody+='</ns2:ObjectType>';
            soapBody+='<ns2:GenericFields dataType="NAMED_ID" name="Status">';
            soapBody+='<ns2:DataValue>';
            soapBody+='<ns2:NamedIDValue>';
            soapBody+='<Name xmlns="urn:base.ws.rightnow.com/v1_2">Complete</Name>';
            soapBody+='</ns2:NamedIDValue>';
            soapBody+='</ns2:DataValue>';
            soapBody+='</ns2:GenericFields>';
            soapBody+='</ns2:ObjectValue>';
            soapBody+='</ns2:DataValue>';            
            soapBody+='</ns2:GenericFields>';         
            soapBody+='</ns7:RNObjects>';
            soapBody+='<ns7:ProcessingOptions>';
            soapBody+='<ns7:SuppressExternalEvents>false</ns7:SuppressExternalEvents>';
            soapBody+='<ns7:SuppressRules>false</ns7:SuppressRules>';
            soapBody+='</ns7:ProcessingOptions>';
            soapBody+='</ns7:Update>';
            soapBody+='</soapenv:Body>';
            soapBody+='</soapenv:Envelope>'; 
            req.setHeader('Content-Length',String.valueOf(soapBody.length()));
            system.debug('Message'+soapBody);
            req.setTimeout(120000);
            req.setBody(soapBody);
            res=http.send(req); 
            system.debug(res);
            // If response is 200 then it success
        }
        catch(Exception e)
        {
             system.debug(e);           
        }
         
    }   
     @TestVisible
    private static HttpRequest getRequest()
    {       
            HttpRequest req = new HttpRequest();
            req.setMethod('POST');
            req.setHeader('Content-Type','text/xml');
            req.setHeader('SOAPAction', endpoint);
            req.setHeader('Authorization', 'Basic Og==');        
            req.setEndpoint(endpoint);  
            return req;
    }
 }
Replace all soap body contant with your tally server content. 
Jayant JadhavJayant Jadhav
Hi Kishor,

Please mark this question is solved if this help you.