• Alex Lazarev
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
Hello guys, I'm trying to migrate an Obj with a field that has a Global ValueSet. 

The Obj, the field, and the global valueset is listed and exported in the metadata but its giving me the next error when I try to push it to the destination org:
 
Error: Cannot set picklist values when a global picklist is referenced on the field

 
Hello guys,

Continuing with my trials of solving the problematic with initial skills of apex development I have the next problematic:

I'm trying to get Sales__c Id with status 'Sold', with the Sale Id check inside the Order_Item__c that belongs to the Sale values Vehicle_Name__c,Item_Quantity__c.

Then search by Vehicle_Name__c inside Vehicle__c and check if Vehicle__c.Quantity__c <= Order_Item__c.Item_Quantity__c

This is what I managed to do so far but its not working and I have no clue on how to continue.

Could someone help me please with the code?
 
trigger SaleCheckout on Sales__c (before update) {
    
    //Map<Id,Sales__c> salesSold = new Map<Id,Sales__c>([SELECT Id FROM Sales__c WHERE Sale_Satus__c = 'Sold']);
    List<Sales__c> sale = [SELECT Id FROM Sales__c WHERE Sale_Satus__c = 'Sold'];
    System.debug(' List<Sales__c> salesSold = ' + sale);
    
    Set<String> s = New Set<String>();
    for(Sales__c sales : sale) {
        s.add(sales.Id);
    }
     
    Map<Id,Order_Item__c> orders = new Map<Id,Order_Item__c>([SELECT Id,Vehicle_Name__c,Item_Quantity__c FROM Order_Item__c WHERE Sale__c  IN : s.Id]);


}

 
Hello guys,

I'm doing a Trigger, but since I have short experience I need some help please. I have the following Trigger that shoots when there is an attemp of insert into the custom Object. This works fine for a new record. But the logic that I'm missing is for bulk of Inserts where my Company told me that we should take the SELECT out of the loop and first build a list of the IDs and then run a single query with
IN : varibleWithIds

Here is my piece of code, how can I take the queries out of the 'for' statement and do a single 'SELECT' for the List of ids??
 
trigger AddOnlyVehiclesInStock on Order_Item__c (before insert) {
    
    // String to storage vehicle type
    Set<String> orderVehicle = 	New Set<String>();
    
    // Going through the Order_Item__c object to assign the field data to the variable orderVehicle
    for(Order_Item__c o : Trigger.New){
        orderVehicle.add(o.Vehicle_Type__c);
        
        System.debug('1-- Order_Item__c.Vehicle_Type__c: ' + orderVehicle);	
        
        	// Getting Name and quantity of the searched vehicle -- This should get the List of IDs and not loop inside a FOR
            List<Vehicle__c> v = [SELECT Name,Quantity__c FROM Vehicle__c Where Name IN : orderVehicle];
            for(Vehicle__c ve : v){
                System.debug('2-- Vehicle query debug: ' + ve);
                
                // If the vehicle that we are trying to add to the order has less than 1 in stock
                // then we cannot add it.
                System.debug('3-- Vehicle quatity: ' + ve.Quantity__c);
                
                if(ve.Quantity__c < 1){
                    o.addError('Cannot add to order vehicles without stock');
                }
            }
    }
}

Thank you!
Hello guys,

Continuing with my trials of solving the problematic with initial skills of apex development I have the next problematic:

I'm trying to get Sales__c Id with status 'Sold', with the Sale Id check inside the Order_Item__c that belongs to the Sale values Vehicle_Name__c,Item_Quantity__c.

Then search by Vehicle_Name__c inside Vehicle__c and check if Vehicle__c.Quantity__c <= Order_Item__c.Item_Quantity__c

This is what I managed to do so far but its not working and I have no clue on how to continue.

Could someone help me please with the code?
 
trigger SaleCheckout on Sales__c (before update) {
    
    //Map<Id,Sales__c> salesSold = new Map<Id,Sales__c>([SELECT Id FROM Sales__c WHERE Sale_Satus__c = 'Sold']);
    List<Sales__c> sale = [SELECT Id FROM Sales__c WHERE Sale_Satus__c = 'Sold'];
    System.debug(' List<Sales__c> salesSold = ' + sale);
    
    Set<String> s = New Set<String>();
    for(Sales__c sales : sale) {
        s.add(sales.Id);
    }
     
    Map<Id,Order_Item__c> orders = new Map<Id,Order_Item__c>([SELECT Id,Vehicle_Name__c,Item_Quantity__c FROM Order_Item__c WHERE Sale__c  IN : s.Id]);


}

 
Hello guys,

I'm doing a Trigger, but since I have short experience I need some help please. I have the following Trigger that shoots when there is an attemp of insert into the custom Object. This works fine for a new record. But the logic that I'm missing is for bulk of Inserts where my Company told me that we should take the SELECT out of the loop and first build a list of the IDs and then run a single query with
IN : varibleWithIds

Here is my piece of code, how can I take the queries out of the 'for' statement and do a single 'SELECT' for the List of ids??
 
trigger AddOnlyVehiclesInStock on Order_Item__c (before insert) {
    
    // String to storage vehicle type
    Set<String> orderVehicle = 	New Set<String>();
    
    // Going through the Order_Item__c object to assign the field data to the variable orderVehicle
    for(Order_Item__c o : Trigger.New){
        orderVehicle.add(o.Vehicle_Type__c);
        
        System.debug('1-- Order_Item__c.Vehicle_Type__c: ' + orderVehicle);	
        
        	// Getting Name and quantity of the searched vehicle -- This should get the List of IDs and not loop inside a FOR
            List<Vehicle__c> v = [SELECT Name,Quantity__c FROM Vehicle__c Where Name IN : orderVehicle];
            for(Vehicle__c ve : v){
                System.debug('2-- Vehicle query debug: ' + ve);
                
                // If the vehicle that we are trying to add to the order has less than 1 in stock
                // then we cannot add it.
                System.debug('3-- Vehicle quatity: ' + ve.Quantity__c);
                
                if(ve.Quantity__c < 1){
                    o.addError('Cannot add to order vehicles without stock');
                }
            }
    }
}

Thank you!