• Victor P
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 5
    Replies
Hi all,

I ran the test class and I get 0% code coverage and an error only when running the test. The trigger works perfectly fine in the sandbox.
Can someone point me in the right direction? 

The triggers loops through all Products in an Opportunity and concatenates all Products in one custom field created in the Opportunity Object.
 
trigger OpportunityConcat on Opportunity (before insert, before update) {

list<opportunity> oppt = trigger.new; 

public static String isEmptyString(String inputString) 
{ 
String str = String.isBlank(inputString)?'': inputString;
return str;
}

if ( trigger.isInsert || trigger.isUpdate){
list<opportunityLineItem> soli = new list<opportunityLineItem>([select id ,opportunityId, opportunity.name, product2.name,Purchase_Order__c, (select id from opportunitylineitemschedules ORDER BY ScheduleDate ASC), Description__c from opportunitylineitem where opportunityId =: trigger.new[0].id]); 
string allProducts='';
if (soli != null && soli.size()>0){
for(opportunityLineItem opp : soli){
 allProducts += opp.id +','+ opp.opportunityid +','+ isEmptyString(opp.opportunity.name) +','+ isEmptyString(opp.product2.name) +','+ isEmptyString(opp.Purchase_Order__c) +','+ isEmptyString(opp.Description__c ) +','+ opp.opportunitylineitemschedules[0].id +'\n';
}

for(Opportunity opp : trigger.new){
 opp.ConcatProd__c = allProducts;
}
}
else
{
for(Opportunity opp : trigger.new){
opp.ConcatProd__c = '';
}
}
}
}



 
I'm trying to create a quick function that I can reuse throughout the code that replaces a null value with an empty space.

Here's how I do it at the moment:
String.isBlank(opportunity.details__c)? '' : opportunity.details__c)
I need to reuse this a lot throughout the code so something simple like
CheckForNull(opportunity.details__c) would be easier.

Here's my poor attempt:
 
function CheckForNull (search) {
var checked = String.isBlank(search)? '' : search)
return checked;
}


 
I have a trigger on the Opportunity object that concatenates all Products (OpportunityLineItem) within an Opportunity. I'm trying to also look at the OpportunityLineItemSchedule which is a child of OpportunityLineItem within the same SOQL. 

I am unable to choose a specific child from OpportunityLineItemSchedule.
For example, I'd like to see all Products from Opportunity A where the scheduledate from the opportunitylineitemschedule is the earliest (first installment). 
 
trigger concatenateProd on Opportunity (before insert, before update) {

list<opportunity> sl = trigger.new;
list<opportunityLineItem> slnu = new list<opportunityLineItem>([select id ,opportunityId, opportunity.name, Product_Family__c, (select Revenue from opportunitylineitemschedules where OpportunityLineItemId =: ??this.opportunitylineitem?? ORDER BY ScheduleDate ASC LIMIT 1) from opportunitylineitem where opportunityId =: trigger.new[0].id]);
 
string productName='';
for(opportunityLineItem opp : slnu){
 productName += opp.id +'||'+ opp.opportunityid +'||'+ opp.opportunity.name +'||'+ ???opp.opportunitylineitemschedules.Revenue??? +'\n'; 
}
for(Opportunity opp : trigger.new){
 opp.Concatenate_Prod__c = productName;
}
}
I get an error saying:
"Error: Compile Error: A non foreign key field cannot be referenced in a path expression: OpportunityLineItemSchedules at line 8"
Hi all,

I wrote a trigger that should write the Installment ID (OpportunityLineItemSchedule.Id)  in the OpportunityLineItem object custom field called "First_Install_Id__c"

I'm not sure what's missing here. I get no errors but the field remains empty.
 
trigger OpportunityFirstInstall on OpportunityLineItem (before insert, before update, before delete)

{
list<opportunitylineitem> sl = trigger.new;
list<opportunityLineItemSchedule> slnu = new list<opportunityLineItemSchedule>([select id from opportunitylineitemschedule where OpportunityLineItemId =: trigger.new[0].id ORDER BY ScheduleDate ASC LIMIT 1]);
 
string firstintstall='';
for(opportunityLineItemSchedule opp : slnu){
 firstintstall = opp.id;
}
for(OpportunityLineItem opp : trigger.new){
 opp.First_Install_Id__c = firstintstall;
}
}

 
Hi all,

I'm trying to create a trigger on the Opportunity object to write all Products of said Opportunity in a custom field.

I found how to do this in an Apex class but it looks like Apex triggers are using a different language? 
 
trigger OpportunityConcatenation on Opportunity (before insert, before update, after insert, after update, before delete)

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

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);
}
opp.Samples_Sent__c = strProductNames;

sforce.connection.update([opp]);
}

 
Hi, 
I'm attempting to authenticate a GET request in Zapier. Salesforce doesn't support basic authentication and even if it would I'd rather not use it as it's not secure.

Is there a way to attach an authentication token directly in the URL request or in the header?

I've heard about Named Credentials but I'm not sure I'm able to pass that in the URL.

Here are the options I see in Zapier:
User-added image
Trying to acess the first date from a Revenue Schedule and use it to read and write to it via the API.
I'm trying to access the date and the Schedule ID of the first date (date1) from the "Schedule Date" object in the OpportunityLineItemSchedule.

But I'm not sure how to create this in order for it to be accesible via the API. 
How can I execute this? Is it necesary to create a custom field via the setup and then write to it via apex code?

Few things I've tried. 

The SOQL query to do this is:
SELECT Id, ScheduleDate, OpportunityLineItem.Id FROM OpportunityLineItemSchedule ORDER BY OpportunityLineItem.Id DESC, ScheduleDate DESC

The code for this would be something similar to this:
List<OpportunityLineItemSchedule> lineSchedules = [select Id from OpportunityLineItemSchedule where OpportunityLineItemId = :lineItems[0].id 

I appreciate your help!

 
Hi, 
I'm attempting to authenticate a GET request in Zapier. Salesforce doesn't support basic authentication and even if it would I'd rather not use it as it's not secure.

Is there a way to attach an authentication token directly in the URL request or in the header?

I've heard about Named Credentials but I'm not sure I'm able to pass that in the URL.

Here are the options I see in Zapier:
User-added image
Hi all,

I ran the test class and I get 0% code coverage and an error only when running the test. The trigger works perfectly fine in the sandbox.
Can someone point me in the right direction? 

The triggers loops through all Products in an Opportunity and concatenates all Products in one custom field created in the Opportunity Object.
 
trigger OpportunityConcat on Opportunity (before insert, before update) {

list<opportunity> oppt = trigger.new; 

public static String isEmptyString(String inputString) 
{ 
String str = String.isBlank(inputString)?'': inputString;
return str;
}

if ( trigger.isInsert || trigger.isUpdate){
list<opportunityLineItem> soli = new list<opportunityLineItem>([select id ,opportunityId, opportunity.name, product2.name,Purchase_Order__c, (select id from opportunitylineitemschedules ORDER BY ScheduleDate ASC), Description__c from opportunitylineitem where opportunityId =: trigger.new[0].id]); 
string allProducts='';
if (soli != null && soli.size()>0){
for(opportunityLineItem opp : soli){
 allProducts += opp.id +','+ opp.opportunityid +','+ isEmptyString(opp.opportunity.name) +','+ isEmptyString(opp.product2.name) +','+ isEmptyString(opp.Purchase_Order__c) +','+ isEmptyString(opp.Description__c ) +','+ opp.opportunitylineitemschedules[0].id +'\n';
}

for(Opportunity opp : trigger.new){
 opp.ConcatProd__c = allProducts;
}
}
else
{
for(Opportunity opp : trigger.new){
opp.ConcatProd__c = '';
}
}
}
}



 
I'm trying to create a quick function that I can reuse throughout the code that replaces a null value with an empty space.

Here's how I do it at the moment:
String.isBlank(opportunity.details__c)? '' : opportunity.details__c)
I need to reuse this a lot throughout the code so something simple like
CheckForNull(opportunity.details__c) would be easier.

Here's my poor attempt:
 
function CheckForNull (search) {
var checked = String.isBlank(search)? '' : search)
return checked;
}


 
I have a trigger on the Opportunity object that concatenates all Products (OpportunityLineItem) within an Opportunity. I'm trying to also look at the OpportunityLineItemSchedule which is a child of OpportunityLineItem within the same SOQL. 

I am unable to choose a specific child from OpportunityLineItemSchedule.
For example, I'd like to see all Products from Opportunity A where the scheduledate from the opportunitylineitemschedule is the earliest (first installment). 
 
trigger concatenateProd on Opportunity (before insert, before update) {

list<opportunity> sl = trigger.new;
list<opportunityLineItem> slnu = new list<opportunityLineItem>([select id ,opportunityId, opportunity.name, Product_Family__c, (select Revenue from opportunitylineitemschedules where OpportunityLineItemId =: ??this.opportunitylineitem?? ORDER BY ScheduleDate ASC LIMIT 1) from opportunitylineitem where opportunityId =: trigger.new[0].id]);
 
string productName='';
for(opportunityLineItem opp : slnu){
 productName += opp.id +'||'+ opp.opportunityid +'||'+ opp.opportunity.name +'||'+ ???opp.opportunitylineitemschedules.Revenue??? +'\n'; 
}
for(Opportunity opp : trigger.new){
 opp.Concatenate_Prod__c = productName;
}
}
I get an error saying:
"Error: Compile Error: A non foreign key field cannot be referenced in a path expression: OpportunityLineItemSchedules at line 8"
Hi all,

I'm trying to create a trigger on the Opportunity object to write all Products of said Opportunity in a custom field.

I found how to do this in an Apex class but it looks like Apex triggers are using a different language? 
 
trigger OpportunityConcatenation on Opportunity (before insert, before update, after insert, after update, before delete)

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

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);
}
opp.Samples_Sent__c = strProductNames;

sforce.connection.update([opp]);
}