• Srikanth sfdc 32
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 9
    Replies
How to get the multiple ids from the url through split method in apex class .. can anyone help me out from this scenario

Hi,

I have a number field in Contact and i want to show the sum of the number field for each contact in Account. How should I use without aggregate function?

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.
User u = [SELECT Id, Contact.AccountId FROM User WHERE Id = :UserInfo.getUserId()][0];
            contact.AccountId = u.Contact.AccountId;
            insert contact;
How to get the multiple ids from the url through split method in apex class .. can anyone help me out from this scenario
Hi,

I am trying to update an account field based on a contact field. I have discovered I need a trigger.

here is my trigger but keep getting an error;

trigger ContactUpdate on Account (after update) {
    set<Id> accountaccList = new set<Id>();
    List<Contact> listContact = new List<Contact>();
    
    for(Account acct : trigger.new){
        if(acct.Account_Has_MQL__c){
            accountaccList.add(acct.id);
        }
    }
    listContact = [ SELECT lastname, AccountId FROM Contact WHERE AccountId IN :accountaccList];
    
    if ( listContact.size() > 0 ) {
        for ( Contact con : listContact ) {            
                con.Became_a_Marketo_Qualifying_Lead__c=true;
                
           }
         if(listContact.size()>0)   
           update listContact;
    }
}
Please have a look at the code below: 

trigger addcontactlastname2accountname on Contact(before insert){

    Set<ID> contactid_lst = new Set<ID>();
    List<Account> account_lst = new List<Account>();
    Map<ID, Account> accountmap = new Map<ID, Account>();

    for(Contact c: Trigger.New){
        
        contactid_lst.add(c.AccountID);
    }

    account_lst = [Select ID, Name from Account where ID IN: contactid_lst];


    for(Contact c: Trigger.New){


        Account objacct = new Account();

        objacct = accountmap(account_lst).get(c.AccountID);
        
        objacct.Name = objacct.Name + '' + c.lastname;
        

    }

}