• k2018123
  • NEWBIE
  • 50 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 17
    Replies
Hi ,

i have a list of sobject as 
        List<sObject> lstSObject = new List<sObject>();
i want to update a field test__c = 'abc' for all the records in this list of sObject.
i tried something like 
for(SObject so : lstSObject){
            so.test__c = so.test__c + 1;
            }
update lstSobject;


But it throw me the error saying could not identify variable test__c. 
Can anyone please give me a snippet how to update a specific field of list of sObjects?

Hi,
I the component , i have created a field with the following code:
<lightning:input aura:id="field" label="Receipt Number" placeholder="Receipt Number" required="true" />
The field needs to be saved in a record with record id  = record.recordid. I am able to get the record.recordid .
I have created a save button with the following code:
<lightning:button label="Save and Close"
                                              aura:Id="saveBtn"
                                              iconPosition="left"
                                              variant="brand"
                                              onclick=""
                                              >
                            </lightning:button>

I want the receipt number to be updated to the record "record.recordid" whenever i click on save button. Can anyone please tell me how to acheieve this? A sample code will be really helpful
Hi,
I the below code, insertlstTarget is having duplicate values. How do i elminate them?
For(Course__c course1 : lstTarget){
                Course__c course2 = new Course__c ();
                course2 = course1.clone(false,false,false,false);
                course2.Specialisation_Code__c = '';
                course2.Specialisation__c = '';
                course2.Course_Code__c = course1.Name;
                newLstTarget.add(course2);
                system.debug('newLstTarget' + newLstTarget.size());
            }
            Map<String,Course__c> extIdMap1 = new Map<String,Course__c>();
            for(Course__c so1 : newLstTarget){
                extIdMap1.put((String)so1.get('Course_Code__c'),so1);
            }
            Set<String> extIdSet1 = extIdMap1.keyset();
            String splitQuery1 = 'SELECT Id,Course_Code__c FROM Course__c WHERE Course_Code__c in :extIdSet1';
            system.debug(splitQuery1);
            List<Course__c> insertlstTarget = new List<Course__c>();
            Map<Id,Course__c> updateMap1 = new Map<Id,Course__c>();
            Map<String,Id> queryMap1 = new Map<String,Id>();
            for(Course__c so1 : database.query(splitquery1)){
                queryMap1.put((String)so1.get('Course_Code__c'), so1.Id);
            }
            for(Course__c so1 : newLstTarget){
                Id theId = queryMap1.get((String)so1.get('Course_Code__c'));
                if(theId != null){
                    so1.Id = theId;
                    updateMap1.put(theId,so1);
                }
                else{
                    insertlstTarget.add(so1);
                }
            }

Thanks
Hi ,
i have a list called List<test__c> lsttest = Database.query(sQueryForUniqueId);. It has a field name unique code with value "1234;456".
I want to create a new list which will have two records one with unique code 1234 and another with 456. Can anyone help with a sample code snippet?

Thanks
Hi I have  a trigger code in which when i am trying to upsert the list it is throwing me the error "System.TypeException: DML on generic List only allowed for insert, update or delete error". My unique external id field for the object is testfield__c. How do i handle the insert and update seperately?
Below is my code: 
Upsert operation highlighted in bold:
public class JobTriggerHandler
{
    private List<trigger_mapping__mdt> lstFieldMapping = null;
    private Schema.SObjectType sobType = null;
    public void onAfterInsert(List<Job_Control__c> lstNewObjA)
    {
        if (lstNewObjA.size() > 1 || (String.isBlank(lstNewObjA[0].Unique_Id__c ) || lstNewObjA[0].Status__c != 'Under Processing')){
            return;
        }
        
        Job_Control__c oJobControl = lstNewObjA[0];
        List<Job_Control__c> LstJobtoUpdateCRM = new List<Job_Control__c>();
        lstFieldMapping = [SELECT Source_Field_API_Name__c, Source_Object__c, Target_Field_API_Name__c, Target_Object__r.DeveloperName FROM trigger_mapping__mdt WHERE Target_Object__r.DeveloperName =:oJobControl.Object_Name__c ];
        sobType = Schema.getGlobalDescribe().get(lstFieldMapping[0].Target_Object__r.DeveloperName +'__c');
        processJobControlRecord(oJobControl.Unique_Id__c, oJobControl.Object_Name__c);
    }
    
    
    
    public void processJobControlRecord(String sUniqueId, String sObjectName)
    {
        if(lstFieldMapping ==null)
            lstFieldMapping = [SELECT Source_Field_API_Name__c, Source_Object__c, Target_Field_API_Name__c, Target_Object__r.DeveloperName FROM trigger_mapping__mdt WHERE Target_Object__r.DeveloperName =:sObjectName ];
        if(sobType == null)
            sobType = Schema.getGlobalDescribe().get(lstFieldMapping[0].Target_Object__r.DeveloperName +'__c');
        String sQueryForUniqueId = getQuery(sObjectName, sUniqueId);
        List<Staging_Course__c> lstStaging = Database.query(sQueryForUniqueId);
        List<sObject> lstSObject = new List<sObject>();
        
        
        for(Staging_Course__c oStag: lstStaging)
        {
            lstSObject.add(createNewRecordFromMapping(oStag, sObjectName));
            oStag.Status__c = 'Completed';
            oStag.Object_Name__c = sObjectName;
        }
        
        upsert lstSObject;
        update lstStaging;
        for(Job_Control__c  obj : [Select Id,Status__c from Job_Control__c where unique_id__c = :sUniqueId]){
            obj.Status__c = 'Completed'; 
            update obj ; 
            
        }
        
    }
    
    
    private String getQuery(String sObjectName, String sUniqueId)
    {
        
        String sQuery = 'SELECT Id ';
        for(trigger_mapping__mdt oMDT: lstFieldMapping)
        {
            sQuery += ',' + oMDT.Source_Field_API_Name__c;   
        }
        
        sQuery += ' FROM Staging_Course__c' + ' WHERE Unique_Id__c =: sUniqueId';
        return sQuery;
    }
    
    
    private sObject createNewRecordFromMapping(Staging_Course__c oStag, String sObjectName)
    {
        
        sObject sObjectNew = sobType.newSObject();
        for(trigger_mapping__mdt oMDT: lstFieldMapping)
        {
            sObjectNew.put(oMDT.Target_Field_API_Name__c, oStag.get(oMDT.Source_Field_API_Name__c));
        }
        
        return sObjectNew;
        
    }
}


 
Hi,
I have. a trigger where is want to udate the record of list "lstNewObjA" . But using the code snippet below, it throws me the error "invalid conversion from runtime type List to List ". I want to update the list after DML operations on lstSObject and lstStaging are performed. Can anybody please help? Below is the code snippet:
public class JobTriggerHandler
{
    public void onAfterInsert(List<Job_Control__c> lstNewObjA)
    {
        if (lstNewObjA.size() > 1 || (String.isBlank(lstNewObjA[0].Unique_Id__c ) || lstNewObjA[0].Status__c != 'Under Processing')){
            return;
        }
        
        Job_Control__c oJobControl = lstNewObjA[0];
        List<Job_Control__c> LstJobtoUpdateCRM = new List<Job_Control__c>();
        processJobControlRecord(oJobControl.Unique_Id__c, oJobControl.Object_Name__c);
        
    }
    
    
    
    public void processJobControlRecord(String sUniqueId, String sObjectName)
    {
        String sQueryForUniqueId = getQuery(sObjectName, sUniqueId);
        List<Staging_Course__c> lstStaging = Database.query(sQueryForUniqueId);
        List<sObject> lstSObject = new List<sObject>();
        List<Job_Control__c> lstJobControl = Database.query(sQueryForUniqueId);
        for(Staging_Course__c oStag: lstStaging)
        {
            lstSObject.add(createNewRecordFromMapping(oStag, sObjectName));
            oStag.Status__c = 'Completed';
        }
        
        insert lstSObject;
        update lstStaging;
       /* for(Job_Control__c objAUpdated : lstJobControl)
            {
            Job_Control__c j = new Job_Control__c(id = objAUpdated.Id);
            j.Status__c = 'Completed';
            lstJobControl.add(j);
            }

            if(lstJobControl.size() > 0){
            update lstJobControl;
            } */
        
    }
    
    
    private String getQuery(String sObjectName, String sUniqueId)
    {
        List<trigger_mapping__mdt> lstFieldMapping = [SELECT Source_Field__r.DeveloperName, Source_Object__c, Target_Field__r.DeveloperName, Target_Object__r.DeveloperName FROM trigger_mapping__mdt WHERE Target_Object__r.DeveloperName =:sObjectName ];
        String sQuery = 'SELECT Id ';
        for(trigger_mapping__mdt oMDT: lstFieldMapping)
        {
            sQuery += ',' + oMDT.Source_Field__r.DeveloperName + '__c';   
        }
        //check for std object condition before constructing query
        sQuery += ' FROM Staging_Course__c' + ' WHERE Unique_Id__c =: sUniqueId';
        return sQuery;
    }
    
    
    private sObject createNewRecordFromMapping(Staging_Course__c oStag, String sObjectName)
    {
        List<trigger_mapping__mdt> lstFieldMapping = [SELECT Source_Field__r.DeveloperName, Source_Object__c, Target_Field__r.DeveloperName, Target_Object__r.DeveloperName FROM trigger_mapping__mdt WHERE Target_Object__r.DeveloperName =:sObjectName ];
        //sObject sObjectNew = new sObject(Type = lstFieldMapping[0].Target_Object__r.DeveloperName +'__c');
        sObject sObjectNew = Schema.getGlobalDescribe().get(lstFieldMapping[0].Target_Object__r.DeveloperName +'__c').newSObject();
        for(trigger_mapping__mdt oMDT: lstFieldMapping)
        {
            sObjectNew.put(oMDT.Target_Field__r.DeveloperName + '__c', oStag.get(oMDT.Source_Field__r.DeveloperName + '__c'));
        }
        
        return sObjectNew;
        
    }
}

The commented part is throwing the error.
HI,
I have. a trigger which is working fine. But i want to update the record value of the object but getting "execution of AfterInsert caused by: System.FinalException: Record is read-only" error. After processing all the records i want to again update the same object record value. Can somebody help. Below is my code snippet. I have commented the code which is not working fine:
public class JobTriggerHandler
{
    public void onAfterInsert(List<Job_Control__c> lstNewObjA)
    {
        Set<String> setUniqueId = new Set<String>();
        Set<String> objAStatus = new Set<String>();
        for(Job_Control__c objA : lstNewObjA)
        {
            if(String.isNotBlank(objA.Unique_Id__c ) && objA.Status__c == 'Under Processing')
            {
                setUniqueId.add(objA.Unique_Id__c );
                // objA.Status__c = 'With CRM';
                
            }
        }
        // if(lstNewObjA.size() > 0){
        //    update lstNewObjA;
        //}
        if(!setUniqueId.isEmpty())
        {
            List<Staging_Course__c> lststag = new List<Staging_Course__c>();
            List<Course__c> lstObjC = new List<Course__c >();
            for(Staging_Course__c  objB: [SELECT test_Field__c , test_field_1__c,name  FROM Staging_Course__c WHERE Unique_Id__c  IN: setUniqueId])
            {
                
                lstObjC.add(new Course__c( test_Field__c  = objB.test_Field__c, test_field_1__c  = objB.test_field_1__c , name = objB.name ));
                objB.Status__c = 'Completed'; 
                lststag.add(objB);
                
            }
            if(!lststag.isEmpty())
                update lststag;
            
            if(!lstObjC.isEmpty())
                insert lstObjC;
            /* for(Job_Control__c objAUpdated : lstNewObjA)
{

objAUpdated.Status__c = 'Completed';

}

if(lstNewObjA.size() > 0){
update lstNewObjA;
}*/ 
            
        }
        
    } 
    
}

 
Hi, 
I want to use custom metadata to make the mapping dynamic in salesforce. Can somebody please help how should i do it?
code snippet for mapping:
for(Staging_Course__c  objB: [SELECT test_Field__c , test_field_1__c,name  FROM Staging_Course__c WHERE Unique_Id__c  IN: setUniqueId])
			{
              
				lstObjC.add(new Course__c( test_Field__c  = objB.test_Field__c, test_field_1__c  = objB.test_field_1__c , name = objB.name ));

I created a custom metadata record but i am not sure how to use to make the mapping dynamic in the above apex code.
User-added image 

Thanks
Hi,
Can someone please help with the sample code snippet for trigger:
Hi Have three objects - (A , B and C).
I have an external system that is creating a single record in object C and bulk of records in object B. I want a trigger that as soon as a record is inserted or updated in obejct C, copy the record values from object B and insert/update it in Object A.

Thanks.
i have a jQuery lightning DataTable with the followwing code:
<aura:component controller="jQueryDataTableCtrl">

    <ltng:require styles="{! $Resource.	datatable + '/DataTables-1.10.16/media/css/jquery.dataTables.min.css'}" 
                  scripts="{!join(',', 
                           $Resource.jquery224 ,
                           
                           $Resource.datatable + '/DataTables-1.10.16/media/js/jquery.dataTables.min.js')
                           }" afterScriptsLoaded="{!c.scriptsLoaded}"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>  
    
    <aura:attribute name="lstOpp" type="opportunity[]"/>     
    
    <div class="slds-m-around_medium">
        <table id="tableId" class="slds-table slds-table_bordered slds-table_cell-buffer" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Stage</th>
                    <th>Amount</th>
                    <th>Close Date</th> 
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.lstOpp}" var="acc">
                    <tr>
                        <td>{!acc.Name}</td>
                        <td>{!acc.Type}</td>
                        <td>{!acc.StageName}</td>
                        <td>{!acc.Amount}</td>
                        <td>{!acc.CloseDate}</td>
                    </tr>
                </aura:iteration>  
            </tbody>
        </table>
    </div>
</aura:component>
JS Controller
({
    ScriptsLoaded : function(component, event, helper) {

    },
    
    doInit : function(component,event,helper){

        var action = component.get('c.fetchOpportunity');
        action.setCallback(this, function(response) {
            //store state of response
            var state = response.getState();
            if (state === "SUCCESS") {
   
                component.set('v.lstOpp', response.getReturnValue());
                
                // when response successfully return from server then apply jQuery dataTable after 500 milisecond
                
                setTimeout(function(){ 
                   
                    $('#tableId').DataTable();

                    $('div.dataTables_filter input').addClass('slds-input');
                   $('div.dataTables_filter input').css("marginBottom", "10px");
                }, 500); 
                
            }
        });
        $A.enqueueAction(action); 
    },
})

I want to add additional functionality of editing the records according to this link https://editor.datatables.net/examples/simple/multiRow.html

Can anyone please help me in that as i am very bad in jQuery and Javascripts. Can you please share the sample code ?
 
Hi,

I am using jquery data table component recently posted in the blog:
http://sfdcmonkey.com/2018/03/13/jquery-datatable-salesforce-lightning-component/#comment-3313

The issue is if i am using two different component in the same page, search and pagination is appearing in one component and it dissapears in the other component.

Any help will be appreciated.

Thanks
Hi ,

i have a list of sobject as 
        List<sObject> lstSObject = new List<sObject>();
i want to update a field test__c = 'abc' for all the records in this list of sObject.
i tried something like 
for(SObject so : lstSObject){
            so.test__c = so.test__c + 1;
            }
update lstSobject;


But it throw me the error saying could not identify variable test__c. 
Can anyone please give me a snippet how to update a specific field of list of sObjects?

Hi,
I the component , i have created a field with the following code:
<lightning:input aura:id="field" label="Receipt Number" placeholder="Receipt Number" required="true" />
The field needs to be saved in a record with record id  = record.recordid. I am able to get the record.recordid .
I have created a save button with the following code:
<lightning:button label="Save and Close"
                                              aura:Id="saveBtn"
                                              iconPosition="left"
                                              variant="brand"
                                              onclick=""
                                              >
                            </lightning:button>

I want the receipt number to be updated to the record "record.recordid" whenever i click on save button. Can anyone please tell me how to acheieve this? A sample code will be really helpful
Hi ,
i have a list called List<test__c> lsttest = Database.query(sQueryForUniqueId);. It has a field name unique code with value "1234;456".
I want to create a new list which will have two records one with unique code 1234 and another with 456. Can anyone help with a sample code snippet?

Thanks
I want to update a record on ABC__c object.

There are two fields "A"  and "B" on this record.

I have a few decision elements one to update "A" and one to update "B" and two record update elements. 

Based on first Decision Element, A value is updated vis a record update element. Then it flows to the next decision elements, to set the value for B, a record update element updates the record.

My question is to understand if having multiple record update elements for the same record causes any performance or DML issues?
Hi Everyone

how we can redirect to edit page  after double click on field in page. 

Thanks in advance
Hi I have  a trigger code in which when i am trying to upsert the list it is throwing me the error "System.TypeException: DML on generic List only allowed for insert, update or delete error". My unique external id field for the object is testfield__c. How do i handle the insert and update seperately?
Below is my code: 
Upsert operation highlighted in bold:
public class JobTriggerHandler
{
    private List<trigger_mapping__mdt> lstFieldMapping = null;
    private Schema.SObjectType sobType = null;
    public void onAfterInsert(List<Job_Control__c> lstNewObjA)
    {
        if (lstNewObjA.size() > 1 || (String.isBlank(lstNewObjA[0].Unique_Id__c ) || lstNewObjA[0].Status__c != 'Under Processing')){
            return;
        }
        
        Job_Control__c oJobControl = lstNewObjA[0];
        List<Job_Control__c> LstJobtoUpdateCRM = new List<Job_Control__c>();
        lstFieldMapping = [SELECT Source_Field_API_Name__c, Source_Object__c, Target_Field_API_Name__c, Target_Object__r.DeveloperName FROM trigger_mapping__mdt WHERE Target_Object__r.DeveloperName =:oJobControl.Object_Name__c ];
        sobType = Schema.getGlobalDescribe().get(lstFieldMapping[0].Target_Object__r.DeveloperName +'__c');
        processJobControlRecord(oJobControl.Unique_Id__c, oJobControl.Object_Name__c);
    }
    
    
    
    public void processJobControlRecord(String sUniqueId, String sObjectName)
    {
        if(lstFieldMapping ==null)
            lstFieldMapping = [SELECT Source_Field_API_Name__c, Source_Object__c, Target_Field_API_Name__c, Target_Object__r.DeveloperName FROM trigger_mapping__mdt WHERE Target_Object__r.DeveloperName =:sObjectName ];
        if(sobType == null)
            sobType = Schema.getGlobalDescribe().get(lstFieldMapping[0].Target_Object__r.DeveloperName +'__c');
        String sQueryForUniqueId = getQuery(sObjectName, sUniqueId);
        List<Staging_Course__c> lstStaging = Database.query(sQueryForUniqueId);
        List<sObject> lstSObject = new List<sObject>();
        
        
        for(Staging_Course__c oStag: lstStaging)
        {
            lstSObject.add(createNewRecordFromMapping(oStag, sObjectName));
            oStag.Status__c = 'Completed';
            oStag.Object_Name__c = sObjectName;
        }
        
        upsert lstSObject;
        update lstStaging;
        for(Job_Control__c  obj : [Select Id,Status__c from Job_Control__c where unique_id__c = :sUniqueId]){
            obj.Status__c = 'Completed'; 
            update obj ; 
            
        }
        
    }
    
    
    private String getQuery(String sObjectName, String sUniqueId)
    {
        
        String sQuery = 'SELECT Id ';
        for(trigger_mapping__mdt oMDT: lstFieldMapping)
        {
            sQuery += ',' + oMDT.Source_Field_API_Name__c;   
        }
        
        sQuery += ' FROM Staging_Course__c' + ' WHERE Unique_Id__c =: sUniqueId';
        return sQuery;
    }
    
    
    private sObject createNewRecordFromMapping(Staging_Course__c oStag, String sObjectName)
    {
        
        sObject sObjectNew = sobType.newSObject();
        for(trigger_mapping__mdt oMDT: lstFieldMapping)
        {
            sObjectNew.put(oMDT.Target_Field_API_Name__c, oStag.get(oMDT.Source_Field_API_Name__c));
        }
        
        return sObjectNew;
        
    }
}


 
HI,
I have. a trigger which is working fine. But i want to update the record value of the object but getting "execution of AfterInsert caused by: System.FinalException: Record is read-only" error. After processing all the records i want to again update the same object record value. Can somebody help. Below is my code snippet. I have commented the code which is not working fine:
public class JobTriggerHandler
{
    public void onAfterInsert(List<Job_Control__c> lstNewObjA)
    {
        Set<String> setUniqueId = new Set<String>();
        Set<String> objAStatus = new Set<String>();
        for(Job_Control__c objA : lstNewObjA)
        {
            if(String.isNotBlank(objA.Unique_Id__c ) && objA.Status__c == 'Under Processing')
            {
                setUniqueId.add(objA.Unique_Id__c );
                // objA.Status__c = 'With CRM';
                
            }
        }
        // if(lstNewObjA.size() > 0){
        //    update lstNewObjA;
        //}
        if(!setUniqueId.isEmpty())
        {
            List<Staging_Course__c> lststag = new List<Staging_Course__c>();
            List<Course__c> lstObjC = new List<Course__c >();
            for(Staging_Course__c  objB: [SELECT test_Field__c , test_field_1__c,name  FROM Staging_Course__c WHERE Unique_Id__c  IN: setUniqueId])
            {
                
                lstObjC.add(new Course__c( test_Field__c  = objB.test_Field__c, test_field_1__c  = objB.test_field_1__c , name = objB.name ));
                objB.Status__c = 'Completed'; 
                lststag.add(objB);
                
            }
            if(!lststag.isEmpty())
                update lststag;
            
            if(!lstObjC.isEmpty())
                insert lstObjC;
            /* for(Job_Control__c objAUpdated : lstNewObjA)
{

objAUpdated.Status__c = 'Completed';

}

if(lstNewObjA.size() > 0){
update lstNewObjA;
}*/ 
            
        }
        
    } 
    
}

 
Hi, 

I have a requirement to select 10MB file in Salesforce and then send it to external system using REST API? Anyway to do this using Lightning or VF?

Thanks,
Rajan
Hi, 
I want to use custom metadata to make the mapping dynamic in salesforce. Can somebody please help how should i do it?
code snippet for mapping:
for(Staging_Course__c  objB: [SELECT test_Field__c , test_field_1__c,name  FROM Staging_Course__c WHERE Unique_Id__c  IN: setUniqueId])
			{
              
				lstObjC.add(new Course__c( test_Field__c  = objB.test_Field__c, test_field_1__c  = objB.test_field_1__c , name = objB.name ));

I created a custom metadata record but i am not sure how to use to make the mapping dynamic in the above apex code.
User-added image 

Thanks
Hi,
Can someone please help with the sample code snippet for trigger:
Hi Have three objects - (A , B and C).
I have an external system that is creating a single record in object C and bulk of records in object B. I want a trigger that as soon as a record is inserted or updated in obejct C, copy the record values from object B and insert/update it in Object A.

Thanks.
Hi,

I am using jquery data table component recently posted in the blog:
http://sfdcmonkey.com/2018/03/13/jquery-datatable-salesforce-lightning-component/#comment-3313

The issue is if i am using two different component in the same page, search and pagination is appearing in one component and it dissapears in the other component.

Any help will be appreciated.

Thanks