• iaesteman
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 10
    Replies

Hello,

I am trying to retrieve all Order Items with a lightning component that will be shown on the Account. But before that I want to explain my structure.
I have product bundles that have object bundle_line_items__c. There is a lookup field inside that connects the bundle_name__c(bundle) and bundle_child__c sub products.
Looks like this.

User-added image
So when I list the product bundle it has his own bundle_line_items in it.

Now, when i want to add that bundle to an order/Order Product i can do it easly. Showing the bundle line items is a bit hard, and that is what exactly i want to achieve.

I created a component with the code below that somehow i can get the order products and the bundle line items in that product to be visible for the sales guy. But code doesn't work and i don't know where i am making a mistake :(

apex class: 

public class MyOrdersListController {
@AuraEnabled
public static List<Order> getOrders(Id recordId) {
   return [select id from order Where AccountId = :recordId];
}
}
ProductOrdersComponent
ProductOrdersComponent.cmp
<aura:component controller="MyOrdersListController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="Account" type="Account" />
<aura:attribute name="Order" type="Order" />
<aura:attribute name="Columns" type="List" />
<aura:handler name="init" value="{!this}" action="{!c.myAction}" />
<force:recordData aura:id="accountRecord"
                  recordId="{!v.recordId}"
                  targetFields="{!v.Account}"
                  layoutType="FULL"
                  />
<lightning:card iconName="standard:contact" title="{! 'Order List for ' + v.Account.Name}">
<lightning:datatable data="{! v.Orders }" columns="{! v.Orders }" keyField="Id" hideCheckboxColumn="true"/>
</lightning:card>
</aura:component>
ProductOrdersComponent.js
({
	myAction : function(component, event, helper) {
        component.set("v.Orders", [
            {label:"id", fieldName:"Id", type:"text"}
        ]);

        var action = component.get("c.getOrders");
        action.setParams({
            recordId: component.get("v.recordId")
        });
        action.setCallback(this, function(data) {
            component.set("v.Orders", data.getReturnValue());
        });
        $A.enqueueAction(action);
	}
})


What I am missing? Any help will be highly appreciated.

The component should be shown on the account image below.
User-added image

with possible Nested Tree like in the link:

https://developer.salesforce.com/docs/component-library/bundle/lightning:tree/example#lightningcomponentdemo:exampleTreeWithMetatext

Thanks,

Darko

Hello,
I am trying to test the time that will be needed to be created more than 90000 records in salesforce with apex code. I need this so i can prove my boss that this is not a best way to run things.
Why we need this?
We basically want to create available time frames for every course so that people can book a time and play on that course.
For example for one day the available time is from 6am to 6pm and every 5 minutes i need to create records to create those time frames. 
More into details:
1 day has 12 hours(6am to 6pm) in 1 hour there are 12 records so for 1 day i will need to create 144 records with this apex code and i need to do that for a specific month(lets say June 2019).  Total: 144 x 31 = 4464 records.

This is my code that I did so far and run into developer console and i defintiely need improvments if anyone can help i will be eternaly grateful!
 
List<Courses__c> course =[select id from courses__c]; 
List<Available_Time__c> cList = new List<Available_Time__c>(); 
for(Courses__c i: course){ 
for(Integer j=0;i<2;i++){ 
Available_Time__c cust = new Available_Time__c(); 
cust.Course__c = 'a0C0D000000Q7qbUAC'; 
} 
}
insert cList;

Thanks,
Darko

Hello,

I am new with apex triggers and I need some assistance. I tried to create a trigger that will provide me with PricebookID and Price to be populated from other fields like Bundle_Child__c and Bundle_Child_Fabric_1__c and Bundle_Child_Fabric_2__c.
So when I insert a Bundle_Child__c(lookup field) with a product value and Price_Book__c (lookup field) with a pricebook i want the Bundle_Child_PB_UnitPRice to be populated with the UnitPrice of that product and the Bundle_Child_PB_ID to be populated with the PricebookentryID field. Also I want to do the same with the Bundle_Child_Fabric_1__c and Bundle_Child_Fabric_2__c fields(lookup fields) to update the values for the Bundle_Child_Fabric_1PB_ID__c and Bundle_Child_Fabric_1PB_ID__c . I am doing this so I can get the exact price from all those products.

This is my code so far. I can't get to work with one. Also I am trying to check if there is a pricebook entry inside if not create it without pricebook. This combination needs to go for all fields if its empty to create it without it.

 

trigger setPricebookEntryID on Bundle_Line_Item__c (before update) { 
    Set<Id> setPriceBookId = new Set<Id>();
    Map<Id,PricebookEntry> mapPriceBookIdToPBE = new Map<Id,PricebookEntry>();
    for (Bundle_Line_Item__c p : Trigger.new) { 
        if (p.Price_Book__c != null) {
            setPriceBookId.add(p.Price_Book__c);    
        }
    }
    if (!setPriceBookId.isEmpty()) {
        for (PricebookEntry pbe : [SELECT Id, UnitPrice, Pricebook2Id 
                    FROM PricebookEntry
                    WHERE Pricebook2Id IN: setPriceBookId]) {
             mapPriceBookIdToPBE.put(pbe.Pricebook2Id, pbe);
        } 
        for (Bundle_Line_Item__c p : Trigger.new) {
            if (mapPriceBookIdToPBE.containskey(p.Price_Book__c) && mapPriceBookIdToPBE.get(p.Price_Book__c).Product2Id == p.Bundle_Child__c) {
                p.Bundle_Child_PB_ID__c= mapPriceBookIdToPBE.get(p.Price_Book__c).Id;
                p.Bundle_Child_PB_UnitPRice__c = mapPriceBookIdToPBE.get(p.Price_Book__c).UnitPrice;
            }
        }             
    }  
}

This is the error I am getting so far.

 

Error:Apex trigger setPricebookEntryID caused an unexpected exception, contact your administrator: setPricebookEntryID: execution of BeforeUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: PricebookEntry.Product2Id: Trigger.setPricebookEntryID: line 29, column 1


Any advices?

Thanks,

Darko

I am new with triggers and I am trying to achieve the following. Every time a BundlePrice field is inserted or updated it should automatically update the standard price with that info according the exchange rate.
This is the trigger that I made.

 

trigger UpdateStandardPrices on Product2 (after insert, after update) {

//Update the Standard price in all currencies from the Cost price on the Product. Cost Price is always in SEK
//Create a PriceBookEntry if it's a new Product

System.Debug('USP TRIGGER');

//This trigger will cause recursion if it's not stopped. 
//The TriggerMonitor class is static, and remains for the lifetime of the insert/update
//This prevents recursion.
//string TriggerName = 'UpdateStandardPrices';
if (TriggerMonitor.runOnce())
{       
    //TriggerMonitor.ExecutedTriggers.add(TriggerName);


    // GET ALL DATA //
    Id PriceBookId = [SELECT Id From Pricebook2 WHERE IsStandard=TRUE].Id;                                                          //Get the ID of the Standard Price Book
    list<CurrencyType> ActiveCurrencies = [SELECT ISOCode, ConversionRate FROM CurrencyType WHERE IsActive=TRUE];                   //Get a list of all active currencies
    list<Product2> Products = new List<Product2>([SELECT Id, Bundle_Price__c, CurrencyIsoCode FROM Product2 WHERE Id in :Trigger.new]);  //Get a list of all new entries
    list<PricebookEntry> resultList = new list<PricebookEntry>();                                                                   //List to populate and update

    for( Product2 product : Products)
    {

        list<PricebookEntry> loopList = new list<PricebookEntry>([Select Id, CurrencyISOCode FROM PricebookEntry WHERE PricebookEntry.Product2Id =: product.Id]); //Get a list of all entries in the Standard Price Book for the product id

        for(CurrencyType c : ActiveCurrencies)
        {

            integer currencyExists = 0;                 //Reset the currency exists flag
            PricebookEntry price = new PricebookEntry();

            for(PricebookEntry l : loopList)        
            {                                           //Is there already an entry in the currency
                if(l.CurrencyIsoCode == c.IsoCode)
                    currencyExists = 1;
            }


            if(currencyExists == 0)
            {                                           //Does not exist in this currency: Insert new StandardPrice

                price.UnitPrice = product.Bundle_Price__c * c.ConversionRate; 
                price.Product2Id = product.Id;
                price.CurrencyISOCode = c.IsoCode;
                price.Pricebook2Id = PriceBookId;
                price.IsActive = TRUE;
                insert price;
            }
            else
            {                                           //Exist in this currency: Update with new StandardPrice
                for(PricebookEntry l : loopList)        
                {                                       //Loop through to find the unique Id for the PricebookEntry

                    if(l.CurrencyIsoCode == c.IsoCode)
                        price.Id = l.Id;
                }

                price.UnitPrice = product.Bundle_Price__c* c.ConversionRate;
                price.IsActive = TRUE;
                resultList.add(price);
            }
        }

    }
    update resultList;
}


What the trigger does is checks currencies check rate and add them to the standard price. But when i test it, it change the price to all currencies the same and ignores the rate. I need to edit the product so the rates will get changed. What I am doing wrong?
Additionally how can I update the trigger to check the PricebookId(sweden) that I have and add the corresponding Standardprice(SEK) to the Swedish price-book.
Any help to reach this mission will be highly appreciated.

 

Thanks, Darko

Hi,

I have 3 fields on one product family called Furniture

User-added image
 

  • Fab.Req m(130) : 4.3
  • Fab.Req m(140) : 4.0
  • Fab.Req m(150) : 4.0
and I have a field on different product family called Fabric
  • Fabric Width: 140

What I want to do is compare the field Fabric Width with the 3 other fields labels and based on that label the defined value to be showned.

How can i achieve this ? Is it possible to do it with a formula?

Thanks,

Darko

Hi,
Is it possible to make a sales path in opportunity where you can add products directly to the quote. For example let say you have a path where you specify the discount and other things in the opportunity in the first stage on the second stage you have a product that you want to add that is furniture on the third stage you have a product that you want to add that is fabric and on the third stage you have product that you want to add that is leggings. See below
User-added image

Is there a way when i go through the stages to add the products and also be added in the quote. I want to do this so i can speed up my sales process.

Cheers

I am new with triggers and I am trying to achieve the following. Every time a BundlePrice field is inserted or updated it should automatically update the standard price with that info according the exchange rate.
This is the trigger that I made.

 

trigger UpdateStandardPrices on Product2 (after insert, after update) {

//Update the Standard price in all currencies from the Cost price on the Product. Cost Price is always in SEK
//Create a PriceBookEntry if it's a new Product

System.Debug('USP TRIGGER');

//This trigger will cause recursion if it's not stopped. 
//The TriggerMonitor class is static, and remains for the lifetime of the insert/update
//This prevents recursion.
//string TriggerName = 'UpdateStandardPrices';
if (TriggerMonitor.runOnce())
{       
    //TriggerMonitor.ExecutedTriggers.add(TriggerName);


    // GET ALL DATA //
    Id PriceBookId = [SELECT Id From Pricebook2 WHERE IsStandard=TRUE].Id;                                                          //Get the ID of the Standard Price Book
    list<CurrencyType> ActiveCurrencies = [SELECT ISOCode, ConversionRate FROM CurrencyType WHERE IsActive=TRUE];                   //Get a list of all active currencies
    list<Product2> Products = new List<Product2>([SELECT Id, Bundle_Price__c, CurrencyIsoCode FROM Product2 WHERE Id in :Trigger.new]);  //Get a list of all new entries
    list<PricebookEntry> resultList = new list<PricebookEntry>();                                                                   //List to populate and update

    for( Product2 product : Products)
    {

        list<PricebookEntry> loopList = new list<PricebookEntry>([Select Id, CurrencyISOCode FROM PricebookEntry WHERE PricebookEntry.Product2Id =: product.Id]); //Get a list of all entries in the Standard Price Book for the product id

        for(CurrencyType c : ActiveCurrencies)
        {

            integer currencyExists = 0;                 //Reset the currency exists flag
            PricebookEntry price = new PricebookEntry();

            for(PricebookEntry l : loopList)        
            {                                           //Is there already an entry in the currency
                if(l.CurrencyIsoCode == c.IsoCode)
                    currencyExists = 1;
            }


            if(currencyExists == 0)
            {                                           //Does not exist in this currency: Insert new StandardPrice

                price.UnitPrice = product.Bundle_Price__c * c.ConversionRate; 
                price.Product2Id = product.Id;
                price.CurrencyISOCode = c.IsoCode;
                price.Pricebook2Id = PriceBookId;
                price.IsActive = TRUE;
                insert price;
            }
            else
            {                                           //Exist in this currency: Update with new StandardPrice
                for(PricebookEntry l : loopList)        
                {                                       //Loop through to find the unique Id for the PricebookEntry

                    if(l.CurrencyIsoCode == c.IsoCode)
                        price.Id = l.Id;
                }

                price.UnitPrice = product.Bundle_Price__c* c.ConversionRate;
                price.IsActive = TRUE;
                resultList.add(price);
            }
        }

    }
    update resultList;
}


What the trigger does is checks currencies check rate and add them to the standard price. But when i test it, it change the price to all currencies the same and ignores the rate. I need to edit the product so the rates will get changed. What I am doing wrong?
Additionally how can I update the trigger to check the PricebookId(sweden) that I have and add the corresponding Standardprice(SEK) to the Swedish price-book.
Any help to reach this mission will be highly appreciated.

 

Thanks, Darko

Hi,

I have 3 fields on one product family called Furniture

User-added image
 

  • Fab.Req m(130) : 4.3
  • Fab.Req m(140) : 4.0
  • Fab.Req m(150) : 4.0
and I have a field on different product family called Fabric
  • Fabric Width: 140

What I want to do is compare the field Fabric Width with the 3 other fields labels and based on that label the defined value to be showned.

How can i achieve this ? Is it possible to do it with a formula?

Thanks,

Darko

I can't find Dev Hub in my org's Setup search.
We are synchronizing products from an external system. We provide a price in a custom field (cost__c) and also the currency.

To be able to import pricelists in all currencies (we create one price list per sales channel), SalesForce requires that the price must exist in the same currency in the Standard Price List.

So - I'd like to do the following:
Whenever a product is added / updated - take the value in cost__c and the currency on the product. Create an entry for every currency in the list of active currencies in the Standard Price List.
  • November 01, 2016
  • Like
  • 0