• Mark.Mulholland
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

Hello,

 

I am trying to create a button that sits on the OpportunityLineItem related list on Opportunities that will create a new Price Plan record for each line item it finds. In theory this doesn't sound too hard but I keep getting an error "identifier starts immediately after numerical literal" and I can't figure out what is causing this error. I don;t see anything wrong with my syntax

 

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.OpportunityLineItem)};
var newRecords = []; 

if (records[0] == null) 
{ 
    alert("Please select at least one row");
} 
else 
{
    var oppLineItemRec = sforce.connection.query("select Product2,UnitPrice,Quantity from OpportunityLineItem where id in ('"+ records +"')");

    for (var n=0; n < oppLineItemRec.length; n++) { 
        var c = new sforce.SObject("Price_Plan__c");
        c.Product__c = oppLineItemRec[n].Product2; 
        c.List_Price__c = oppLineItemRec[n].UnitPrice;
        c.Quantity__c = oppLineItemRec[n].Quantity; 
        c.Account__c = {!Opportunity.AccountId};
        c.Opportunity__c = {!Opportunity.Id};
        newRecords.push(c);
    }
}

var result = sforce.connection.create(newRecords); 

window.location.reload();

 Does anyone know what this error could be caused by?

Thanks

Mark

Hello,

 

I am trying to create a trigger on a custom object called Price Plan. The Trigger should query the PriceBookEntry object and, using the associated Product Id, The Account's Currency ISO Code and a hard coded Price Book Id. retrieve the UnitPrice and enter in into the List Price field on the Price Plan.

 

I could get the trigger to save but I am getting an Index Out Of Bounds error when I save a Price Plan which presumably means the SOQL Query is not getting any results to populate the UnitPrices List. However I tested this SOQL Query in the Dataloader and it worked. Can someone let me know where I am going wrong please

 

I know the code is not pretty, I haven't been coding long :/

 

 

 

 

trigger getPriceBookEntry on Price_Plan__c (before insert, before update) {


    Id[] productIds = new List<Id>();
    string[] currencyISOs = new List<string>();
    double[] unitPrices = new List<double>();
    Integer i = 0;
    //declare variables
    
    
    
    for (Price_Plan__c p : trigger.new) {
               productIds.set(i,p.product__r.id);
               currencyISOs.set(i,p.account__r.CurrencyIsoCode);
               i++;
               //iterate through all new Price Plans and each time insert the
               //product Id's and Currency ISO's for each Price Plan into the lists
               }
               
    
    
          i = 0;
          for (PriceBookEntry pbu : [Select UnitPrice from pricebookEntry where PriceBook2Id = '01sL0000000CoyR'
                                      AND currencyISOCode = :currencyISOs.get(i)
                                      AND product2id = :productIds.get(i)]) {
               unitPrices.set(i,pbu.UnitPrice);
               i++;
               //perform a SOQL query to pull the corresponding UnitPrice from the PriceBookEntry object where the
               //ProductId and CurrencyISO's match up. Then insert the Unit Price into the UnitPrices list
       }
         
         
         
    
    i = 0;
    for (price_plan__c p : trigger.new) {
        p.List_Price__c = unitPrices.get(i);
        i++;
        //Loop through all Price Plans again, this time populating the List_Price__c field with the
        //associated UnitPrice
        }
         
         
         
               
}

Hello,

 

I am trying to create a button that sits on the OpportunityLineItem related list on Opportunities that will create a new Price Plan record for each line item it finds. In theory this doesn't sound too hard but I keep getting an error "identifier starts immediately after numerical literal" and I can't figure out what is causing this error. I don;t see anything wrong with my syntax

 

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.OpportunityLineItem)};
var newRecords = []; 

if (records[0] == null) 
{ 
    alert("Please select at least one row");
} 
else 
{
    var oppLineItemRec = sforce.connection.query("select Product2,UnitPrice,Quantity from OpportunityLineItem where id in ('"+ records +"')");

    for (var n=0; n < oppLineItemRec.length; n++) { 
        var c = new sforce.SObject("Price_Plan__c");
        c.Product__c = oppLineItemRec[n].Product2; 
        c.List_Price__c = oppLineItemRec[n].UnitPrice;
        c.Quantity__c = oppLineItemRec[n].Quantity; 
        c.Account__c = {!Opportunity.AccountId};
        c.Opportunity__c = {!Opportunity.Id};
        newRecords.push(c);
    }
}

var result = sforce.connection.create(newRecords); 

window.location.reload();

 Does anyone know what this error could be caused by?

Thanks

Mark

Hello,

 

I am trying to create a trigger on a custom object called Price Plan. The Trigger should query the PriceBookEntry object and, using the associated Product Id, The Account's Currency ISO Code and a hard coded Price Book Id. retrieve the UnitPrice and enter in into the List Price field on the Price Plan.

 

I could get the trigger to save but I am getting an Index Out Of Bounds error when I save a Price Plan which presumably means the SOQL Query is not getting any results to populate the UnitPrices List. However I tested this SOQL Query in the Dataloader and it worked. Can someone let me know where I am going wrong please

 

I know the code is not pretty, I haven't been coding long :/

 

 

 

 

trigger getPriceBookEntry on Price_Plan__c (before insert, before update) {


    Id[] productIds = new List<Id>();
    string[] currencyISOs = new List<string>();
    double[] unitPrices = new List<double>();
    Integer i = 0;
    //declare variables
    
    
    
    for (Price_Plan__c p : trigger.new) {
               productIds.set(i,p.product__r.id);
               currencyISOs.set(i,p.account__r.CurrencyIsoCode);
               i++;
               //iterate through all new Price Plans and each time insert the
               //product Id's and Currency ISO's for each Price Plan into the lists
               }
               
    
    
          i = 0;
          for (PriceBookEntry pbu : [Select UnitPrice from pricebookEntry where PriceBook2Id = '01sL0000000CoyR'
                                      AND currencyISOCode = :currencyISOs.get(i)
                                      AND product2id = :productIds.get(i)]) {
               unitPrices.set(i,pbu.UnitPrice);
               i++;
               //perform a SOQL query to pull the corresponding UnitPrice from the PriceBookEntry object where the
               //ProductId and CurrencyISO's match up. Then insert the Unit Price into the UnitPrices list
       }
         
         
         
    
    i = 0;
    for (price_plan__c p : trigger.new) {
        p.List_Price__c = unitPrices.get(i);
        i++;
        //Loop through all Price Plans again, this time populating the List_Price__c field with the
        //associated UnitPrice
        }
         
         
         
               
}