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
sanjaykumarsanjaykumar 

Retriving records

Hi All,
               I am retrieving the records from opportunity line item schedule corresponding to the opportunity line item id, but there are multiple records in OpportunityLineItemSchedule corresponding to the one OpportunityLineItemId ..
 
I dont know how the compare the records available from the OpportunityLineItemSchedule with the OpportunityLineItemId and fetch the matched records and how to store them in an object.
 
Please help..
Thanks in Advance,
sanjay..
 
The_FoxThe_Fox
Hello Sanjay,

Can you precise what you would like to achieve?

Regards

sanjaykumarsanjaykumar
Hi Fox,
 
      I am using the Opportunity line Item Id to get thr Opportunity ID and then comparing that id in the Pricebook entry to get the product details corresponding to it, I am able to do this using the retrieve function ..now i am using the same Opportunity Line Item Id to get the records of revenue and schedule date corresponding to the OpportunityLineItemId and the product associated with it..
 
but the Problem is that one OpportunityLineItemId has mutilple record rows which are distinct only on schedule date...
 
I have to take all  the records and upsert it to a new custom ogject named "GP_Calc" in my project.
 
but when i use this Retrieve function and passing Opportunity LIne Item Id its returning null value..
 
i am  also sending you the code, plz help....
 
private void doUpsert() {
  QueryResult qr = null;
  try {
   qr = binding.query("select opportunityId,pricebookEntryId,Id from OpportunityLineItem");
   } catch (UnexpectedErrorFault uef) {
   System.out.println(uef.getExceptionMessage() + "\n\n");
   return;
   } catch (Exception e) {
   e.printStackTrace();
   System.out.println("\n\n");
   return;
  }
  if (qr != null) {
   SObject[] records = qr.getRecords();
   _opportunityLineItem = new OpportunityLineItem[records.length];
   for (int i = 0; i < records.length; i++) {
    OpportunityLineItem opportunityLineItem = (OpportunityLineItem) records[i];
    _opportunityLineItem[i] = opportunityLineItem;
    
    System.out.println("                                               ");
    System.out.println(" Opportunity ID                              - " + opportunityLineItem.getOpportunityId());
    System.out.println(" Price Book Entry Id                         - " + opportunityLineItem.getPricebookEntryId());
    System.out.println(" Opportunity Line Item Id                    - " + opportunityLineItem.getId());
        
    SObject[] upsertobject = new GP_Calc__c[1];
    GP_Calc__c upsertGP = new GP_Calc__c();
    ID opportunityid = opportunityLineItem.getOpportunityId();
    upsertGP.setOpportunity__c(opportunityid);
    try {
     SObject[] sObjects = binding.retrieve("product2Id,name,pricebook2Id", "PricebookEntry", new ID[] {opportunityLineItem.getPricebookEntryId()});
     
     if (sObjects != null) {
      for ( int j = 0; j< sObjects.length; j++) {
       PricebookEntry pbe = (PricebookEntry) sObjects[j];
       System.out.println(" Product 2 Id                                - " + pbe.getProduct2Id());
       
       ID productid = pbe.getProduct2Id();
       upsertGP.setProduct2__c(productid);
      }
     }
    } catch (Exception ex) {
     System.out.println("An unexpected error has occurred." + ex.getMessage());
    }
    
    try { 
     SObject[] sObject = binding.retrieve("revenue,scheduleDate,Id","OpportunityLineItemSchedule",new ID[] {opportunityLineItem.getId()});
    
     if (sObject != null) {
      
      for (int k = 0; k < 1; k++) {
       OpportunityLineItemSchedule olis = (OpportunityLineItemSchedule) sObject[k];
       System.out.println("Revenue                          - " + olis.getRevenue());
       System.out.println("Scheduled Date                   - " + olis.getScheduleDate());
       
       Double revenue = olis.getRevenue();
       upsertGP.setGP_Amount__c(revenue);
       
       Date scheduleDate = new Date(olis.getScheduleDate().getTime());
       upsertGP.setSchedule_Date__c(scheduleDate);
       
       ID externalid = olis.getId();
       upsertGP.setExternal_ID__c(externalid);
      }
     }
    } catch (Exception ex) {
     System.out.println("An unexpected error has occurred." + ex.getMessage());
    }
    
    upsertobject[0] = upsertGP;
    try {
     UpsertResult[] upsertResults = binding.upsert("External_Id__c", upsertobject);
     if (upsertResults[0].isSuccess())
      System.out.println("\nthe upsertion is a success\n");
     else {
      System.out.println("\nthe upsertion was a failure\n");
     }
    } catch (RemoteException ex) {
     System.out.println("An unexpected error has occurred....." + ex.getMessage());
    }
    getUserInput("\nPress the RETURN key to continue...");
   }
  }
 }
 
please let me know the changes i need to make in the code......
 
thanks in  Advance...