• Bango
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 12
    Replies
Hello,
I have the following JS code in a an opportunity Detail custom button. My goal:

- Have Sales reps click on a button fron the opportunity that will create a quote record, set the pricebook, and add a quote line item. Everything works except getting the ID of the quote created so I can create the line under it (meaning that I can give it a static ID and it'll work). I highlited what I'm looking to fix in Bold (It's after the = sign). Please help me :)

{!REQUIRESCRIPT('/soap/ajax/34.0/connection.js')} 

var RecID = '{!Opportunity.RecordTypeId}'; 
var pricebookid = "01s60000000AaPr"; 
var newQuote = new sforce.SObject('Quote'); 

var CreateHeader = []; 

if (RecID == "01232000000Q897" || RecID == "012320000005P5G" || RecID == "012600000009XZ6") 

newQuote.RecordTypeId = '01232000000JOUt'; 


newQuote.Name = 'Proposal - {!Today}'; 
newQuote.OpportunityId = '{!Opportunity.Id}'; 
newQuote.Pricebook2Id = pricebookid; 

CreateHeader.push(newQuote) 

result = sforce.connection.create(CreateHeader); 

var CreateLines=[]; 

var linky=new sforce.SObject("QuoteLineItem"); 
linky.QuoteID = result[0].Id
linky.PriceBookEntryId = '01u6000000AQn3TAAT'; 
linky.Quantity = 1; 
linky.UnitPrice = 1; 
linky.Description = 'Add-On - FMA'; 
CreateLines.push(linky); 

result=sforce.connection.create(CreateLines); 


window.location.reload();
  • May 07, 2018
  • Like
  • 0
Hello all, I created this button on the Quote object to create QuoteLineItems but it's not working. Below is the code BUT please see my note below the code for some clarification:

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} 

var pricebookid = "01s60000000AaPr"; 
var quoteId = "{!Quote.Id}"; 
var quoteQuery = sforce.connection.query("Select Id, Name FROM Quote WHERE Id='" + quoteId + "'"); 
var quotyResult = quoteQuery.getArray("records"); 
quotyResult[0].Pricebook2Id = pricebookid; 
var updatequotyResult = sforce.connection.update([quotyResult[0]]); 


var result = sforce.connection.query("Select Id,Name,HE__c,HE_Qauntity__c,Price_Book_Entry_ID__c From Product2 Where HE__c = TRUE"); 
var records = result.getArray("records"); 

var CreateRecords=[]; 

if(records[0]==null) 
alert('No Product Set is Retrieved!'); 
for(var i=0;i<records.length;i++) 

var linky=new sforce.SObject("QuoteLineItem"); 
linky.QuoteID = '{!Quote.Id}'; 
linky.PriceBookEntryId = records[i].Price_Book_Entry_ID__c; 
linky.Quantity = records[i].HE_Qauntity__c; 
linky.UnitPrice = 1; 
linky.Quoting_Tool__c = 1; 
CreateRecords.push(linky); 


result=sforce.connection.create([CreateRecords]); 
alert(result); 


window.location.reload();


// The code works fine if I create them one by one within the loop but I wanted to create them at once from an array. For example, if I put 

result=sforce.connection.create([linky]);

in the loop it works fine but slow. That's whay I wanted to go the other way around to create them at once from an array. Please help. 
  • June 12, 2017
  • Like
  • 0
Hi there,

I wrote a a trigger to add a product to the opportunity, it works fine but I'm stuck at the test class which is giving me low code coverage, I need help with the test class. Please see the trigger/test class below, thanks in advance.

trigger AddOppLines on Opportunity (after update,after insert) 
{
    List<OpportunityLineItem> OppLineItems = new List<OpportunityLineItem>();
    for (Opportunity newOpp: Trigger.New) 
    {
            
            Integer C110013 = 1;
            
            for(PriceBookEntry a : [SELECT Id, ProductCode FROM PriceBookEntry WHERE PriceBook2.Name='Bulk TV 1'])
            {
                if (a.ProductCode == '110013' && C110013 > 0)
                {
                    OppLineItems.add(new OpportunityLineItem(OpportunityId = newOpp.Id,PricebookEntryId = a.Id,Quantity = C110013, UnitPrice = 0,Auto__c = TRUE));
                }
            }   
    }
    insert OppLineItems;
}


---------------------------------------------------------------------------------------------------------------------------------------------------------------


@isTest 
private class AddOppLinesTestClass 
{
    static testMethod void validateAddOppLines() 
    {
    
        PriceBook2 pb = new PriceBook2(Name='Bulk TV 1',IsActive=true);
        insert pb;
        
        Product2 p = new Product2(Name='TrigTest',IsActive=TRUE,ProductCode='110013',Description='TriggerTest');
        insert p;
        
        PricebookEntry pbe = new PricebookEntry(Product2Id = p.Id,PriceBook2Id = pb.Id,IsActive = true,UnitPrice = 20.00);
        
        Opportunity b = new Opportunity(Name='Test 1',StageName='New',CloseDate=Date.today());
        insert b;
    }
}
  • February 03, 2015
  • Like
  • 0

Hello experts :) I created the following APEX Class in my Dev Org:

 

@RestResource(urlMapping='/createCase/*')
global with sharing class RESTCaseController 
{

@HttpPost  
global static Void createNewCase()
{
Case c = new Case();
c.OwnerId = '005i0000001uqEm';
c.AccountId = '001i000000RsOOS';
c.Subject = 'SOAP Test';
c.Status = 'New';
insert c;
return;
}

}

 

 

So the endpoint URL is https://na15.salesforce.com/services/apexrest/FieldCase

 

There will be a a third party application that will send SOAP messages to that end point.


I would like to test it and see if it'll create a case for me :) Any help is much apreciated (By the way, I'm new to this so bare with me :) )

  • October 24, 2013
  • Like
  • 0

Hello all,

 

Scenario: An external System sends us SOAP messages. We have control over the URL the message gets sent to.

 

Goal: We create a case for each SOAP Message.

 

Solution? Can I create a REST URL API in Salesforce and point the Messages to that URL and parse the message to create a case out of it? If so, what's the best way to parse SOAP Messages? 

 

Thank you in advance :)

  • October 23, 2013
  • Like
  • 0

Hello all,

 

I have very little experience with this so please bare with me and be clear :)

 

We have an external system that sends out SOAP messages when an issue occurs. The goal is to catch those messages and create a case out of them. I would like to know how to do that in steps please. Any help is helpful :) Take care and please let me know if you need additional information.

  • October 22, 2013
  • Like
  • 0

Hello all,

 

I have very little experience with this so please bare with me and be clear :)

 

We have an external system that sends out SOAP messages when an issue occurs. The goal is to catch those messages and create a case out of them. I would like to know how to do that in steps please. Any help is helpful :) Take care and please let me know if you need additional information.

  • October 22, 2013
  • Like
  • 0

Hello all, this is my first post here :) I'm writing an APEX Trigger that is supposed to create a Product Line Item when an opportunity is created. Here is what I did:

 

trigger AutoCreateInterviewer on Opportunity (after insert) {
List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>();
for (Opportunity newOpportunity: Trigger.New) {
if (newOpportunity.of_HD_Channels__c != null) {
OpportunityLineItems.add(new OpportunityLineItem(ProductId = '01t60000004Inzu',Opportunity = newOpportunity.Id,Quantity = 3,UnitPrice = 50));
}
}
insert OpportunityLineItems;

 

but it's not working, it gives me the following error:

 

Error: Compile Error: Invalid field ProductId for SObject OpportunityLineItem at line 5 column 74

 


Could you kindly tell me what the right syntaz is for what I need? Thanks in advance

 

My issue is with the arguments I'm passing, mainly the ProductId and the Opportunity I think because it saves fine without them there, please help :(

  • June 28, 2013
  • Like
  • 0
Hello,
I have the following JS code in a an opportunity Detail custom button. My goal:

- Have Sales reps click on a button fron the opportunity that will create a quote record, set the pricebook, and add a quote line item. Everything works except getting the ID of the quote created so I can create the line under it (meaning that I can give it a static ID and it'll work). I highlited what I'm looking to fix in Bold (It's after the = sign). Please help me :)

{!REQUIRESCRIPT('/soap/ajax/34.0/connection.js')} 

var RecID = '{!Opportunity.RecordTypeId}'; 
var pricebookid = "01s60000000AaPr"; 
var newQuote = new sforce.SObject('Quote'); 

var CreateHeader = []; 

if (RecID == "01232000000Q897" || RecID == "012320000005P5G" || RecID == "012600000009XZ6") 

newQuote.RecordTypeId = '01232000000JOUt'; 


newQuote.Name = 'Proposal - {!Today}'; 
newQuote.OpportunityId = '{!Opportunity.Id}'; 
newQuote.Pricebook2Id = pricebookid; 

CreateHeader.push(newQuote) 

result = sforce.connection.create(CreateHeader); 

var CreateLines=[]; 

var linky=new sforce.SObject("QuoteLineItem"); 
linky.QuoteID = result[0].Id
linky.PriceBookEntryId = '01u6000000AQn3TAAT'; 
linky.Quantity = 1; 
linky.UnitPrice = 1; 
linky.Description = 'Add-On - FMA'; 
CreateLines.push(linky); 

result=sforce.connection.create(CreateLines); 


window.location.reload();
  • May 07, 2018
  • Like
  • 0
Hello all, I created this button on the Quote object to create QuoteLineItems but it's not working. Below is the code BUT please see my note below the code for some clarification:

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} 

var pricebookid = "01s60000000AaPr"; 
var quoteId = "{!Quote.Id}"; 
var quoteQuery = sforce.connection.query("Select Id, Name FROM Quote WHERE Id='" + quoteId + "'"); 
var quotyResult = quoteQuery.getArray("records"); 
quotyResult[0].Pricebook2Id = pricebookid; 
var updatequotyResult = sforce.connection.update([quotyResult[0]]); 


var result = sforce.connection.query("Select Id,Name,HE__c,HE_Qauntity__c,Price_Book_Entry_ID__c From Product2 Where HE__c = TRUE"); 
var records = result.getArray("records"); 

var CreateRecords=[]; 

if(records[0]==null) 
alert('No Product Set is Retrieved!'); 
for(var i=0;i<records.length;i++) 

var linky=new sforce.SObject("QuoteLineItem"); 
linky.QuoteID = '{!Quote.Id}'; 
linky.PriceBookEntryId = records[i].Price_Book_Entry_ID__c; 
linky.Quantity = records[i].HE_Qauntity__c; 
linky.UnitPrice = 1; 
linky.Quoting_Tool__c = 1; 
CreateRecords.push(linky); 


result=sforce.connection.create([CreateRecords]); 
alert(result); 


window.location.reload();


// The code works fine if I create them one by one within the loop but I wanted to create them at once from an array. For example, if I put 

result=sforce.connection.create([linky]);

in the loop it works fine but slow. That's whay I wanted to go the other way around to create them at once from an array. Please help. 
  • June 12, 2017
  • Like
  • 0
Hi there,

I wrote a a trigger to add a product to the opportunity, it works fine but I'm stuck at the test class which is giving me low code coverage, I need help with the test class. Please see the trigger/test class below, thanks in advance.

trigger AddOppLines on Opportunity (after update,after insert) 
{
    List<OpportunityLineItem> OppLineItems = new List<OpportunityLineItem>();
    for (Opportunity newOpp: Trigger.New) 
    {
            
            Integer C110013 = 1;
            
            for(PriceBookEntry a : [SELECT Id, ProductCode FROM PriceBookEntry WHERE PriceBook2.Name='Bulk TV 1'])
            {
                if (a.ProductCode == '110013' && C110013 > 0)
                {
                    OppLineItems.add(new OpportunityLineItem(OpportunityId = newOpp.Id,PricebookEntryId = a.Id,Quantity = C110013, UnitPrice = 0,Auto__c = TRUE));
                }
            }   
    }
    insert OppLineItems;
}


---------------------------------------------------------------------------------------------------------------------------------------------------------------


@isTest 
private class AddOppLinesTestClass 
{
    static testMethod void validateAddOppLines() 
    {
    
        PriceBook2 pb = new PriceBook2(Name='Bulk TV 1',IsActive=true);
        insert pb;
        
        Product2 p = new Product2(Name='TrigTest',IsActive=TRUE,ProductCode='110013',Description='TriggerTest');
        insert p;
        
        PricebookEntry pbe = new PricebookEntry(Product2Id = p.Id,PriceBook2Id = pb.Id,IsActive = true,UnitPrice = 20.00);
        
        Opportunity b = new Opportunity(Name='Test 1',StageName='New',CloseDate=Date.today());
        insert b;
    }
}
  • February 03, 2015
  • Like
  • 0

Hello experts :) I created the following APEX Class in my Dev Org:

 

@RestResource(urlMapping='/createCase/*')
global with sharing class RESTCaseController 
{

@HttpPost  
global static Void createNewCase()
{
Case c = new Case();
c.OwnerId = '005i0000001uqEm';
c.AccountId = '001i000000RsOOS';
c.Subject = 'SOAP Test';
c.Status = 'New';
insert c;
return;
}

}

 

 

So the endpoint URL is https://na15.salesforce.com/services/apexrest/FieldCase

 

There will be a a third party application that will send SOAP messages to that end point.


I would like to test it and see if it'll create a case for me :) Any help is much apreciated (By the way, I'm new to this so bare with me :) )

  • October 24, 2013
  • Like
  • 0

Hello all,

 

I have very little experience with this so please bare with me and be clear :)

 

We have an external system that sends out SOAP messages when an issue occurs. The goal is to catch those messages and create a case out of them. I would like to know how to do that in steps please. Any help is helpful :) Take care and please let me know if you need additional information.

  • October 22, 2013
  • Like
  • 0

Hello all, this is my first post here :) I'm writing an APEX Trigger that is supposed to create a Product Line Item when an opportunity is created. Here is what I did:

 

trigger AutoCreateInterviewer on Opportunity (after insert) {
List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>();
for (Opportunity newOpportunity: Trigger.New) {
if (newOpportunity.of_HD_Channels__c != null) {
OpportunityLineItems.add(new OpportunityLineItem(ProductId = '01t60000004Inzu',Opportunity = newOpportunity.Id,Quantity = 3,UnitPrice = 50));
}
}
insert OpportunityLineItems;

 

but it's not working, it gives me the following error:

 

Error: Compile Error: Invalid field ProductId for SObject OpportunityLineItem at line 5 column 74

 


Could you kindly tell me what the right syntaz is for what I need? Thanks in advance

 

My issue is with the arguments I'm passing, mainly the ProductId and the Opportunity I think because it saves fine without them there, please help :(

  • June 28, 2013
  • Like
  • 0