• Stavros McGillicuddy
  • NEWBIE
  • 45 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 21
    Replies
Why does this formula return Sunday result is 2 when it should be 1 
 
(Actual_Ship_Date__c - Expected_Ship_Date__c) - ( FLOOR ( ( ( (Actual_Ship_Date__c) - Expected_Ship_Date__c) / 7 ) ) * 2 ) + CASE(MOD ( Expected_Ship_Date__c - DATE( 1900,1,6 ),7), 0,CASE( MOD ((Actual_Ship_Date__c) - DATE( 1900,1,6 ),7),0,1,2 ), 1,CASE( MOD ((Actual_Ship_Date__c) - DATE( 1900,1,6 ),7),0,2,1 ), IF(MOD(Expected_Ship_Date__c - DATE( 1900,1,6 ),7) - MOD((Actual_Ship_Date__c) - DATE( 1900,1,6 ),7) <= 0 ,0, IF(MOD((Actual_Ship_Date__c) - DATE( 1900,1,6 ),7) = 0,1,-2 ) ) )

 
Sudden Full Sandbox horrible performance, it takes up to 5 minutes to move from object to object.
Cleared cache and tried different browser and different computer. If I "refresh" the sandbox, will I loose all the work I've done? 
Is there anything else I can try?
I am trying to modify this code (found on forums) to update the Expected_Ship_Date__c to CloseDate + one business day
Im not getting any errors but, the field is not updating

Monday + 1
Tuesday  + 1
Wednesday  + 1
Thursday  + 1
Friday + 3
Saturday + 2
Sunday  + 1
CASE(MOD( CloseDate - DATE( 1900, 1, 7 ), 7 ), 
1, CloseDate + 1, 
2, CloseDate + 1, 
3, CloseDate + 1, 
4, CloseDate + 1, 
5, CloseDate + 3, 
6, CloseDate + 2, 
CloseDate + 1 
)

 
This code queries the current opportunity's line item Name, Quantity, TotalPrice and Description and places them into custom fields and executes without error.

The problem is it only places the first two characters of the Name. 
The receiving field is a text (100) field

By commenting out this line, it works as expected but I don’t know how to fix it.
I was graciously helped with this by the community so I am not sure what this line is supposed to do or if I even need it  

if(strProductNames.length>0){ strProductNames = strProductNames.substring(0,strProductNames.length-2); } ​
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 

var record = new sforce.SObject("Opportunity"); 
record.Id = '{!Opportunity.Id}'; 

result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice, Description, ServiceDate From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')"); 
records = result.getArray("records"); 

var strProductNames = ''; 
var strProductQuantity = ''; 
var strProductPrice = ''; 
var strDescription = ''; 
var strServiceDate = ''; 
for(var i=0; i<records.length ; i++){ 
strProductNames = records[i].PricebookEntry.Product2.Name 
strProductQuantity = records[i].Quantity 
strProductPrice = records[i].TotalPrice 
strDescription = records[i].Description 
strServiceDate = records[i].ServiceDate; 
} 

if(strProductNames.length>0){ 
strProductNames = strProductNames.substring(0,strProductNames.length-2); 
} 
record.Sample_Name__c = strProductNames; 
record.Sample_Quantity__c = strProductQuantity; 
record.Sample_Price__c = strProductPrice; 
record.Sample_Description__c = strDescription; 
record.Sample_Service_Date__c =strServiceDate; 

sforce.connection.update([record]); 
window.location.reload();

 
​I have to believe my syntax is not correct. Maybe I'm declaring everything as string rather than integer?

Sample_Name__c is a text field
Sample_Quantity__c is a numeric field
Sample_Price__c is a currency field

When I change all of the field types to text this code executes as expected but fails when the fields are set to numeric and currecy.
What edit to my code do I need to make?
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 

var record = new sforce.SObject("Opportunity"); 
record.Id = '{!Opportunity.Id}'; 

//copy opportunity line items 
result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')"); 
records = result.getArray("records"); 

var strProductNames = ''; 
var strProductQuantity = ''; 
var strProductPrice = ''; 
for(var i=0; i<records.length ; i++){ 
strProductNames = records[i].PricebookEntry.Product2.Name 
strProductQuantity = records[i].Quantity 
strProductPrice = records[i].TotalPrice; 
} 

if(strProductNames.length>0){ 
strProductNames = strProductNames.substring(0,strProductNames.length-2); 
} 
record.Sample_Name__c = strProductNames; 
record.Sample_Quantity__c = [i].strProductQuantity; 
record.Sample_Price__c = strProductPrice; 

sforce.connection.update([record]); 
window.location.reload();

 
The code below will take all Product Names, Quantities and Total Price for each Opportunity line item of an Opportunity and concatenate them into one custom fields and then delete the Opportunity Line Items. It works flawlessly

For reporting purposes, instead of concatenating into one field I need this code modified to copy the:..
1st Opportunity line item Name and place it in  Sample_1_Name__c
2nd Opportunity line item Name and place it in  Sample_2_Name__c
3rd Opportunity line item Name and place it in  Sample_3_Name__c
4th Opportunity line item Name and place it in  Sample_4_Name__c
5th Opportunity line item Name and place it in  Sample_5_Name__c

1st Opportunity line item Quantity and place it in Sample_1_Quantity__c
2nd Opportunity line item Quantity and place it in Sample_2_Quantity__c
3rd Opportunity line item Quantity and place it in Sample_3_Quantity__c
4th Opportunity line item Quantity and place it in Sample_4_Quantity__c
5th Opportunity line item Quantity and place it in Sample_5_Quantity__c

1st Opportunity line item Total Price and place it in Sample_1_Price__c
2nd Opportunity line item Total Price and place it in Sample_2_Price__c
3rd Opportunity line item Total Price and place it in Sample_3_Price__c
4th Opportunity line item Total Price and place it in Sample_4_Price__c
5th Opportunity line item Total Price and place it in Sample_5_Price__c
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}

var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';

//copy opportunity line items
result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')");
records = result.getArray("records");

var strProductNames = '';
for(var i=0; i<records.length ; i++){
 strProductNames += 'PRODUCT NAME: ' + records[i].PricebookEntry.Product2.Name + ' --- QUANTITY: ' + records[i].Quantity + ' --- TOTAL PRICE: $ ' + records[i].TotalPrice +',\n';
}

if(strProductNames.length>0){
 strProductNames = strProductNames.substring(0,strProductNames.length-2);
}
record.Samples_Sent__c = strProductNames;

//delete opportunity line items
var lineItems = sforce.connection.query("select id from opportunitylineitem where opportunityid = '{!Opportunity.Id}'")
var oliIds = []
var qri = new sforce.QueryResultIterator(lineItems)
while(qri.hasNext())
    oliIds.push(qri.next().Id)
sforce.connection.deleteIds(oliIds)

sforce.connection.update([record]);
window.location.reload();

 
I've made multiple changes in sandbox.. Custom fields, page layouts, modified picklists, workflows and apex buttons and reports.
I'm getting ready to push to production.

Is it a good practice to select all custom fields, layouts reports etc into the change set? Or, is there a way select all the changes made by my user?
Opportunity Product line items are added to our Opportunities as they mature.
I am in need of an Opportunity with Products report 
I need to report Opportunities and their Products, Quantity and Price while the status was New and "Pending"
I cannot seem to find an Opportunity history report that can get me there. 
At the click of a custom button on an Opportunity object, this is supposed to:
  1. Capture all Opportunity line items
  2. Concatenate all line items except ones that have DISCOUNT in the name into a Samples_Sent__c field
  3. Delete all Opportunity line items
It executes perfectly if the net count (opportunity line items that do not have DISCOUNT in the name) of the items being concatenated is two or more but does nothing (does not concatenate and no errors) if the net count is one.
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';

var retriveOpptyLineItems = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')");

var strProductNames = '';
for(var i=0; i<retriveOpptyLineItems.records.length ; i++){
strProductNames += 'PRODUCT NAME: ' + retriveOpptyLineItems.records[i].PricebookEntry.Product2.Name + ' --- QUANTITY: ' + retriveOpptyLineItems.records[i].Quantity + ' --- TOTAL PRICE: $ ' + retriveOpptyLineItems.records[i].TotalPrice +',' + '\n ';
}

//eliminate the last ','
if(strProductNames.length>0){
strProductNames = strProductNames.substring(0,strProductNames.length-1);
}
record.Samples_Sent__c = strProductNames;

sforce.connection.update([record]);
window.location.reload();

 
This should copy Opportunity Line Items to a Custom field when the product name does not include "Discount". It runs perfectly when "Discount" is not the first line item. If it is, it fails with "Cannot read property 'length' of undefined"
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';

var retriveOpptyLineItems = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')");

var strProductNames = '';
for(var i=0; i<retriveOpptyLineItems.records.length ; i++){
strProductNames += 'PRODUCT NAME: ' + retriveOpptyLineItems.records[i].PricebookEntry.Product2.Name + ' --- QUANTITY: ' + retriveOpptyLineItems.records[i].Quantity + ' --- TOTAL PRICE: $ ' + retriveOpptyLineItems.records[i].TotalPrice +',' + '\n ';
}

sforce.connection.update([record]);
window.location.reload();

 
With a lot of help from the forum over the past week, I have a custom button that performs a series of functions on the Opportunity object

 1. It copies 6 fields to six custom fields
 2. It clears the 6 fields
 3. It copies all Opportunity Line Items to a Custom field
 4. It deletes all Opportunity Line Items

It seems like item 4 sometimes fires before 3 has completed so, the Opportunity line Items never make it into the custom field.

Realizing I'm a noob, is there an easy remedy? Maybe have a message box popup that fires the code for Item 4 on it?
Why can I get this to run in the Developer Console but not from a custom button?
I get an unexpected identifier error 
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}

OpportunityLineItem opp=[Select OpportunityID From OpportunityLineItem WHERE OpportunityId = '0063300000iu2IC'];
delete opp;

sforce.connection.update([record]);
window.location.reload();
I'm trying to delete all Product Line Items for an Opportunity via a javascript button.
This gives me an Unknown error parsing query error in the developer Console
Select OpportunityID From OpportunityLineItem WHERE OpportunityId = '0063300000iu2IC' delete OpportunityID

 
The code below works fine concatenating PriceBook.Entry.Product2.Name on seperate lines of a custom field with a comma at the end of each line.

I need to add Quantity and TotalCost for each Opportunity Product Line item to each line of the custom field and seperate the values with a space hyphen space like this:

PricebookEntryProduct2.Name - Quantity - TotalCost,
PricebookEntryProduct2.Name - Quantity - TotalCost,
PricebookEntryProduct2.Name - Quantity - TotalCost,
PricebookEntryProduct2.Name - Quantity - TotalCost,

When I try to add Quantity and TotalPrice like this, I get a "Quantity not defined" error
 
var strProductNames = '';
for(var i=0; i<retriveOpptyLineItems.records.length ; i++){
strProductNames += retriveOpptyLineItems.records[i].PricebookEntry.Product2.Name, Quantity, TotalPrice + ',' + '\n ';
}


 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';
var retriveOpptyLineItems = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')");
 
var strProductNames = '';
for(var i=0; i<retriveOpptyLineItems.records.length ; i++){
strProductNames += retriveOpptyLineItems.records[i].PricebookEntry.Product2.Name + ',' + '\n ';
}
 
//eliminate the last ','
if(strProductNames.length>0){
strProductNames = strProductNames.substring(0,strProductNames.length-1);
}
record.Sample_Product_Name_1__c = strProductNames;
sforce.connection.update([record]);
window.location.reload();
This code grabs only one of the Opportunity Line Item names and puts it into a field.
I need to add a loop to grab all Opportunity Line Items for an Opportunity
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';
var retriveOpptyLineItems = sforce.connection.query("Select PricebookEntry.Product2.Name From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}'");

record.Sample_Product_Name_1__c=retriveOpptyLineItems.records[0].PricebookEntry.Product2.Name; 

sforce.connection.update([record]); 
window.location.reload();

 
This "should" work by placing everything into one field (Sample_Product_Name_1). but it throws an "Invalid or Unexpected token" error
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}

var record = new sforce.SObject("Opportunity");
record.oli ='{Select Amount,CloseDate,Name, 
     (Select PricebookEntry.Product2Id, 
             TotalPrice, 
             UnitPrice, 
             ListPrice 
      From OpportunityLineItems) 
   From Opportunity};

record.Id = '{!Opportunity.Id}';
record.Sample_Product_Name_1__c= record.oli;
sforce.connection.update([record]); window.location.reload();

 
My opportunities may have up to 4 products (line items) attached to them.
I am looking for the syntax to copy the 4 Opportunity > Product Names to 4 custom fiedls on the Opportunity object

This does not throw an error but it does nothing
record.Sample_Product_Name_2__c='{!Product2.Name}';

 
I am trying to copy a picklist value to a text field with a custom button but can't figure out the syntax.

This syntax populates the field with
TEXT(!Opportunity.AVSFQB__Generate_Object__c) 
 
record.Sample_Generate__c = 'TEXT(!Opportunity.AVSFQB__Generate_Object__c)'; 

Thank you
I am trying to update the Sample_QB_Error__c field with Hello
This code throws "an Invalid or unexpected token"  

Thanks
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 
var record = new sforce.SObject("Opportunity"); 
record.Id = ‘{!Opportunity.Id}’; 
record.Sample_QB_Error__c ="Hello"; 
sforce.connection.update([record]); 
window.location.reload();

 
On my Opportunity object: I have created six custom fields
AVSFQB__Generate_Object__c  (picklist)
AVSFQB__Quickbooks_Id__c  (text 50 - External ID)
AVSFQB__QuickBooks_ItemType__c   (picklist)
Sample_Generate__c  (text 100)
Sample_Quickbooks_ID__c   (text 50)
Sample_QuickBooks_ItemType__c   (text 100)
I have also created a custom button Process_Sample_Sent

I would like to click the button and move the field contents:
AVSFQB__Generate_Object__c to Sample_Generate__c
AVSFQB__Quickbooks_Id__c to Sample_Quickbooks_ID__c
AVSFQB__QuickBooks_ItemType__c to Sample_QuickBooks_ItemType__c

On the custom button, I have selected:
Display type - Detail Page Button
Behavior - Execute JavaScript
Content Source - OnClick JavaScript

I am trying to get this code to work with one set of fields before I add the others

This code produces an "Unexpected identifier error"
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var record = new sforce.SObject("Opportunity__c"); 
record.Id = ("Opportunity__c.Id"); 
record.Sample_Generate__c = {!Opportunity.AVSFQB__Generate_Object__c};
var result = sforce.connection.update([record]); 
// check the result here 
window.location.reload();

 
I am trying to update the Sample_QB_Error__c field with Hello
This code throws "an Invalid or unexpected token"  

Thanks
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 
var record = new sforce.SObject("Opportunity"); 
record.Id = ‘{!Opportunity.Id}’; 
record.Sample_QB_Error__c ="Hello"; 
sforce.connection.update([record]); 
window.location.reload();

 
Why does this formula return Sunday result is 2 when it should be 1 
 
(Actual_Ship_Date__c - Expected_Ship_Date__c) - ( FLOOR ( ( ( (Actual_Ship_Date__c) - Expected_Ship_Date__c) / 7 ) ) * 2 ) + CASE(MOD ( Expected_Ship_Date__c - DATE( 1900,1,6 ),7), 0,CASE( MOD ((Actual_Ship_Date__c) - DATE( 1900,1,6 ),7),0,1,2 ), 1,CASE( MOD ((Actual_Ship_Date__c) - DATE( 1900,1,6 ),7),0,2,1 ), IF(MOD(Expected_Ship_Date__c - DATE( 1900,1,6 ),7) - MOD((Actual_Ship_Date__c) - DATE( 1900,1,6 ),7) <= 0 ,0, IF(MOD((Actual_Ship_Date__c) - DATE( 1900,1,6 ),7) = 0,1,-2 ) ) )

 
Sudden Full Sandbox horrible performance, it takes up to 5 minutes to move from object to object.
Cleared cache and tried different browser and different computer. If I "refresh" the sandbox, will I loose all the work I've done? 
Is there anything else I can try?
I am trying to modify this code (found on forums) to update the Expected_Ship_Date__c to CloseDate + one business day
Im not getting any errors but, the field is not updating

Monday + 1
Tuesday  + 1
Wednesday  + 1
Thursday  + 1
Friday + 3
Saturday + 2
Sunday  + 1
CASE(MOD( CloseDate - DATE( 1900, 1, 7 ), 7 ), 
1, CloseDate + 1, 
2, CloseDate + 1, 
3, CloseDate + 1, 
4, CloseDate + 1, 
5, CloseDate + 3, 
6, CloseDate + 2, 
CloseDate + 1 
)

 
This code queries the current opportunity's line item Name, Quantity, TotalPrice and Description and places them into custom fields and executes without error.

The problem is it only places the first two characters of the Name. 
The receiving field is a text (100) field

By commenting out this line, it works as expected but I don’t know how to fix it.
I was graciously helped with this by the community so I am not sure what this line is supposed to do or if I even need it  

if(strProductNames.length>0){ strProductNames = strProductNames.substring(0,strProductNames.length-2); } ​
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 

var record = new sforce.SObject("Opportunity"); 
record.Id = '{!Opportunity.Id}'; 

result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice, Description, ServiceDate From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')"); 
records = result.getArray("records"); 

var strProductNames = ''; 
var strProductQuantity = ''; 
var strProductPrice = ''; 
var strDescription = ''; 
var strServiceDate = ''; 
for(var i=0; i<records.length ; i++){ 
strProductNames = records[i].PricebookEntry.Product2.Name 
strProductQuantity = records[i].Quantity 
strProductPrice = records[i].TotalPrice 
strDescription = records[i].Description 
strServiceDate = records[i].ServiceDate; 
} 

if(strProductNames.length>0){ 
strProductNames = strProductNames.substring(0,strProductNames.length-2); 
} 
record.Sample_Name__c = strProductNames; 
record.Sample_Quantity__c = strProductQuantity; 
record.Sample_Price__c = strProductPrice; 
record.Sample_Description__c = strDescription; 
record.Sample_Service_Date__c =strServiceDate; 

sforce.connection.update([record]); 
window.location.reload();

 
​I have to believe my syntax is not correct. Maybe I'm declaring everything as string rather than integer?

Sample_Name__c is a text field
Sample_Quantity__c is a numeric field
Sample_Price__c is a currency field

When I change all of the field types to text this code executes as expected but fails when the fields are set to numeric and currecy.
What edit to my code do I need to make?
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 

var record = new sforce.SObject("Opportunity"); 
record.Id = '{!Opportunity.Id}'; 

//copy opportunity line items 
result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')"); 
records = result.getArray("records"); 

var strProductNames = ''; 
var strProductQuantity = ''; 
var strProductPrice = ''; 
for(var i=0; i<records.length ; i++){ 
strProductNames = records[i].PricebookEntry.Product2.Name 
strProductQuantity = records[i].Quantity 
strProductPrice = records[i].TotalPrice; 
} 

if(strProductNames.length>0){ 
strProductNames = strProductNames.substring(0,strProductNames.length-2); 
} 
record.Sample_Name__c = strProductNames; 
record.Sample_Quantity__c = [i].strProductQuantity; 
record.Sample_Price__c = strProductPrice; 

sforce.connection.update([record]); 
window.location.reload();

 
The code below will take all Product Names, Quantities and Total Price for each Opportunity line item of an Opportunity and concatenate them into one custom fields and then delete the Opportunity Line Items. It works flawlessly

For reporting purposes, instead of concatenating into one field I need this code modified to copy the:..
1st Opportunity line item Name and place it in  Sample_1_Name__c
2nd Opportunity line item Name and place it in  Sample_2_Name__c
3rd Opportunity line item Name and place it in  Sample_3_Name__c
4th Opportunity line item Name and place it in  Sample_4_Name__c
5th Opportunity line item Name and place it in  Sample_5_Name__c

1st Opportunity line item Quantity and place it in Sample_1_Quantity__c
2nd Opportunity line item Quantity and place it in Sample_2_Quantity__c
3rd Opportunity line item Quantity and place it in Sample_3_Quantity__c
4th Opportunity line item Quantity and place it in Sample_4_Quantity__c
5th Opportunity line item Quantity and place it in Sample_5_Quantity__c

1st Opportunity line item Total Price and place it in Sample_1_Price__c
2nd Opportunity line item Total Price and place it in Sample_2_Price__c
3rd Opportunity line item Total Price and place it in Sample_3_Price__c
4th Opportunity line item Total Price and place it in Sample_4_Price__c
5th Opportunity line item Total Price and place it in Sample_5_Price__c
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}

var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';

//copy opportunity line items
result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')");
records = result.getArray("records");

var strProductNames = '';
for(var i=0; i<records.length ; i++){
 strProductNames += 'PRODUCT NAME: ' + records[i].PricebookEntry.Product2.Name + ' --- QUANTITY: ' + records[i].Quantity + ' --- TOTAL PRICE: $ ' + records[i].TotalPrice +',\n';
}

if(strProductNames.length>0){
 strProductNames = strProductNames.substring(0,strProductNames.length-2);
}
record.Samples_Sent__c = strProductNames;

//delete opportunity line items
var lineItems = sforce.connection.query("select id from opportunitylineitem where opportunityid = '{!Opportunity.Id}'")
var oliIds = []
var qri = new sforce.QueryResultIterator(lineItems)
while(qri.hasNext())
    oliIds.push(qri.next().Id)
sforce.connection.deleteIds(oliIds)

sforce.connection.update([record]);
window.location.reload();

 
I've made multiple changes in sandbox.. Custom fields, page layouts, modified picklists, workflows and apex buttons and reports.
I'm getting ready to push to production.

Is it a good practice to select all custom fields, layouts reports etc into the change set? Or, is there a way select all the changes made by my user?
At the click of a custom button on an Opportunity object, this is supposed to:
  1. Capture all Opportunity line items
  2. Concatenate all line items except ones that have DISCOUNT in the name into a Samples_Sent__c field
  3. Delete all Opportunity line items
It executes perfectly if the net count (opportunity line items that do not have DISCOUNT in the name) of the items being concatenated is two or more but does nothing (does not concatenate and no errors) if the net count is one.
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';

var retriveOpptyLineItems = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')");

var strProductNames = '';
for(var i=0; i<retriveOpptyLineItems.records.length ; i++){
strProductNames += 'PRODUCT NAME: ' + retriveOpptyLineItems.records[i].PricebookEntry.Product2.Name + ' --- QUANTITY: ' + retriveOpptyLineItems.records[i].Quantity + ' --- TOTAL PRICE: $ ' + retriveOpptyLineItems.records[i].TotalPrice +',' + '\n ';
}

//eliminate the last ','
if(strProductNames.length>0){
strProductNames = strProductNames.substring(0,strProductNames.length-1);
}
record.Samples_Sent__c = strProductNames;

sforce.connection.update([record]);
window.location.reload();

 
I'm trying to delete all Product Line Items for an Opportunity via a javascript button.
This gives me an Unknown error parsing query error in the developer Console
Select OpportunityID From OpportunityLineItem WHERE OpportunityId = '0063300000iu2IC' delete OpportunityID

 
This code grabs only one of the Opportunity Line Item names and puts it into a field.
I need to add a loop to grab all Opportunity Line Items for an Opportunity
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
var record = new sforce.SObject("Opportunity");
record.Id = '{!Opportunity.Id}';
var retriveOpptyLineItems = sforce.connection.query("Select PricebookEntry.Product2.Name From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}'");

record.Sample_Product_Name_1__c=retriveOpptyLineItems.records[0].PricebookEntry.Product2.Name; 

sforce.connection.update([record]); 
window.location.reload();

 
My opportunities may have up to 4 products (line items) attached to them.
I am looking for the syntax to copy the 4 Opportunity > Product Names to 4 custom fiedls on the Opportunity object

This does not throw an error but it does nothing
record.Sample_Product_Name_2__c='{!Product2.Name}';

 
I am trying to copy a picklist value to a text field with a custom button but can't figure out the syntax.

This syntax populates the field with
TEXT(!Opportunity.AVSFQB__Generate_Object__c) 
 
record.Sample_Generate__c = 'TEXT(!Opportunity.AVSFQB__Generate_Object__c)'; 

Thank you
I am trying to update the Sample_QB_Error__c field with Hello
This code throws "an Invalid or unexpected token"  

Thanks
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 
var record = new sforce.SObject("Opportunity"); 
record.Id = ‘{!Opportunity.Id}’; 
record.Sample_QB_Error__c ="Hello"; 
sforce.connection.update([record]); 
window.location.reload();

 
On my Opportunity object: I have created six custom fields
AVSFQB__Generate_Object__c  (picklist)
AVSFQB__Quickbooks_Id__c  (text 50 - External ID)
AVSFQB__QuickBooks_ItemType__c   (picklist)
Sample_Generate__c  (text 100)
Sample_Quickbooks_ID__c   (text 50)
Sample_QuickBooks_ItemType__c   (text 100)
I have also created a custom button Process_Sample_Sent

I would like to click the button and move the field contents:
AVSFQB__Generate_Object__c to Sample_Generate__c
AVSFQB__Quickbooks_Id__c to Sample_Quickbooks_ID__c
AVSFQB__QuickBooks_ItemType__c to Sample_QuickBooks_ItemType__c

On the custom button, I have selected:
Display type - Detail Page Button
Behavior - Execute JavaScript
Content Source - OnClick JavaScript

I am trying to get this code to work with one set of fields before I add the others

This code produces an "Unexpected identifier error"
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var record = new sforce.SObject("Opportunity__c"); 
record.Id = ("Opportunity__c.Id"); 
record.Sample_Generate__c = {!Opportunity.AVSFQB__Generate_Object__c};
var result = sforce.connection.update([record]); 
// check the result here 
window.location.reload();