• Vladimir Bessonov
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 59
    Questions
  • 39
    Replies
I am trying to solve the puzzle how to avoid CPU time error

my code is below. 
on the internet a lot of recommendations and examples with maps. 
But I am creating new records and need to iterate over quantities to create records. 

so what I shall do? 
 
public with sharing class BatchCreateNonSerializedParts implements Database.Batchable<sObject> {
    String ProjectConfigID;
    String ProjectID;
    Integer VehicleFleetStartNumber;
    ComponentProjectConfiguration__c ProjectConfig;

    List<NonSerializedPart__c> NonSerPartsConfig;
    List<project_Non_Serialized_Part__c> NonSerParts = new List<project_Non_Serialized_Part__c>();
    List<Acceptance__c> NonSerPartAcceptances = new List<Acceptance__c>();  


    public BatchCreateNonSerializedParts(String ProjectConfigID, String ProjectID) {
        this.ProjectConfigID = ProjectConfigID;
        this.ProjectID = ProjectID;

        ProjectConfig = [Select ID, Name, Vehicle_fleet_start_number__c from ComponentProjectConfiguration__c where ID =: ProjectConfigID];
        VehicleFleetStartNumber = Integer.valueOf(ProjectConfig.Vehicle_fleet_start_number__c);

        NonSerPartsConfig = [Select ID, Name, Number_of_units__c, Quantity__c, Unit_of_measurement__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from NonSerializedPart__c where Project__c =: ProjectConfigID];
        

        for (NonSerializedPart__c part : NonSerPartsConfig) {
        Double Total = part.Number_of_units__c * part.Quantity__c;
        project_Non_Serialized_Part__c NewPart = New project_Non_Serialized_Part__c(Name = part.Name, Project__c =ProjectID,
        Material_Number__c = part.Material_Number__c, Supplier__c = part.Supplier__c, 
        Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
        Total_Quantity__c = Total ,Unit_of_measurement__c = part.Unit_of_measurement__c,
        Number_of_units__c = part.Number_of_units__c, unit_Quantity__c = part.Quantity__c);

        NonSerParts.add(NewPart);
        
        }
       // insert NonSerParts; 

        Database.SaveResult[] srList = Database.insert(NonSerParts, false);
            
        // Iterate through each returned result
        for (Database.SaveResult sr : srList) {
            if (sr.isSuccess()) {
                // Operation was successful, so get the ID of the record that was processed
                System.debug('Successfully inserted NonPartsSets: ');
            }
            else {
                // Operation failed, so get all errors                
                for(Database.Error err : sr.getErrors()) {
                    System.debug('The following error has occurred.');                    
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                    System.debug('NonPartsSets fields that affected this error: ' + err.getFields());
                }

                return;
            }
        }

     // Create Acceptance object    

        for(project_Non_Serialized_Part__c part : NonSerParts){ 
                
            for(Integer i=0;i<part.Number_of_units__c;i++){
                    Acceptance__c newAcceptance = new Acceptance__c(Non_Serialized_Part__c = part.id, Quantity__c = part.unit_Quantity__c,
                    Unit_of_measurement__c = part.Unit_of_measurement__c, Acceptance_Non_Serialized_Part__c = part.Name, Status__c = 'NOT SENT');  
                    NonSerPartAcceptances.add(newAcceptance);
                }
        
        }

    }
    
    public Iterable<SObject> start(Database.BatchableContext bc) {

       return NonSerPartAcceptances;
    }
   
    public static void execute(Database.BatchableContext bc, List<Acceptance__c> NonSerPartAcceptances) {

        for(Acceptance__c a : NonSerPartAcceptances){ 
            insert a;
        }   
    }
    public void finish(Database.BatchableContext bc){

        
        System.debug('Succesfully inserted Non Serialized parts and Acceptances');
    }


}

another batch class 
 
public with sharing class BatchCreateSerializedParts implements Database.Batchable<sObject> {
        String ProjectConfigID;
        String ProjectID;
        Integer VehicleFleetStartNumber;
        ComponentProjectConfiguration__c ProjectConfig;
    
        List<SerializedPartsSet__c> SerPartsSetConfig;
        List<project_Serialized_Parts_Set__c> SerPartsSets = new List<project_Serialized_Parts_Set__c>();
        List<project_Serialized_Part__c> SerParts = new List<project_Serialized_Part__c>();
    
        public BatchCreateSerializedParts(String ProjectConfigID, String ProjectID) {
            //this.ProjectConfigID = ProjectConfigID;
            //this.ProjectID = ProjectID;
                // not Batch operations 
            ProjectConfig = [Select ID, Name, Vehicle_fleet_start_number__c from ComponentProjectConfiguration__c where ID =: ProjectConfigID];
            VehicleFleetStartNumber = Integer.valueOf(ProjectConfig.Vehicle_fleet_start_number__c);
            SerPartsSetConfig = [Select ID, Name, Quantity__c from SerializedPartsSet__c where Project__c =: ProjectConfigID];

            for (SerializedPartsSet__c partSet : SerPartsSetConfig) {
    
                //   Double Total = part.Number_of_units__c * part.Quantity__c;
                   project_Serialized_Parts_Set__c NewPartSet = New project_Serialized_Parts_Set__c(Name = partSet.Name, Project__c =ProjectID, Quantity__c = partSet.Quantity__c);
                     SerPartsSets.add(NewPartSet);
                   } 
             
           // try {insert SerPartsSets;} catch (system.Dmlexception e) { system.debug (e);}
            
                        // DML statement
            Database.SaveResult[] srList = Database.insert(SerPartsSets, false);
            
            // Iterate through each returned result
            for (Database.SaveResult sr : srList) {
                if (sr.isSuccess()) {
                    // Operation was successful, so get the ID of the record that was processed
                    System.debug('Successfully inserted SerPartsSets: ');
                }
                else {
                    // Operation failed, so get all errors                
                    for(Database.Error err : sr.getErrors()) {
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('SerPartsSets fields that affected this error: ' + err.getFields());
                    }

                    return;
                }
            }
            
            // iterate over Part Sets to create all Serialized parts

            for(project_Serialized_Parts_Set__c partSet: SerPartsSets){ 
                    // ITERATE PART SETS. PROPULSION & TRUCK    
    
               // SerializedPartsSet__c ConfPartSet = [Select ID, Name, Project__c from SerializedPartsSet__c where Project__c =: ProjectConfigID AND Name =: partSet.Name];
                //List <SerializedPart__c> SerPartsConfig = [Select ID, Name, Quantity__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from SerializedPart__c where SerializedPartSet__c =: ConfPartSet.ID];
                List <SerializedPart__c> SerPartsConfig = [Select ID, Name, Quantity__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from SerializedPart__c where SerializedPartSet__c =: [Select ID from SerializedPartsSet__c where Project__c =: ProjectConfigID AND Name =: partSet.Name].id ];
                    // ITERATE OVER SETS - for example 400
                //System.debug(SerPartsConfig);

                for(Integer i=0; i<partSet.Quantity__c;i++) {
        
                    for(SerializedPart__c part: SerPartsConfig){
        
                
                        if( part.Quantity__c == 1) {
                            system.debug('PART QUANTITY is 1:' + part.Quantity__c ); 
                            
                            project_Serialized_Part__c newPart = new project_Serialized_Part__c(
                            Name= part.Name, Quantity__c = part.Quantity__c , Material_Number__c = part.Material_Number__c, 
                            Set_Number__c = i + VehicleFleetStartNumber, Status__c = 'NOT SENT',
                            Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
                            Supplier__c = part.Supplier__c, Serialized_Part_Set__c = partSet.ID); 
                        
                            SerParts.add(newPart);}
                            else {
                                system.debug('PART QUANTITY is > 1:' + part.Quantity__c );
                                for(Integer j=0; j<part.Quantity__c; j++) {
                                    project_Serialized_Part__c newPart = new project_Serialized_Part__c(
                                    Name= part.Name, Quantity__c = 1 , Material_Number__c = part.Material_Number__c, 
                                    Set_Number__c = i + VehicleFleetStartNumber, Status__c = 'NOT SENT',
                                    Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
                                    Supplier__c = part.Supplier__c, Serialized_Part_Set__c = partSet.ID); 
                                
                                    SerParts.add(newPart);
                                }
                            }
        
                        }
        
                    }
                }         
        }
    
        public Iterable<SObject> start(Database.BatchableContext bc) {
            return SerParts;
        }
        
        public static void execute(Database.BatchableContext bc, List<project_Serialized_Part__c> SerParts) { 
            for(project_Serialized_Part__c p : SerParts){ 
                insert p;
            }
        }
    
        public void finish(Database.BatchableContext bc){
            System.debug('Succesfully inserted Serialized parts and Sets');
        }



    }

 
I am getting APEX CPU issue as I have to process a lot of records 

I found one example from Salesforce on how to use Maps instead of slow list iteration. 

My question is how I can apply the same principle if I need to assign values of Map to another object. 
 
for (NonSerializedPart__c part : NonSerPartsConfig) {
        Double Total = part.Number_of_units__c * part.Quantity__c;
        project_Non_Serialized_Part__c NewPart = New project_Non_Serialized_Part__c(Name = part.Name, Project__c =ProjectID,
        Material_Number__c = part.Material_Number__c, Supplier__c = part.Supplier__c, 
        Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
        Total_Quantity__c = Total ,Unit_of_measurement__c = part.Unit_of_measurement__c,
        Number_of_units__c = part.Number_of_units__c, unit_Quantity__c = part.Quantity__c);

        NonSerParts.add(NewPart);
        
        }
        insert NonSerParts;

so I need to assign somehow the values of Map to the list. A simple cast doesn't work in this case. 
 
Map<id, NonSerializedPart__c>  NSPM = new Map <id, NonSerializedPart__c>([Select ID, Name, Number_of_units__c, Quantity__c, Unit_of_measurement__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from NonSerializedPart__c where Project__c =: 'a3ae0000003ZTBmAAO']);


NonSerParts = (project_Non_Serialized_Part__c) NSPM.values();

I have 1 field in the object that the original one doesn't have. 
Double Total = part.Number_of_units__c * part.Quantity__c; 

Please advise. 




 
Hi. Can somebody share gitlab-ci.yml for not master branch? 

When I use default template - there is a problem when pushed to non master branch.

defined stages are no execuded.
instead of 
 
stages:
  - preliminary-testing
  - create-scratch-org
  - test-scratch-org
  - package
  - staging
  - production

only the following are executed
 
stages:
  - preliminary-testing
  - create-scratch-org
  - test-scratch-org

I use slightly modifed gitlab-ci.yml from salesforce tamplates for gitlab

It is too long to copy-paste, link is below 

sfdx-cicd-template (https://gitlab.com/sfdx/sfdx-cicd-template/-/blob/master/Salesforce.gitlab-ci.yml#L167-169)
 
Hello 
It might be more questions to Gitlab than to SFDX.

I created a branch of my SFDX salesforce project, gitlab-ci.yml is the same. When I push it, pipeline is default. 

Jobs are defined in  gitlab-ci.yml, right? 

what could be the problem? 
how to disable trigger in unmanaged package? I need for dataloader records update. 

When open Apex Trigger, find the one I need and select to deactivate, changes are not saved. 

everytime disable code in code and deploy? 
Hey
Can someone tell me what are the limits for the code below? or how to estimate it? 
 
/*****************************************************************************
* Description: Class that implements Batch interface and allows to with DML > 10000

*/

    public with sharing class BatchCreateSerializedParts implements Database.Batchable<sObject> {
        String ProjectConfigID;
        String ProjectID;
        Integer VehicleFleetStartNumber;
        ComponentProjectConfiguration__c ProjectConfig;
    
        List<SerializedPartsSet__c> SerPartsSetConfig;
        List<project_Serialized_Parts_Set__c> SerPartsSets = new List<project_Serialized_Parts_Set__c>();
        List<project_Serialized_Part__c> SerParts = new List<project_Serialized_Part__c>();
    
        public BatchCreateSerializedParts(String ProjectConfigID, String ProjectID) {
            this.ProjectConfigID = ProjectConfigID;
            this.ProjectID = ProjectID;
                // not Batch operations 
            ProjectConfig = [Select ID, Name, Vehicle_fleet_start_number__c from ComponentProjectConfiguration__c where ID =: ProjectConfigID];
            VehicleFleetStartNumber = Integer.valueOf(ProjectConfig.Vehicle_fleet_start_number__c);
            SerPartsSetConfig = [Select ID, Name, Quantity__c from SerializedPartsSet__c where Project__c =: ProjectConfigID];

            for (SerializedPartsSet__c partSet : SerPartsSetConfig) {
    
                //   Double Total = part.Number_of_units__c * part.Quantity__c;
                   project_Serialized_Parts_Set__c NewPartSet = New project_Serialized_Parts_Set__c(Name = partSet.Name, Project__c =ProjectID, Quantity__c = partSet.Quantity__c);
                     SerPartsSets.add(NewPartSet);
                   } 
             
            try {insert SerPartsSets;} catch (system.Dmlexception e) { system.debug (e);}

            for(project_Serialized_Parts_Set__c partSet: SerPartsSets){ 
                    // ITERATE PART SETS. PROPULSION & TRUCK    
    
                SerializedPartsSet__c ConfPartSet = [Select ID, Name, Project__c from SerializedPartsSet__c where Project__c =: ProjectConfigID AND Name =: partSet.Name];
                List <SerializedPart__c> SerPartsConfig = [Select ID, Name, Quantity__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from SerializedPart__c where SerializedPartSet__c =: ConfPartSet.ID];
                    // ITERATE OVER SETS - for example 400
                for(Integer i=0; i<partSet.Quantity__c;i++){
        
                    for(SerializedPart__c part: SerPartsConfig){
        
                
                        if( part.Quantity__c == 1) {
                            system.debug('PART QUANTITY is 1:' + part.Quantity__c ); 
                            
                            project_Serialized_Part__c newPart = new project_Serialized_Part__c(
                            Name= part.Name, Quantity__c = part.Quantity__c , Material_Number__c = part.Material_Number__c, 
                            Set_Number__c = i + VehicleFleetStartNumber, Status__c = 'NOT SENT',
                            Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
                            Supplier__c = part.Supplier__c, Serialized_Part_Set__c = partSet.ID); 
                        
                            SerParts.add(newPart);}
                            else {
                                system.debug('PART QUANTITY is > 1:' + part.Quantity__c );
                                for(Integer j=0; j<part.Quantity__c; j++) {
                                    project_Serialized_Part__c newPart = new project_Serialized_Part__c(
                                    Name= part.Name, Quantity__c = 1 , Material_Number__c = part.Material_Number__c, 
                                    Set_Number__c = i + VehicleFleetStartNumber, Status__c = 'NOT SENT',
                                    Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
                                    Supplier__c = part.Supplier__c, Serialized_Part_Set__c = partSet.ID); 
                                
                                    SerParts.add(newPart);
                                }
                            }
        
                        }
        
                    }
                }         
        }
    
        public Iterable<SObject> start(Database.BatchableContext bc) {
            return SerParts;
        }

        public void execute(Database.BatchableContext bc, List<project_Serialized_Part__c> SerParts) { 
            for(project_Serialized_Part__c p : SerParts){ 
                insert p;
            }
        }
    
        public void finish(Database.BatchableContext bc){
            System.debug('Succesfully inserted Serialized parts and Sets');
        }
    }

and another one
 
/******************************************************************************

* Description: Class that implements Batch interface and allows to with DML > 10000
*/

public with sharing class BatchCreateNonSerializedParts implements Database.Batchable<sObject> {
    String ProjectConfigID;
    String ProjectID;
    Integer VehicleFleetStartNumber;
    ComponentProjectConfiguration__c ProjectConfig;

    List<NonSerializedPart__c> NonSerPartsConfig;
    List<project_Non_Serialized_Part__c> NonSerParts = new List<project_Non_Serialized_Part__c>();
    List<Acceptance__c> NonSerPartAcceptances = new List<Acceptance__c>();  


    public BatchCreateNonSerializedParts(String ProjectConfigID, String ProjectID) {
        this.ProjectConfigID = ProjectConfigID;
        this.ProjectID = ProjectID;

        ProjectConfig = [Select ID, Name, Vehicle_fleet_start_number__c from ComponentProjectConfiguration__c where ID =: ProjectConfigID];
        VehicleFleetStartNumber = Integer.valueOf(ProjectConfig.Vehicle_fleet_start_number__c);

        NonSerPartsConfig = [Select ID, Name, Number_of_units__c, Quantity__c, Unit_of_measurement__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from NonSerializedPart__c where Project__c =: ProjectConfigID];
        
        for (NonSerializedPart__c part : NonSerPartsConfig) {
        Double Total = part.Number_of_units__c * part.Quantity__c;
        project_Non_Serialized_Part__c NewPart = New project_Non_Serialized_Part__c(Name = part.Name, Project__c =ProjectID,
        Material_Number__c = part.Material_Number__c, Supplier__c = part.Supplier__c, 
        Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
        Total_Quantity__c = Total ,Unit_of_measurement__c = part.Unit_of_measurement__c,
        Number_of_units__c = part.Number_of_units__c, unit_Quantity__c = part.Quantity__c);

        NonSerParts.add(NewPart);
        
        }
        insert NonSerParts;
        for(project_Non_Serialized_Part__c part : NonSerParts){ 
                
            for(Integer i=0;i<part.Number_of_units__c;i++){
                    Acceptance__c newAcceptance = new Acceptance__c(Non_Serialized_Part__c = part.id, Quantity__c = part.unit_Quantity__c,
                    Unit_of_measurement__c = part.Unit_of_measurement__c, Acceptance_Non_Serialized_Part__c = part.Name, Status__c = 'NOT SENT');  
                    NonSerPartAcceptances.add(newAcceptance);
                    System.debug('Acceptances size: ' + NonSerPartAcceptances.size());
                }
        }

    }
    
    public Iterable<SObject> start(Database.BatchableContext bc) {

       return NonSerPartAcceptances;
    }

    public void execute(Database.BatchableContext bc, List<Acceptance__c> NonSerPartAcceptances) {

        for(Acceptance__c a : NonSerPartAcceptances){ 
            insert a;
        }   
    }
    public void finish(Database.BatchableContext bc){
        System.debug('Succesfully inserted Non Serialized parts and Acceptances');
    }
}

​​​​​​​



 
Hello Everyone. 

I was using the code below testing it on small amount of records, it worked fine till I used in sandbox with lots of records. 

Please advise how to rewrite into Batch apex code.
 
/******************************************************************************
Trigger for Class that implements batchable 
*/


trigger ProjectCreateTrigger on Component_Project__c (after insert) {

    String ProjectConfigID;
    String ProjectID;
  
    for (Component_Project__c c : Trigger.new) {
//         // c - is created new Project where the records shall be added

         ProjectConfigID = c.Project__c;  
        ProjectID = c.ID;
       
     }

    database.executebatch(new BatchProjectCreate(ProjectConfigID, ProjectID),200);

 }



/******************************************************************************
Class implement Batchable 
*/

public with sharing class BatchProjectCreate  implements Database.Batchable<sObject> {

    public BatchProjectCreate(String ProjectConfigID, String ProjectID) {

    Integer VehicleFleetStartNumber;

    ComponentProjectConfiguration__c ProjectConfig = [Select ID, Name, Vehicle_fleet_start_number__c from ComponentProjectConfiguration__c where ID =: ProjectConfigID];
    VehicleFleetStartNumber = Integer.valueOf(ProjectConfig.Vehicle_fleet_start_number__c);

    List<NonSerializedPart__c> NonSerPartsConfig = [Select ID, Name, Number_of_units__c, Quantity__c, Unit_of_measurement__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from NonSerializedPart__c where Project__c =: ProjectConfigID];
    
    // CREATE NON SERIALIZED PART RECORDS FOR THE PROJECT 
    
    List<project_Non_Serialized_Part__c> NonSerParts = new List<project_Non_Serialized_Part__c>();
    List<Acceptance__c> NonSerPartAcceptances = new List<Acceptance__c>();  
    for (NonSerializedPart__c part : NonSerPartsConfig) {
           Double Total = part.Number_of_units__c * part.Quantity__c;
            project_Non_Serialized_Part__c NewPart = New project_Non_Serialized_Part__c(Name = part.Name, Project__c =ProjectID,
             Material_Number__c = part.Material_Number__c, Supplier__c = part.Supplier__c, 
             Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
             Total_Quantity__c = Total ,Unit_of_measurement__c = part.Unit_of_measurement__c,
             Number_of_units__c = part.Number_of_units__c, unit_Quantity__c = part.Quantity__c);

         NonSerParts.add(NewPart);
           }  

    try {
         insert NonSerParts;	
	 } catch (system.Dmlexception e) {
	 	system.debug (e);
     }

     for(project_Non_Serialized_Part__c part : NonSerParts){ 
                
        for(Integer i=0;i<part.Number_of_units__c;i++){
                Acceptance__c newAcceptance = new Acceptance__c(Non_Serialized_Part__c = part.id, Quantity__c = part.unit_Quantity__c,
                Unit_of_measurement__c = part.Unit_of_measurement__c, Acceptance_Non_Serialized_Part__c = part.Name, Status__c = 'NOT SENT');
             
                NonSerPartAcceptances.add(newAcceptance);
        }
    }

    try {
        insert NonSerPartAcceptances;	
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
// Serialized Sets and Parts Creation 
    List<SerializedPartsSet__c> SerPartsSetConfig = [Select ID, Name, Quantity__c from SerializedPartsSet__c where Project__c =: ProjectConfigID];
    List<project_Serialized_Parts_Set__c> SerPartsSets = new List<project_Serialized_Parts_Set__c>();
    List<project_Serialized_Part__c> SerParts = new List<project_Serialized_Part__c>();

    for (SerializedPartsSet__c partSet : SerPartsSetConfig) {

    //   Double Total = part.Number_of_units__c * part.Quantity__c;
       project_Serialized_Parts_Set__c NewPartSet = New project_Serialized_Parts_Set__c(Name = partSet.Name, Project__c =ProjectID, Quantity__c = partSet.Quantity__c);
         SerPartsSets.add(NewPartSet);
       } 
 
    try {
        insert SerPartsSets;
	
    } catch (system.Dmlexception e) {
        system.debug (e);
    }

    // SerializedPartsSet__c ConfPartSet = [Select ID, Name, Project__c from SerializedPartsSet__c 
    // where Project__c =: ProjectConfigID AND Name =: partSet.Name];

    // insert Parts
    for(project_Serialized_Parts_Set__c partSet: SerPartsSets){ 
        // ITERATE PART SETS. PROPULSION & TRUCK    

        SerializedPartsSet__c ConfPartSet = [Select ID, Name, Project__c from SerializedPartsSet__c 
        where Project__c =: ProjectConfigID AND Name =: partSet.Name];
        List <SerializedPart__c> SerPartsConfig = [Select ID, Name, Quantity__c,
         Material_Number__c, Supplier_Part_Number__c, Supplier__c from SerializedPart__c 
         where SerializedPartSet__c =: ConfPartSet.ID];

        // ITERATE OVER SETS - for example 400
        for(Integer i=0; i<partSet.Quantity__c;i++){

            for(SerializedPart__c part: SerPartsConfig){

                // IF QUANTITY IS NOT ONE, ITERATE OVER THE QUIANITY AND INSERT RECORD FOR EACH 
                if( part.Quantity__c == 1) {
                    system.debug('PART QUANTITY is 1:' + part.Quantity__c ); 
                   
                    project_Serialized_Part__c newPart = new project_Serialized_Part__c(
                        Name= part.Name, Quantity__c = part.Quantity__c , Material_Number__c = part.Material_Number__c, 
                        Set_Number__c = i + VehicleFleetStartNumber, Status__c = 'NOT SENT',
                        Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
                        Supplier__c = part.Supplier__c, Serialized_Part_Set__c = partSet.ID); 
                      
                        SerParts.add(newPart);
                } else {
                    system.debug('PART QUANTITY is > 1:' + part.Quantity__c );
                    for(Integer j=0; j<part.Quantity__c; j++) {
                        project_Serialized_Part__c newPart = new project_Serialized_Part__c(
                            Name= part.Name, Quantity__c = 1 , Material_Number__c = part.Material_Number__c, 
                            Set_Number__c = i + VehicleFleetStartNumber, Status__c = 'NOT SENT',
                            Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
                            Supplier__c = part.Supplier__c, Serialized_Part_Set__c = partSet.ID); 
                           
                            SerParts.add(newPart);
                    }
                }

            }

        }
    }

    try {
        insert SerParts;	

    } catch (system.Dmlexception e) {
        system.debug(e);
    }

    }

    // Non Serialized Parts creation 


}



 
Hi. 
Is it possible to lookup field of one object? 
I dont want to create new object just for lookup. 
Isn't possible just to use the object I already have? 

to filter ser parts I wanted to have Set Number field available as lookup field.  



serialized part
 
I am struggling with how to search with record id in lookup field? 
it is wastful to create extra field for the name and have auto enumaration for name 

I found an option to change search layout - add some other field there, but it still looks only for name ? is there any workaround? to me Record is explicit enough to find the record. 
how to search with record id in lookup field? 
it is wastful to create extra field for the name and have auto enumaration for name 

I found an option to change search layout - add some other field there, but it still looks only for name ? is there any workaround? to me Record is explicit enough to find the record. 
HI. I have an issue 

for simplicity, I decided to use process builder. 

It is a process on the record created or edited. 
I don't need to run the process when the record is created, thus INOT(ISNEW()).
NOT(ISNEW()) && NOT(

(ISPICKVAL([project_Serialized_Part__c].Status__c, 'ACCEPTED')) 

|| 

(ISPICKVAL([project_Serialized_Part__c].Status__c, 'AFTER WARRANTY')) 

)

STATUS has several pick values 
NOT SENT, SENT, ARRIVED, ACCEPTED, AFTER WARRANTY. 

to update the date fields with status.ACCEPTED the following formula works fine. 
 
NOT(ISNEW()) && ISPICKVAL([project_Serialized_Part__c].Status__c, 'ACCEPTED')

I cannot figure out why my formula NOT update the field is evaluated to TRUE and the date fields set to NULL. 
 
Will it work - to connect Field devices with their IoT and LWC to monitor data change without refreshing the page. 
What is the right way to implement it? 

I was looking for a sample project. 
Can somebody share one? 

I saw IoT Salesforce  - is it possible to use it as Streaming data for LWC? 

 
Hi. 
I want to make an LWC MAP component that will display objects GPS updated online. 

how to do it?  
Idia is later connecting this frontend with IoT. 
Is there any sample project with that? 
Hi. Does anybody have a repo with  MindSphere and Salesforce project? 
I wanted to use Mindpshre as an IoT platform and integrate it with Salesforce CRM

Did somebody do any IoT Salesforce projects?

I did not find clear documentation on what API shall be used for constant data update, REST POST can be used, true. But I thought it is streaming API to update data from sensors. 

Is it possible to make a graphical visualization in some sort of trend? 
In Salesforce it is possible to enable history on some fields, but it is very limited, not suatable for IoT data. 
 
I am trying to deploy package to Sandbox and getting the following error 
 
"message": "No matching source was found within the package root directory:

I run command in vscode 
 
sfdx force:package:version:create --targetdevhubusername DevHub --package 0Ho1W000000XXXXXXXX --versionnumber 1.0.0.NEXT --installationkeybypass --wait 10 --json

{
  "status": 1,
  "name": "Error",
  "message": "No matching source was found within the package root directory: /Users/01_Salesforce/CICD/app/force-app",
  "exitCode": 1,
  "commandName": "PackageVersionCreateCommand",
  "stack": "Error: No matching source was found within the package root directory: /Users/01_Salesforce/CICD/app/force-app\n
.....
I used the same template before another unlocked package. It is working with no issue. 
I cannot figure out why this happened in the first place and how to resolve it.

P.S. it is a new package I try to deploy. I created based on my previous template. 
It ways on the state of package creation. 
 
Hi. I am trying to deploy the project with CICD pipeline when I still haven't developed any classes yet. In my company preferred way is declarative development (not everyone knows how to code, that helps to avoid complexity for newcomers )

when it comes to executing the apex tests 
sfdx force:apex:test:run --codecoverage --resultformat human --wait 10

ERROR running force:apex:test:run:  Unable to invoke any tests. Ensure the tests are loaded into the org or valid inputs are supplied. Always provide a classes, suites, tests, or testLevel property.
I am getting an error. 
How to fix it without writing rewriting .gitlab-cicd.yml? 

for example lwc tests I skipped with simply adding ---passWithNoTests option 

 
sfdx force:org:display --verbose --targetusername DEVHUB --json
org_username=null

When I try to deploy to CICD pipeline I am getting this error. 
Cannot figure out how to solve it.
 
I was following a quick start on IoT Salesforce. 
After I created Event, Context, Orchestration - I created rules to create cases. I thought it is not working. but then I used the console. I queried cases - I saw all of them are there. but when I open cases in the service cloud, I see only those I created manually. 

What could be the issue?  

P.S. While I was writing it I found the reason. I needed to create a new list view for the cases and remove the filter - to see all cases, not only mines. 
Hi. Everyone.
I am getting the fault when I try to pull changes from Scratch Org.

I think it is general issue in Salesforce. 

I saw an workaround for it 
sfdx force:data:soql:query -q "Select Id, MemberName From SourceMember Where MemberType = 'CustomApplication'" -t

fdx force:data:record:delete -s SourceMember -i <id retrieved above> -t

But when I try 
sfdx force:data:soql:query -q "Select Id From OrchestrationContext Where Name = 'Fault'" -t -u IoTScratchOrg
Querying Data... done
ERROR running force:data:soql:query:  sObject type 'OrchestrationContext' is not supported.
'OrchestrationContext' is not supported. 

How to fix it? 
 
Hi. I am trying to get an access token for working with API

I always get the message 

{"error":"invalid_grant","error_description":"authentication failure"}*

I tried postman and curl 
 
curl -v https://login.salesforce.com/services/oauth2/token 
      -d "grant_type=password" -d "client_id=consumer_key" 
      -d "client_secret=consumer_secret" 
      -d "username=username" -d "password=password"

curl I repeat instruction from https://developer.salesforce.com/docs/atlas.en-us.api_iot.meta/api_iot/qs_auth_access_token.htm, but it still doesn't work 

what is wrong here? 
 
I am struggling with how to search with record id in lookup field? 
it is wastful to create extra field for the name and have auto enumaration for name 

I found an option to change search layout - add some other field there, but it still looks only for name ? is there any workaround? to me Record is explicit enough to find the record. 
I am getting APEX CPU issue as I have to process a lot of records 

I found one example from Salesforce on how to use Maps instead of slow list iteration. 

My question is how I can apply the same principle if I need to assign values of Map to another object. 
 
for (NonSerializedPart__c part : NonSerPartsConfig) {
        Double Total = part.Number_of_units__c * part.Quantity__c;
        project_Non_Serialized_Part__c NewPart = New project_Non_Serialized_Part__c(Name = part.Name, Project__c =ProjectID,
        Material_Number__c = part.Material_Number__c, Supplier__c = part.Supplier__c, 
        Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
        Total_Quantity__c = Total ,Unit_of_measurement__c = part.Unit_of_measurement__c,
        Number_of_units__c = part.Number_of_units__c, unit_Quantity__c = part.Quantity__c);

        NonSerParts.add(NewPart);
        
        }
        insert NonSerParts;

so I need to assign somehow the values of Map to the list. A simple cast doesn't work in this case. 
 
Map<id, NonSerializedPart__c>  NSPM = new Map <id, NonSerializedPart__c>([Select ID, Name, Number_of_units__c, Quantity__c, Unit_of_measurement__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from NonSerializedPart__c where Project__c =: 'a3ae0000003ZTBmAAO']);


NonSerParts = (project_Non_Serialized_Part__c) NSPM.values();

I have 1 field in the object that the original one doesn't have. 
Double Total = part.Number_of_units__c * part.Quantity__c; 

Please advise. 




 
Hi. Can somebody share gitlab-ci.yml for not master branch? 

When I use default template - there is a problem when pushed to non master branch.

defined stages are no execuded.
instead of 
 
stages:
  - preliminary-testing
  - create-scratch-org
  - test-scratch-org
  - package
  - staging
  - production

only the following are executed
 
stages:
  - preliminary-testing
  - create-scratch-org
  - test-scratch-org

I use slightly modifed gitlab-ci.yml from salesforce tamplates for gitlab

It is too long to copy-paste, link is below 

sfdx-cicd-template (https://gitlab.com/sfdx/sfdx-cicd-template/-/blob/master/Salesforce.gitlab-ci.yml#L167-169)
 
how to disable trigger in unmanaged package? I need for dataloader records update. 

When open Apex Trigger, find the one I need and select to deactivate, changes are not saved. 

everytime disable code in code and deploy? 
Hello Everyone. 

I was using the code below testing it on small amount of records, it worked fine till I used in sandbox with lots of records. 

Please advise how to rewrite into Batch apex code.
 
/******************************************************************************
Trigger for Class that implements batchable 
*/


trigger ProjectCreateTrigger on Component_Project__c (after insert) {

    String ProjectConfigID;
    String ProjectID;
  
    for (Component_Project__c c : Trigger.new) {
//         // c - is created new Project where the records shall be added

         ProjectConfigID = c.Project__c;  
        ProjectID = c.ID;
       
     }

    database.executebatch(new BatchProjectCreate(ProjectConfigID, ProjectID),200);

 }



/******************************************************************************
Class implement Batchable 
*/

public with sharing class BatchProjectCreate  implements Database.Batchable<sObject> {

    public BatchProjectCreate(String ProjectConfigID, String ProjectID) {

    Integer VehicleFleetStartNumber;

    ComponentProjectConfiguration__c ProjectConfig = [Select ID, Name, Vehicle_fleet_start_number__c from ComponentProjectConfiguration__c where ID =: ProjectConfigID];
    VehicleFleetStartNumber = Integer.valueOf(ProjectConfig.Vehicle_fleet_start_number__c);

    List<NonSerializedPart__c> NonSerPartsConfig = [Select ID, Name, Number_of_units__c, Quantity__c, Unit_of_measurement__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from NonSerializedPart__c where Project__c =: ProjectConfigID];
    
    // CREATE NON SERIALIZED PART RECORDS FOR THE PROJECT 
    
    List<project_Non_Serialized_Part__c> NonSerParts = new List<project_Non_Serialized_Part__c>();
    List<Acceptance__c> NonSerPartAcceptances = new List<Acceptance__c>();  
    for (NonSerializedPart__c part : NonSerPartsConfig) {
           Double Total = part.Number_of_units__c * part.Quantity__c;
            project_Non_Serialized_Part__c NewPart = New project_Non_Serialized_Part__c(Name = part.Name, Project__c =ProjectID,
             Material_Number__c = part.Material_Number__c, Supplier__c = part.Supplier__c, 
             Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
             Total_Quantity__c = Total ,Unit_of_measurement__c = part.Unit_of_measurement__c,
             Number_of_units__c = part.Number_of_units__c, unit_Quantity__c = part.Quantity__c);

         NonSerParts.add(NewPart);
           }  

    try {
         insert NonSerParts;	
	 } catch (system.Dmlexception e) {
	 	system.debug (e);
     }

     for(project_Non_Serialized_Part__c part : NonSerParts){ 
                
        for(Integer i=0;i<part.Number_of_units__c;i++){
                Acceptance__c newAcceptance = new Acceptance__c(Non_Serialized_Part__c = part.id, Quantity__c = part.unit_Quantity__c,
                Unit_of_measurement__c = part.Unit_of_measurement__c, Acceptance_Non_Serialized_Part__c = part.Name, Status__c = 'NOT SENT');
             
                NonSerPartAcceptances.add(newAcceptance);
        }
    }

    try {
        insert NonSerPartAcceptances;	
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
// Serialized Sets and Parts Creation 
    List<SerializedPartsSet__c> SerPartsSetConfig = [Select ID, Name, Quantity__c from SerializedPartsSet__c where Project__c =: ProjectConfigID];
    List<project_Serialized_Parts_Set__c> SerPartsSets = new List<project_Serialized_Parts_Set__c>();
    List<project_Serialized_Part__c> SerParts = new List<project_Serialized_Part__c>();

    for (SerializedPartsSet__c partSet : SerPartsSetConfig) {

    //   Double Total = part.Number_of_units__c * part.Quantity__c;
       project_Serialized_Parts_Set__c NewPartSet = New project_Serialized_Parts_Set__c(Name = partSet.Name, Project__c =ProjectID, Quantity__c = partSet.Quantity__c);
         SerPartsSets.add(NewPartSet);
       } 
 
    try {
        insert SerPartsSets;
	
    } catch (system.Dmlexception e) {
        system.debug (e);
    }

    // SerializedPartsSet__c ConfPartSet = [Select ID, Name, Project__c from SerializedPartsSet__c 
    // where Project__c =: ProjectConfigID AND Name =: partSet.Name];

    // insert Parts
    for(project_Serialized_Parts_Set__c partSet: SerPartsSets){ 
        // ITERATE PART SETS. PROPULSION & TRUCK    

        SerializedPartsSet__c ConfPartSet = [Select ID, Name, Project__c from SerializedPartsSet__c 
        where Project__c =: ProjectConfigID AND Name =: partSet.Name];
        List <SerializedPart__c> SerPartsConfig = [Select ID, Name, Quantity__c,
         Material_Number__c, Supplier_Part_Number__c, Supplier__c from SerializedPart__c 
         where SerializedPartSet__c =: ConfPartSet.ID];

        // ITERATE OVER SETS - for example 400
        for(Integer i=0; i<partSet.Quantity__c;i++){

            for(SerializedPart__c part: SerPartsConfig){

                // IF QUANTITY IS NOT ONE, ITERATE OVER THE QUIANITY AND INSERT RECORD FOR EACH 
                if( part.Quantity__c == 1) {
                    system.debug('PART QUANTITY is 1:' + part.Quantity__c ); 
                   
                    project_Serialized_Part__c newPart = new project_Serialized_Part__c(
                        Name= part.Name, Quantity__c = part.Quantity__c , Material_Number__c = part.Material_Number__c, 
                        Set_Number__c = i + VehicleFleetStartNumber, Status__c = 'NOT SENT',
                        Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
                        Supplier__c = part.Supplier__c, Serialized_Part_Set__c = partSet.ID); 
                      
                        SerParts.add(newPart);
                } else {
                    system.debug('PART QUANTITY is > 1:' + part.Quantity__c );
                    for(Integer j=0; j<part.Quantity__c; j++) {
                        project_Serialized_Part__c newPart = new project_Serialized_Part__c(
                            Name= part.Name, Quantity__c = 1 , Material_Number__c = part.Material_Number__c, 
                            Set_Number__c = i + VehicleFleetStartNumber, Status__c = 'NOT SENT',
                            Supplier_Part_Number__c = part.Supplier_Part_Number__c, 
                            Supplier__c = part.Supplier__c, Serialized_Part_Set__c = partSet.ID); 
                           
                            SerParts.add(newPart);
                    }
                }

            }

        }
    }

    try {
        insert SerParts;	

    } catch (system.Dmlexception e) {
        system.debug(e);
    }

    }

    // Non Serialized Parts creation 


}



 
Hi. 
Is it possible to lookup field of one object? 
I dont want to create new object just for lookup. 
Isn't possible just to use the object I already have? 

to filter ser parts I wanted to have Set Number field available as lookup field.  



serialized part
 
how to search with record id in lookup field? 
it is wastful to create extra field for the name and have auto enumaration for name 

I found an option to change search layout - add some other field there, but it still looks only for name ? is there any workaround? to me Record is explicit enough to find the record. 
Hi. 
I want to make an LWC MAP component that will display objects GPS updated online. 

how to do it?  
Idia is later connecting this frontend with IoT. 
Is there any sample project with that? 
Hi. Everyone.
I am getting the fault when I try to pull changes from Scratch Org.

I think it is general issue in Salesforce. 

I saw an workaround for it 
sfdx force:data:soql:query -q "Select Id, MemberName From SourceMember Where MemberType = 'CustomApplication'" -t

fdx force:data:record:delete -s SourceMember -i <id retrieved above> -t

But when I try 
sfdx force:data:soql:query -q "Select Id From OrchestrationContext Where Name = 'Fault'" -t -u IoTScratchOrg
Querying Data... done
ERROR running force:data:soql:query:  sObject type 'OrchestrationContext' is not supported.
'OrchestrationContext' is not supported. 

How to fix it? 
 
Hi. I am writing a report on a custom object. 
I have an issue with creating the report 

mu records have quantity and status 
I want to get a summary of each record in different statuses. 
How it can be done? 

report on custom object
I cannot change in scratch org Administrative Permissions. ( I need to activate Run Flows)
the same with other permissions. 
I don't know why. 
Hi. Everyone.

I wonder if it is possible to create many records with process builder. 

My case is I have a project config. 
Then I create a project record itself, I use a lookup field to find the available configs. 
In this configs I have numbers of records I need to create and some other data related to the records I need to create: Serial number (it will be entered later manually), supplier, supplier part  name, other descripiton, etc. 

I know it is possible to do it with Apex code, but I wanted to keep it simple - use declarative programming. 
I want to create an object with some predefined and prefilled data depending on the selected Picklist value. But then the picklist shall no be active, which means it is impossible to change the picklist value? 

How to implement it? 

I am trying to work in CICD pipelines. 

I cannot figure out or find any good examples of packaging the metedata

1) How I have to retrieve metadata developed declaratively in salesforce? Shall I create a separate org just for declarative programming? After done with that pull the data into source code?
I am doing now 20 push already as I always miss something: flexipage, layout, some custom object, etc. How to avoid it? is it a normal process?

2) when I get the complete correct package.xml - it is more or less clear. 
git add *, git commit -m "...", git push origin master. 
but how to get this complete correct list? 

how other people work? I created scratch org but it did not work for some reason. I thought scratch org shall be empty, so what ever you create shall be possible to retreive all somehow I guess. 

But still it is very confusing. 

how to corrrectly work with metadata? I see people flad with lots of water but no clera instrucitons. 

 

I am trying to move from org development to source code development. 
i cannot find clear instructions on how to work with metadata. 

for example I declaratively created customapplication, objects, tabs, each object has page layout, custom field, etc. 
How to import it into my source code and update package.xml now? Import with all dependent fields, objects, etc?

if I import some custom object and try to push code, it fails as some relevant objects, fields are missing. 

I have no issue with Sfdx-project-cicd, but I don't understand how to import metadata with relevant objects, fields. 

Please some one show how to do with examples, not general phrases 



 

I have an issue with API versions

when I run locally "lwc-jest" I have not issue. API 50 

 PASS  force-app/main/default/lwc/hello/__tests__/hello.test.js
  c-hello
    ✓ displays greeting (18ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.86s, estimated 2s

But when I push the code to git, I receive the message that version 47 is required and pipeline fails. 
"error Invalid sourceApiVersion found in sfdx-project.json. Expected 47.0, found 50.0"

Can some explain, please?

sfdx-project.json is below 
{
"packageDirectories": [
{
"path": "force-app",
"default": true,
"package": "CoManagerApp",
"versionName": "Version 1.0",
"versionNumber": "1.0.0.NEXT"
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "50.0",
"packageAliases": {
"CoManagerApp": "xxxxxxxxxxxxxx"
}
}


package.json 
"scripts": {
"test:lwc": "sfdx-lwc-jest",
"test:scratch": "sfdx force:apex:test:run --codecoverage --resultformat human --wait 10"
},
"devDependencies": {
"@salesforce/sfdx-lwc-jest": "^0.10.1"
}
}
how to insert multiple records using dynamic apex in salesforce