You need to sign in to do that
Don't have an account?
Iqra Tech
need to convert this class into the batch class beacuse of governer limits
public class My_2nd_Api {
Public static void Insert_Records(){
List<Opportunity> oppbatch=[select id,name,stageName, Edition__r.name,
(select id, name from OpportunityLineItems ),
(Select contact.firstname,contact.lastname,contact.Email,contact.Phone,contact.Salutation,contact.title from OpportunityContactRoles)
from Opportunity where Edition__r.name ='FM EXPO 2017' AND HasOpportunityLineItem = true ];
system.debug('oppbatch List query.. '+oppbatch);
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
for(Opportunity opp : oppbatch)
{
system.debug('Chehking'+opp.OpportunityLineItems);
OppWrapper oppwrappervar = new OppWrapper(opp.id,opp.name,opp.StageName,opp.Edition__r.name,
null, null, null, null, null);
for(OpportunityLineItem li : opp.OpportunityLineItems)
{
oppwrappervar.SFDC_Record_Unique_ID=li.id;
oppwrappervar.Product_Name=li.name;
}
for(OpportunityContactRole ocr : opp.OpportunityContactRoles)
{
oppwrappervar.First_Name = ocr.contact.firstname;
oppwrappervar.Last_Name =ocr.contact.lastname ;
oppwrappervar.Email=ocr.contact.Email;
oppwrappervar.Mobile=ocr.contact.Phone;
oppwrappervar.Salutation=ocr.contact.Salutation;
oppwrappervar.Job_Title=ocr.contact.title;
}
oppWrapperVarList.add(oppwrappervar);
}
string jsonbody=Json.serialize(oppWrapperVarList);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
//request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
request.setEndpoint('http://sfdata.iqratechnology.com/api/fs_metadata');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
//request.setHeader('Content-Type','multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
//request.setHeader('Authorization','Bearer '+ AuthorizationToken);
//request.setBody('[{ "RecordId": "456","RecordName": "moosa traders pvt ltd / The Big 5 Construct Egypt 2018 / / 093061123", "EventName": "a2JD0000001ns6uMAA U", "RecordStage": "Test Stage Amjad","BannerName": "Test Banner Amjad","StandNo": "Test Stand Amjad"}]');
request.setBody(jsonbody);
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
Public class OppWrapper
{
public String SFDC_RecordID {get;set;}
public String SFDC_RecordName {get;set;}
public String SFDC_RecordStage {get;set;}
public String SFDC_EventName {get;set;}
public String SFDC_Record_Unique_ID {get;set;}
public String Product_Name {get;set;}
public String First_Name {get;set;}
public String Last_Name {get;set;}
public String Email {get;set;}
public String Mobile {get;set;}
public String Salutation {get;set;}
public String Job_Title {get;set;}
public OppWrapper(String SFDC_RecordID,String SFDC_RecordName,String SFDC_RecordStage,String SFDC_EventName,
String SFDC_Record_Unique_ID,String Product_Name,String First_Name,String Last_Name,String Email,String Mobile,String Salutation,
String Job_Title)
{
this.SFDC_RecordID =SFDC_RecordID;
this.SFDC_RecordName =SFDC_RecordName;
this.SFDC_RecordStage =SFDC_RecordStage;
this.SFDC_EventName=SFDC_EventName;
this.SFDC_Record_Unique_ID=SFDC_Record_Unique_ID;
this.Product_Name=Product_Name;
this.First_Name=First_Name;
this.Last_Name=Last_Name;
this.Email=Email;
this.Mobile=Mobile;
this.Salutation=Salutation;
this.Job_Title=Job_Title;
}
}
}
i have created this class for posting the data in third party API but facing governer limits now i need to convert this class into the batch class can any one please help me to achive this requiremnt need urgent please help...........
Public static void Insert_Records(){
List<Opportunity> oppbatch=[select id,name,stageName, Edition__r.name,
(select id, name from OpportunityLineItems ),
(Select contact.firstname,contact.lastname,contact.Email,contact.Phone,contact.Salutation,contact.title from OpportunityContactRoles)
from Opportunity where Edition__r.name ='FM EXPO 2017' AND HasOpportunityLineItem = true ];
system.debug('oppbatch List query.. '+oppbatch);
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
for(Opportunity opp : oppbatch)
{
system.debug('Chehking'+opp.OpportunityLineItems);
OppWrapper oppwrappervar = new OppWrapper(opp.id,opp.name,opp.StageName,opp.Edition__r.name,
null, null, null, null, null);
for(OpportunityLineItem li : opp.OpportunityLineItems)
{
oppwrappervar.SFDC_Record_Unique_ID=li.id;
oppwrappervar.Product_Name=li.name;
}
for(OpportunityContactRole ocr : opp.OpportunityContactRoles)
{
oppwrappervar.First_Name = ocr.contact.firstname;
oppwrappervar.Last_Name =ocr.contact.lastname ;
oppwrappervar.Email=ocr.contact.Email;
oppwrappervar.Mobile=ocr.contact.Phone;
oppwrappervar.Salutation=ocr.contact.Salutation;
oppwrappervar.Job_Title=ocr.contact.title;
}
oppWrapperVarList.add(oppwrappervar);
}
string jsonbody=Json.serialize(oppWrapperVarList);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
//request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
request.setEndpoint('http://sfdata.iqratechnology.com/api/fs_metadata');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
//request.setHeader('Content-Type','multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
//request.setHeader('Authorization','Bearer '+ AuthorizationToken);
//request.setBody('[{ "RecordId": "456","RecordName": "moosa traders pvt ltd / The Big 5 Construct Egypt 2018 / / 093061123", "EventName": "a2JD0000001ns6uMAA U", "RecordStage": "Test Stage Amjad","BannerName": "Test Banner Amjad","StandNo": "Test Stand Amjad"}]');
request.setBody(jsonbody);
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
Public class OppWrapper
{
public String SFDC_RecordID {get;set;}
public String SFDC_RecordName {get;set;}
public String SFDC_RecordStage {get;set;}
public String SFDC_EventName {get;set;}
public String SFDC_Record_Unique_ID {get;set;}
public String Product_Name {get;set;}
public String First_Name {get;set;}
public String Last_Name {get;set;}
public String Email {get;set;}
public String Mobile {get;set;}
public String Salutation {get;set;}
public String Job_Title {get;set;}
public OppWrapper(String SFDC_RecordID,String SFDC_RecordName,String SFDC_RecordStage,String SFDC_EventName,
String SFDC_Record_Unique_ID,String Product_Name,String First_Name,String Last_Name,String Email,String Mobile,String Salutation,
String Job_Title)
{
this.SFDC_RecordID =SFDC_RecordID;
this.SFDC_RecordName =SFDC_RecordName;
this.SFDC_RecordStage =SFDC_RecordStage;
this.SFDC_EventName=SFDC_EventName;
this.SFDC_Record_Unique_ID=SFDC_Record_Unique_ID;
this.Product_Name=Product_Name;
this.First_Name=First_Name;
this.Last_Name=Last_Name;
this.Email=Email;
this.Mobile=Mobile;
this.Salutation=Salutation;
this.Job_Title=Job_Title;
}
}
}
i have created this class for posting the data in third party API but facing governer limits now i need to convert this class into the batch class can any one please help me to achive this requiremnt need urgent please help...........