• Karna Shiva
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Developer
  • Hexaware Technologies

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
My client have requirment  to insert data from informatica into SFDC object, how this is possible?


Please see the below code:

Rebate_Amount__c object having - 92255 rows and suppose to insert 92255 rows on gross profit, but it is inserting more than 1 laks rows

global class RebateGPBatch implements Database.Batchable<SObject>
{

    global Database.QueryLocator start(Database.BatchableContext bc)

  {
       string query = '';
       query += ' select Opportunity_Name__r.id  from Rebate_Amount__c ';
    
       if(Test.isRunningTest())
       {
          query  = ' select id from Rebate_Amount__c  ';
          query += ' where company__c = \'SDS\' ';
          query += ' limit 20';
       }

       return Database.getQueryLocator(query);
  }

  global void execute(Database.BatchableContext bc, List<SObject> scope)
  {

     List<Id> optyWithQuoteSet = new List<Id>();
    
  
      for (sObject obj :scope)
      {
         Rebate_Amount__c   op = (Rebate_Amount__c)obj;
          
         optyWithQuoteSet.add(op.Opportunity_Name__r.id);
      }


    
list<Shipped__c>  listSch =[select cost__c,Material__c  ,Opportunity2__c
                                                  from Shipped__c
                                                     where Quote__c!=null and Opportunity2__r.StageName='S' and Opportunity2__c = :optyWithQuoteSet];

map<string,Shipped__c> mapShipped= new map<string,Shipped__c>();

for(Shipped__c sch : listSch)
{
mapShipped.put(sch.Material__c + sch.Opportunity2__c,sch);
}

  //GP insert - start
   List<Gross_Profit__c> GPList = new List<Gross_Profit__c>();

Rebate_Amount__c object having - 92255 rows and suppose to insert 92255 rows on gross profit, but it is inserting more than 1 laks rows

List<Rebate_Amount__c> Gp_data = [Select Material__c,Quote_Number__c,Company_Code__c,Rebate_by_Amount__c,Item_Number__c,Active_Flag__c,Net_Sales_Amount__c from Rebate_Amount__c where Opportunity_Name__r.id=:optyWithQuoteSet];


for(Rebate_Amount__c oli : Gp_data)
{

   Gross_Profit__c  gp= new Gross_Profit__c();
   gp.Quote_No__c= oli.Quote_Number__c;
   gp.Company__c=oli.Company_Code__c;
   gp.Item_Number__c = oli.Item_Number__c;
   gp.Rebate__c = oli.Rebate_by_Amount__c;
   gp.Active_Flag__c = oli.Active_Flag__c;
   gp.Net_Sales__c = oli.Net_Sales_Amount__c;
   string keyMap_Cost=oli.Material__c + oli.Quote_Number__c;

   if (mapShipped.containskey(keyMap_Cost))
    {
    gp.Cost__c = mapShipped.get(keyMap_Cost).cost__c;
    }
    GPList.add(gp);
     }
   if(GPList.size()>0)
   {
      system.debug('GP Insert section ');
   insert GPList;
   }


   // GP insert - end

}

   global void finish(Database.BatchableContext bc)
  {

    }



}
query += ' select id from opportunity ';
query += ' where company__c = \'' + company + '\' ';
query += ' and stagename in (\'E1\',\'E2\',\'E3\',\'D1\',\'D2\',\'D3\',\'C\',\'B\',\'S\')';


Execute Method :

   set<Id> optyWithQuoteSet = new set<Id>();
    
      List<Rebate_Amount__c> RBTableList = new List<Rebate_Amount__c>();
  
      for (sObject obj :scope)
      {
         Opportunity op = (Opportunity)obj;
          
         optyWithQuoteSet.add(op.id);
      }

List<Quote_Line_Item__c> Shiped_data = [select  Product__r.name,Net_Amount_5__c,Quote__r.Opportunity.Distribution_Channel__c
,Quote__r.Net_Amount__c,Product__r.Product_Group_Report__c,Line_Item_Number__c  from Quote_Line_Item__c where Quote__r.QuoteNumber<> null and
Quote__r.Opportunity.StageName='S' and Quote__r.Opportunity.id=:optyWithQuoteSet ];


for(Quote_Line_Item__c oli : Shiped_data)
{

Rebate_Amount__c rv= new Rebate_Amount__c();
   rv.Sale_Group__c= oli.Quote__r.Opportunity.Sale_Group__c;
   rv.Sale_Office__c = oli.Quote__r.Opportunity.Sale_Office__c;
   rv.Enquiry_No__c = oli.Quote__r.Opportunity.Auto_Number__c;
   rv.Rebate_by_Qountity__c=0;
   rv.Customer_Id__c = oli.Quote__r.Opportunity.Account.Account_Number__c;
   rv.Item_Number__c = oli.Line_Item_Number__c;
        system.debug(' out side shipped for loop ');
   for (Shipped__c sch :[select cost__c,Material__c  ,Opportunity2__r.id from Shipped__c where Quote__c!=null and Material__c=:oli.Product__r.name and Opportunity2__r.id=:oli.Quote__r.Opportunity.id])
   {
      system.debug(' Shipped for loop ');
    
   if (sch.Opportunity2__r.id == oli.Quote__r.Opportunity.id && oli.Product__r.name ==sch.Material__c)
   {
   rv.Cost__c = sch.cost__c;
   }
   RBTableList.add(rv);
   }
   }  
 
   if(RBTableList.size()>0)
   {
   insert RBTableList;
   }
My client have requirement, when he click Error Message it should be re-direct to Opportunity detail page, is this possible through Validation rules or Apex class?
Please see the below code:

Rebate_Amount__c object having - 92255 rows and suppose to insert 92255 rows on gross profit, but it is inserting more than 1 laks rows

global class RebateGPBatch implements Database.Batchable<SObject>
{

    global Database.QueryLocator start(Database.BatchableContext bc)

  {
       string query = '';
       query += ' select Opportunity_Name__r.id  from Rebate_Amount__c ';
    
       if(Test.isRunningTest())
       {
          query  = ' select id from Rebate_Amount__c  ';
          query += ' where company__c = \'SDS\' ';
          query += ' limit 20';
       }

       return Database.getQueryLocator(query);
  }

  global void execute(Database.BatchableContext bc, List<SObject> scope)
  {

     List<Id> optyWithQuoteSet = new List<Id>();
    
  
      for (sObject obj :scope)
      {
         Rebate_Amount__c   op = (Rebate_Amount__c)obj;
          
         optyWithQuoteSet.add(op.Opportunity_Name__r.id);
      }


    
list<Shipped__c>  listSch =[select cost__c,Material__c  ,Opportunity2__c
                                                  from Shipped__c
                                                     where Quote__c!=null and Opportunity2__r.StageName='S' and Opportunity2__c = :optyWithQuoteSet];

map<string,Shipped__c> mapShipped= new map<string,Shipped__c>();

for(Shipped__c sch : listSch)
{
mapShipped.put(sch.Material__c + sch.Opportunity2__c,sch);
}

  //GP insert - start
   List<Gross_Profit__c> GPList = new List<Gross_Profit__c>();

Rebate_Amount__c object having - 92255 rows and suppose to insert 92255 rows on gross profit, but it is inserting more than 1 laks rows

List<Rebate_Amount__c> Gp_data = [Select Material__c,Quote_Number__c,Company_Code__c,Rebate_by_Amount__c,Item_Number__c,Active_Flag__c,Net_Sales_Amount__c from Rebate_Amount__c where Opportunity_Name__r.id=:optyWithQuoteSet];


for(Rebate_Amount__c oli : Gp_data)
{

   Gross_Profit__c  gp= new Gross_Profit__c();
   gp.Quote_No__c= oli.Quote_Number__c;
   gp.Company__c=oli.Company_Code__c;
   gp.Item_Number__c = oli.Item_Number__c;
   gp.Rebate__c = oli.Rebate_by_Amount__c;
   gp.Active_Flag__c = oli.Active_Flag__c;
   gp.Net_Sales__c = oli.Net_Sales_Amount__c;
   string keyMap_Cost=oli.Material__c + oli.Quote_Number__c;

   if (mapShipped.containskey(keyMap_Cost))
    {
    gp.Cost__c = mapShipped.get(keyMap_Cost).cost__c;
    }
    GPList.add(gp);
     }
   if(GPList.size()>0)
   {
      system.debug('GP Insert section ');
   insert GPList;
   }


   // GP insert - end

}

   global void finish(Database.BatchableContext bc)
  {

    }



}
query += ' select id from opportunity ';
query += ' where company__c = \'' + company + '\' ';
query += ' and stagename in (\'E1\',\'E2\',\'E3\',\'D1\',\'D2\',\'D3\',\'C\',\'B\',\'S\')';


Execute Method :

   set<Id> optyWithQuoteSet = new set<Id>();
    
      List<Rebate_Amount__c> RBTableList = new List<Rebate_Amount__c>();
  
      for (sObject obj :scope)
      {
         Opportunity op = (Opportunity)obj;
          
         optyWithQuoteSet.add(op.id);
      }

List<Quote_Line_Item__c> Shiped_data = [select  Product__r.name,Net_Amount_5__c,Quote__r.Opportunity.Distribution_Channel__c
,Quote__r.Net_Amount__c,Product__r.Product_Group_Report__c,Line_Item_Number__c  from Quote_Line_Item__c where Quote__r.QuoteNumber<> null and
Quote__r.Opportunity.StageName='S' and Quote__r.Opportunity.id=:optyWithQuoteSet ];


for(Quote_Line_Item__c oli : Shiped_data)
{

Rebate_Amount__c rv= new Rebate_Amount__c();
   rv.Sale_Group__c= oli.Quote__r.Opportunity.Sale_Group__c;
   rv.Sale_Office__c = oli.Quote__r.Opportunity.Sale_Office__c;
   rv.Enquiry_No__c = oli.Quote__r.Opportunity.Auto_Number__c;
   rv.Rebate_by_Qountity__c=0;
   rv.Customer_Id__c = oli.Quote__r.Opportunity.Account.Account_Number__c;
   rv.Item_Number__c = oli.Line_Item_Number__c;
        system.debug(' out side shipped for loop ');
   for (Shipped__c sch :[select cost__c,Material__c  ,Opportunity2__r.id from Shipped__c where Quote__c!=null and Material__c=:oli.Product__r.name and Opportunity2__r.id=:oli.Quote__r.Opportunity.id])
   {
      system.debug(' Shipped for loop ');
    
   if (sch.Opportunity2__r.id == oli.Quote__r.Opportunity.id && oli.Product__r.name ==sch.Material__c)
   {
   rv.Cost__c = sch.cost__c;
   }
   RBTableList.add(rv);
   }
   }  
 
   if(RBTableList.size()>0)
   {
   insert RBTableList;
   }
My client have requirement, when he click Error Message it should be re-direct to Opportunity detail page, is this possible through Validation rules or Apex class?