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
bharathsdsd kumarbharathsdsd kumar 

Batchlass help needed

Hi ,

I am trying to write a batch class for the following the below condition

Please create a new batch class for M2M_Activation_Status__c object. Below is the logic that is needed.
- Query records where Order Number(Order_Number__c) is not blank and Activation complete(Activation_Complete__c) is false


Kindly help me with the code pls

Thanks in Advance
AshlekhAshlekh
Hi
 
global class YOUR_BATCHCLASSNAME implements Database.Batchable<sObject>{

   global Database.QueryLocator start(Database.BatchableContext BC){
      String quer= 'select id from M2M_Activation_Status__c  where Order_Number__c != null and  
       Activation_Complete__c = true ';
       return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
    //Put your logic here.
   }

   global void finish(Database.BatchableContext BC){
   }
}
-Thanks
For more information - 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
http://blog.shivanathd.com/2013/01/how-to-write-batch-class-in.html


-Thanks
Ashlekh Gera
 
bharathsdsd kumarbharathsdsd kumar
Hi ashlekh,

I have done the code

 
MY CODE :
global class BatchM2MActivationstatusUpdate implements Database.Batchable<sObject> {
    global String [] email = new String[] {'test@test.com'};//Add here your email address here
        
        global Database.QueryLocator start(Database.BatchableContext BC) {
            String query = 'SELECT Id,Activation_Complete__c,Order_Number__c FROM M2M_Activation_Status__c where Order_Number__c!=null and Activation_Complete__c=false';
            return Database.getQueryLocator(query);
        }
    
    global void execute(Database.BatchableContext BC, List<M2M_Activation_Status__c> scope) {
        for(M2M_Activation_Status__c ms : scope)
        {
            M2M_Activation_Status__c mas = (M2M_Activation_Status__c)ms;
        }
        if (scope != null && scope.size()>0) {//Check if List is empty or not
            insert  scope;
            
        }
    }
    
    global void finish(Database.BatchableContext BC) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        //Below code will fetch the job Id
        AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors, a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById, a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];//get the job Id
        System.debug('$$$ Jobid is'+BC.getJobId());
        //below code will send an email to User about the status
        mail.setToAddresses(email);
        mail.setReplyTo('test@test.com');//Add here your email address
        mail.setSenderDisplayName('Apex Batch Processing Module');
        mail.setSubject('Batch Processing '+a.Status);
        mail.setPlainTextBody('The Batch Apex job processed  '+a.TotalJobItems+'batches with  '+a.NumberOfErrors+'failures'+'Job Item processed are'+a.JobItemsProcessed);
        Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
    }
}

Actually my need is

For the retrieved records we need to create a XML request in below format to send to BizTalk.


Request Format:
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" Id="Body">
<sfd:SFDCCheckStausReqResp xmlns:sfd="http://SFDCtoVIPM2MActivation" xmlns:sfd1="http://SFDCtoVIPBizServices.SFDCBizServicesSchema">
<sfd1:POSBizServices>
<POSBizServiceHeader>
<userId>WUSER</userId>
<password>2013Testing</password>
<clientId>31</clientId>
<action>CHECKSTATUS</action>
<responseFormat>XML</responseFormat>
</POSBizServiceHeader>
<request>
<checkStatus></checkStatus>
<refNum>1234455</refNum> This is order number that should be passed
</request>
</sfd1:POSBizServices>
</sfd:SFDCCheckStausReqResp>
</soapenv:Body>


Kindly help me how to pare the xml request in the format above

Thanks in advance
Lokeswara ReddyLokeswara Reddy
Hi,
BizTalk should have provided you an WSDL to invoke their service, you have to generate stubbs using this wsdl and invoke their service.
It is not required to manually generate the xml, the request object in the wsdl will do it for you.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex.htm