• SF Beginner 2019
  • NEWBIE
  • 70 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 28
    Questions
  • 27
    Replies
I am Encountering this error

Unable to Access Page
The value of a parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information. 

wherein I just followed this one

https://automationchampion.com/tag/auto-remove-permission-sets-in-salesforce/

so I created a process builder wherein upon edit or create, it will assigne a permission set. the create works perfectly, but when I tried to do blank update/update of a field, it returns tha above error
How to call this apex class to make it a batch job?
 
public class ApplicationYearsinService{

    public static void YearsinService(List<Application__c> appList){
        //Declares the Variables, List, ID to be used
        Date dat = System.today();
        Integer yr = dat.year();   
        Map<Id, Set<Integer>> setofYear = new Map<Id, Set<Integer>>();
        Set<Id> accountIdSet = new set<Id>();
        
        //Gets the values of the Account(Account__c from the Application
        for(Application__c cs: appList ){
            accountIdSet.add(cs.Account__c);            
        }
        
        //Query in the Application to get the value from the Account
        for(Application__c p : [SELECT ID, Account__c, Received_Date__c from Application__c where Account__c IN : accountIdSet ]){
            if(p.Received_Date__c != null){
                if(setofYear.containskey(p.Account__c)){
                    if(p.Received_Date__c != NULL) {
                        setofYear.get(p.Account__c).add(p.Received_Date__c.Year());
                    }
                }
                else {
                    setofYear.put(p.Account__c, new Set<Integer>{p.Received_Date__c.Year()});
                }     
            }
        }
        
        Map<String, List<Application__c>> appMap = new Map<String ,List<Application__c>>();
        Map<String, Account> lisAcct = new  Map<String, Account>();
        List<Account> acctToUpdate = new  List<Account>();
        List<Account> accountListToLoop = [Select Id, YearsinService__c, (Select Id FROM Applications__r LIMIT 1) from Account where Id=:accountIdSet];
        for(Account acc: accountListToLoop){
            lisAcct.put(acc.Id+'', acc);
        }       
        for(Account act : accountListToLoop ){
            if(setofYear.containskey(act.id)){
                act.YearsinService__c = setofYear.get(act.id).size();
                acctToUpdate.add(act);
                lisAcct.remove(act.Id+'');
            }
            else {
                act.YearsinService__c = 0;
                acctToUpdate.add(act);
            }
        }
        Database.upsert(acctToUpdate, false); 
    }
}

 
How do I assign a permission set on  newly created partner user?
 
public class AssignPermissionSet {
    
    public static void assignperm(List<user> userlist){
        Set<ID> usersId = new Set<Id>();
        Set<Id> contactIdsSet = new Set<Id>();
        List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment>();
        
        
        for (User u : [Select Id, Name, ProfileId FROM User Where Id IN : userlist]){ // Add fields as per your requirement...
            if(u.ProfileId == '00e360003429432'){
            PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = '0PS33609skjojsae', AssigneeId = u.Id);
            permissionSetList.add(psa);
                }
        }
        insert permissionSetList;
    }
}

 
I have this code wherein it seems that even when run into small bulk like 50 updating it causing apex cpu limit is there a way I can remove that cpu limit
 
public class depToAccount {
    public static void deptpAccountV1(List<Dependent__c> depmem) {
        Set<Id> accountIdSet = new Set<Id>();
        Set<Id> coverIdSet = new Set<Id>();
        Map<Id, List<Dependent__c>> atoDep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ctomeddep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> cto19belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ato19belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> cto20belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ato20updep = new Map<Id, List<Dependent__c>>();//
        List<CampaignMember> cmList = new List<CampaignMember>();
        
        Map<Id, Account> accountToUpdateMap = new Map<Id, Account>();
        
        
        for(Dependent__c depm : depmem){
            if(depm.status__c == 'ACTIVE' && depm.Catg__c == 'Vision'){
                if(depm.Account__c != null){
                    accountIdSet.add(depm.Account__c);
                }
                if(depm.Cover__c != null){
                    coverIdSet.add(depm.Cover__c); 
                }
            }
        }
        
        List<Dependent__c> existingDependent = [SELECT Id, Account__c, Account__r.Name, Cover__c, Cover__r.Comply__c,Rel__c, status__c, Catg__c, Age_Today__c 
                                                            FROM Dependent__c 
                                                            WHERE ((Cover__c IN: coverIdSet AND Cover__c != null)
                                                                   OR (Account__c IN: accountIdSet AND Account__c != null))
                                                            AND status__c ='ACTIVE' AND Plan_Name__c != NULL aND Catg__c != NULL];
        for(Dependent__c depM : existingDependent){
            if(depM.Age_Today__c < 19){
                if(cto19belowdep.containsKey(depM.Cover__c)){
                    cto19belowdep.get(depM.Cover__c).add(depM);
                }
                else {
                    cto19belowdep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
                
                if(ato19belowdep.containsKey(depM.Account__c)){
                    ato19belowdep.get(depM.Account__c).add(depM);
                }
                else {
                    ato19belowdep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
            if(depM.Age_Today__c >= 19){
                if(cto20belowdep.containsKey(depM.Cover__c)){
                    cto20belowdep.get(depM.Cover__c).add(depM);
                }
                else {
                    cto20belowdep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
                
                if(ato20updep.containsKey(depM.Account__c)){
                    ato20updep.get(depM.Account__c).add(depM);
                }
                else {
                    ato20updep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
            if(depM.Catg__c == 'Vision'){
                if(ctomeddep.containsKey(depM.Cover__c)){
                    ctomeddep.get(depM.Cover__c).add(depM);
                }
                else {
                    ctomeddep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
            }
            
            if(depM.Catg__c == 'Dental'){
                if(atoDep.containsKey(depM.Account__c)){
                    atoDep.get(depM.Account__c).add(depM);
                }
                else {
                    atoDep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
        }
        Map<Id, Account> acctAttesAppMap = new Map<Id, Account>([Select ID,Good__c,Age_in_Numbers__pc,PersonContactId,Phone__c ,NumberofYears__c  FROM Account where ID IN : accountIdSet ]);
        
        for(Id acctId : accountIdSet){
            for(Dependent__c depM : existingDependent){
                for(Id covId : coverIdSet){
                    if(cto19belowdep.containsKey(covId) && depM.Cover__c==covId){ 
                        for(Dependent__c depU19 : cto19belowdep.get(covId)){
                            if(depU19.Age_Today__c < 19){ 
 
                                if((atoDep.containsKey(acctId)) || (acctAttesAppMap.get(acctId).Good__c == true) || (acctAttesAppMap.get(acctId ).NumberofYears__c > 0 )){ 
                                    if(ctomeddep.containsKey(covId)){
                                        for(Dependent__c depMemMedi : ctomeddep.get(covId)){ 
                                            accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=true, Comply__c=false));
                                        }
                                    }
                                    
                                }
                                else {
                                    if((!atoDep.containsKey(acctId)) || (acctAttesAppMap.get(acctId).Good__c == false) || (acctAttesAppMap.get(acctId ).NumberofYears__c == 0 )){ 
                                        if(ctomeddep.containsKey(covId)){
                                            for(Dependent__c depMemMedi : ctomeddep.get(covId)){
                                                accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=false, Comply__c=false));
                                            }
                                        }
                                        
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c != NULL ){
                                        {
                                           
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Doctor_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));

                                            
                                        }
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c == NULL && acctAttesAppMap.get(acctId).Age_in_Numbers__pc >= 19){
                                        {
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Nurse_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));
                                        }
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c == NULL &&  acctAttesAppMap.get(acctId).Age_in_Numbers__pc < 19){
                                        {
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Staff_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));
                                        }
                                    }
                                }
                            }
                            
                        }
                    else if(cto20belowdep.containsKey(covId) && depM.Cover__c==covId){
                        for(Dependent__c depU20 : cto20belowdep.get(covId)){
                            if(depU20.Age_Today__c >= 19){ 
                                if(atoDep.containsKey(acctId) ){
                                    if(ctomeddep.containsKey(covId)){
                                        for(Dependent__c depMemMedi : ctomeddep.get(covId)){
                                            accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=false, Comply__c=true));
                                        }
                                    }
                                }
                            }
                            
                        }
                    }
                    if(depM.Cover__r.Comply__c==true && depM.Cover__c == covId){
                        if(ctomeddep.containsKey(covId)) 
                            for(Dependent__c CMmed : ctomeddep.get(covId)){
                                accountToUpdateMap.put(CMmed.Account__c, new Account(Id=CMmed.Account__c, Compliant__c=false, Comply__c=true));
                            }
                    } 
                    
                }
            }
        }
        database.insert(cmlist, false);
        update accountToUpdateMap.values();
        
    }
    
}

 
I tried to make an else statement but it seems i doesn't indentify when it has a size of 0
 
List<Task> taskCompletedOrInvalidPhone = [SELECT Id, whatid, CallCustom__c, RecordtypeId 
                                                  FROM Task 
                                                  WHERE Whatid IN :forWhatID 
                                                  AND CallCustom__c = 'Completed' AND WhatID != null];
        for(Task tsk : taskCompletedOrInvalidPhone){
            if(accountIdToListTaskCompletedMap.containsKey(tsk.WhatId)){
                accountIdToListTaskCompletedMap.get(tsk.WhatId).add(tsk);
            }
            else{
                accountIdToListTaskCompletedMap.put(tsk.WhatId, new List<Task>{tsk});
            }
        }


for(Id acctId : forWhatID){
            if(accountIdToListTaskCompletedMap.containsKey(acctId)){
                if(accountIdToListTaskCompletedMap.get(acctId).size() >0){
                    if(accountIdToListDepMap.containsKey(acctId)){
                        for(Dependent__c covMem : accountIdToListDepMap.get(acctId)){
                            if(coverageIdToListDepMap.containsKey(covMem.Coverage__c)){
                                for(Dependent__c depMem2 : coverageIdToListDepMap.get(covMem.Coverage__c)){
                                    accountsToUpdate.put(depMem2.Account__c, new Account(Id=depMem2.Account__c, Good__c=true, Verygood__c=true));
                                }
                            }
                        } 
                    } 
                }
            }
			else{
			if(accountIdToListTaskCompletedMap.containsKey(acctId)){
                if(accountIdToListTaskCompletedMap.get(acctId).size() == 0){
                    if(accountIdToListDepMap.containsKey(acctId)){
                        for(Dependent__c covMem : accountIdToListDepMap.get(acctId)){
                            if(coverageIdToListDepMap.containsKey(covMem.Coverage__c)){
                                for(Dependent__c depMem2 : coverageIdToListDepMap.get(covMem.Coverage__c)){
                                    accountsToUpdate.put(depMem2.Account__c, new Account(Id=depMem2.Account__c, Good__c=false, Verygood__c=false));
                                }
                            }
                        } 
                    } 
                }
            }
			}

 
how can I attain that if there is no task or specific task in will update a field in account, trigger should be account,
HI 

I am encountering and error while doing a data load.

here is my code when dataloading. is there anything that needs to be optimize in here so far?
 
public class depToAccount {
    public static void deptpAccountV1(List<Dependent__c> depmem) {
        Set<Id> accountIdSet = new Set<Id>();
        Set<Id> coverIdSet = new Set<Id>();
        Map<Id, List<Dependent__c>> atoDep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ctomeddep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> cto19belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ato19belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> cto20belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ato20updep = new Map<Id, List<Dependent__c>>();//
        List<CampaignMember> cmList = new List<CampaignMember>();
        
        Map<Id, Account> accountToUpdateMap = new Map<Id, Account>();
        
        
        for(Dependent__c depm : depmem){
            if(depm.status__c == 'ACTIVE' && depm.Catg__c == 'Vision'){
                if(depm.Account__c != null){
                    accountIdSet.add(depm.Account__c);
                }
                if(depm.Cover__c != null){
                    coverIdSet.add(depm.Cover__c); 
                }
            }
        }
        
        List<Dependent__c> existingDependent = [SELECT Id, Account__c, Account__r.Name, Cover__c, Cover__r.Comply__c,Rel__c, status__c, Catg__c, Age_Today__c 
                                                            FROM Dependent__c 
                                                            WHERE ((Cover__c IN: coverIdSet AND Cover__c != null)
                                                                   OR (Account__c IN: accountIdSet AND Account__c != null))
                                                            AND status__c ='ACTIVE' AND Plan_Name__c != NULL aND Catg__c != NULL];
        for(Dependent__c depM : existingDependent){
            if(depM.Age_Today__c < 19){
                if(cto19belowdep.containsKey(depM.Cover__c)){
                    cto19belowdep.get(depM.Cover__c).add(depM);
                }
                else {
                    cto19belowdep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
                
                if(ato19belowdep.containsKey(depM.Account__c)){
                    ato19belowdep.get(depM.Account__c).add(depM);
                }
                else {
                    ato19belowdep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
            if(depM.Age_Today__c >= 19){
                if(cto20belowdep.containsKey(depM.Cover__c)){
                    cto20belowdep.get(depM.Cover__c).add(depM);
                }
                else {
                    cto20belowdep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
                
                if(ato20updep.containsKey(depM.Account__c)){
                    ato20updep.get(depM.Account__c).add(depM);
                }
                else {
                    ato20updep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
            if(depM.Catg__c == 'Vision'){
                if(ctomeddep.containsKey(depM.Cover__c)){
                    ctomeddep.get(depM.Cover__c).add(depM);
                }
                else {
                    ctomeddep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
            }
            
            if(depM.Catg__c == 'Dental'){
                if(atoDep.containsKey(depM.Account__c)){
                    atoDep.get(depM.Account__c).add(depM);
                }
                else {
                    atoDep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
        }
        Map<Id, Account> acctAttesAppMap = new Map<Id, Account>([Select ID,Good__c,Age_in_Numbers__pc,PersonContactId,Phone__c ,NumberofYears__c  FROM Account where ID IN : accountIdSet ]);
        
        for(Id acctId : accountIdSet){
            for(Dependent__c depM : existingDependent){
                for(Id covId : coverIdSet){
                    if(cto19belowdep.containsKey(covId) && depM.Cover__c==covId){ 
                        for(Dependent__c depU19 : cto19belowdep.get(covId)){
                            if(depU19.Age_Today__c < 19){ 
 
                                if((atoDep.containsKey(acctId)) || (acctAttesAppMap.get(acctId).Good__c == true) || (acctAttesAppMap.get(acctId ).NumberofYears__c > 0 )){ 
                                    if(ctomeddep.containsKey(covId)){
                                        for(Dependent__c depMemMedi : ctomeddep.get(covId)){ 
                                            accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=true, Comply__c=false));
                                        }
                                    }
                                    
                                }
                                else {
                                    if((!atoDep.containsKey(acctId)) || (acctAttesAppMap.get(acctId).Good__c == false) || (acctAttesAppMap.get(acctId ).NumberofYears__c == 0 )){ 
                                        if(ctomeddep.containsKey(covId)){
                                            for(Dependent__c depMemMedi : ctomeddep.get(covId)){
                                                accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=false, Comply__c=false));
                                            }
                                        }
                                        
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c != NULL ){
                                        {
                                           
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Doctor_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));

                                            
                                        }
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c == NULL && acctAttesAppMap.get(acctId).Age_in_Numbers__pc >= 19){
                                        {
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Nurse_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));
                                        }
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c == NULL &&  acctAttesAppMap.get(acctId).Age_in_Numbers__pc < 19){
                                        {
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Staff_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));
                                        }
                                    }
                                }
                            }
                            
                        }
                    else if(cto20belowdep.containsKey(covId) && depM.Cover__c==covId){
                        for(Dependent__c depU20 : cto20belowdep.get(covId)){
                            if(depU20.Age_Today__c >= 19){ 
                                if(atoDep.containsKey(acctId) ){
                                    if(ctomeddep.containsKey(covId)){
                                        for(Dependent__c depMemMedi : ctomeddep.get(covId)){
                                            accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=false, Comply__c=true));
                                        }
                                    }
                                }
                            }
                            
                        }
                    }
                    if(depM.Cover__r.Comply__c==true && depM.Cover__c == covId){
                        if(ctomeddep.containsKey(covId)) 
                            for(Dependent__c CMmed : ctomeddep.get(covId)){
                                accountToUpdateMap.put(CMmed.Account__c, new Account(Id=CMmed.Account__c, Compliant__c=false, Comply__c=true));
                            }
                    } 
                    
                }
            }
        }
        database.insert(cmlist, false);
        update accountToUpdateMap.values();
        
    }
    
}

 
Hi

I am getting this issue to many soql, is there something wrong with my code when try to save a record this error appers that too many soql
public class AccountTask {
    
    
    
    public static void accountTaskCopy(List<Account> acclist){
        Id EmailRT = SObjectType.Task.getRecordTypeInfosByDeveloperName().get('Email').getRecordTypeId();
        Id CallRT = SObjectType.Task.getRecordTypeInfosByDeveloperName().get('Call').getRecordTypeId(); 
        
        Set<Id> forWhatID = new Set<Id>();
        Set<Id> accID = new Set<Id>();
        Set<Id> coverageIds = new Set<Id>();
        Map<ID, List<CM__c>> accountIdToListCMOMap = new Map<Id, List<CM__c>>(); 
        Map<ID, List<CM__c>> coverageIdToListCVMMap = new Map<Id, List<CM__c>>();
        Map<ID, List<Task>> accountIdToListTaskCompletedMap = new Map<Id, List<Task>>();
        Map<ID, List<Task>> accountIdToListTaskNotCompletedMap = new Map<Id, List<Task>>();
        Map<Id, Account> accountsToUpdate = new Map<Id, Account>();
       
        for(Account acc: acclist){
            {
            accID.add(acc.ID);
            }
       }

        
        for(Task tsk : [SELECT ID,whatid FROM TASK where WHATID IN : accID]){
            if(tsk.WhatID != Null && tsk.WhatID.getSObjectType() == Account.SobjectType){
                forWhatID.add(tsk.WhatId);
                System.debug('forWhatID' + forWhatID);
            }
        }
         
        List<CM__c> existingCMs = [SELECT Id, Account__c, Account__r.Name, CVR__c, Coverage__r.Good__c,rel__c, status__c, BusinessType__c, Age_Today__c 
                                                            FROM CM__c 
                                                            WHERE (CVR__c != null AND Account__c IN: forWhatID AND Account__c != null) AND status__c ='ACTIVE' AND BusinessType__c = 'Medical'];
        
        for(CM__c cMo : existingCMs){
            if(accountIdToListCMOMap.containsKey(cMo.Account__c)){
                accountIdToListCMOMap.get(cMo.Account__c).add(cMo);
            }
            else{
                accountIdToListCMOMap.put(cMo.Account__c, new List<CM__c>{cMo});
            }
            
            if(coverageIdToListCVMMap.containsKey(cMo.CVR__c)){
                coverageIdToListCVMMap.get(cMo.CVR__c).add(cMo);
            }
            else{
                coverageIdToListCVMMap.put(cMo.CVR__c, new List<CM__c>{cMo});
            }
            
            coverageIds.add(cMo.CVR__c);
        }
        
        List<CM__c> existingCMFromCov = [SELECT Id, Account__c, Account__r.Name, CVR__c, Coverage__r.Good__c,rel__c, status__c, BusinessType__c, Age_Today__c 
                                                                   FROM CM__c 
                                                                   WHERE (CVR__c != null AND CVR__c IN: coverageIds AND Account__c != null) AND status__c ='ACTIVE' AND BusinessType__c = 'Medical'];
        for(CM__c cMo : existingCMFromCov){
            if(coverageIdToListCVMMap.containsKey(cMo.CVR__c)){
                coverageIdToListCVMMap.get(cMo.CVR__c).add(cMo);
            }
            else{
                coverageIdToListCVMMap.put(cMo.CVR__c, new List<CM__c>{cMo});
            }
        }
        System.debug('accountIdToListCMOMap ' + accountIdToListCMOMap);
        System.debug('coverageIdToListCVMMap ' + coverageIdToListCVMMap);
        
        
        List<Task> taskCompletedOrInvalidPhone = [SELECT Id, whatid, CallCustom__c, RecordtypeId 
                                                  FROM Task 
                                                  WHERE Whatid IN :forWhatID 
                                                  AND (CallCustom__c = 'Completed Campaign Requirements' OR CallCustom__c = 'Invalid Phone') AND WhatID != null];
        for(Task tsk : taskCompletedOrInvalidPhone){
            if(accountIdToListTaskCompletedMap.containsKey(tsk.WhatId)){
                accountIdToListTaskCompletedMap.get(tsk.WhatId).add(tsk);
            }
            else{
                accountIdToListTaskCompletedMap.put(tsk.WhatId, new List<Task>{tsk});
            }
        }
        
        List<Task> taskNotCompleteCampaign = [SELECT Id, whatid,CallCustom__c, RecordtypeId  FROM Task WHERE Whatid IN :forWhatID AND RecordTypeID =: CallRT AND (CallCustom__c = 'Left Message' OR  CallCustom__c = 'Unable to Reach') AND WhatID != null ];
        for(Task tsk : taskNotCompleteCampaign){
            if(accountIdToListTaskNotCompletedMap.containsKey(tsk.WhatId)){
                accountIdToListTaskNotCompletedMap.get(tsk.WhatId).add(tsk);
            }
            else{
                accountIdToListTaskNotCompletedMap.put(tsk.WhatId, new List<Task>{tsk});
            }
        }
        
        System.debug('accountIdToListTaskCompletedMap ' + accountIdToListTaskCompletedMap);
        System.debug('accountIdToListTaskNotCompletedMap ' + accountIdToListTaskNotCompletedMap);
        
        for(Id acctId : forWhatID){
            System.debug('acctId ' + acctId);
            if(accountIdToListTaskCompletedMap.containsKey(acctId)){
            system.debug('acctIdlist' + accountIdToListTaskCompletedMap);
                if(accountIdToListCMOMap.containsKey(acctId)){
                    for(CM__c cMo : accountIdToListCMOMap.get(acctId)){
                        System.debug('cMo ' + cMo);
                        if(coverageIdToListCVMMap.containsKey(cMo.CVR__c)){
                            for(CM__c covMem2 : coverageIdToListCVMMap.get(cMo.CVR__c)){
                                System.debug('covMem2 ' + covMem2);
                                accountsToUpdate.put(covMem2.Account__c, new Account(Id=covMem2.Account__c, PDC__c=true));
                            }
                        }
                        
                    } 
                } 
            }
        
        }
        
        System.debug('accountsToUpdate ' + accountsToUpdate);
        update accountsToUpdate.values();
        
    }
}

 
HI 

I am trying to parse this 

<advertisers type="array">
  <advertiser>
    <id type="integer">7</id>
    <name>ABC Telecom</name>
  </advertiser>
  <advertiser>
    <id type="integer">106</id>
    <name>ABC_Ozone</name>
  </advertiser><advertiser>
    <id type="integer">13</id>
    <name>Acme Corp</name>
  </advertiser>
</advertisers>


with this code
 
public with sharing class xmltosobject{
    public string s='';
    public void readxml(ID TestObjectID){
        XMLParsing__c TObj = [SELECT xml__c FROM XMLParsing__c where id= : TestObjectID];
        s= TObj.Event_Message_XML__c ;
        List<ParsedXML__c> newaccounts = new List<ParsedXML__c> ();
        
        Dom.Document docx = new Dom.Document();
        docx.load(s);
        dom.XmlNode xroot = docx.getrootelement() ;
        
        dom.XmlNode [] xrec = xroot.getchildelements() ; //Get all Record Elements
        
        for(Dom.XMLNode child : xrec) //Loop Through Records
        {
            ParsedXML__c a = new ParsedXML__c();
            
            for (dom.XmlNode awr : child.getchildren() ) {
                if (awr.getname() == 'id') {
                    system.debug('Id' + awr.gettext());
                    a.accountnumber__c = awr.gettext();
                }  
                
                if (awr.getname() == 'name') {
                    system.debug('name' + awr.gettext());
                    a.name__c = awr.gettext();
                }  
                
                
            }
            newaccounts.add(a);
        }
        system.debug(newaccounts);//you could insert here or upsert based on ID with an external Id field
    }
}


I got an invalid type when running this in execute anonymous
 
String str = '<advertisers type="array"><advertiser><id type="integer">7</id><name>ABC Telecom</name></advertiser><advertiser><id type="integer">106</id><name>ABC_Ozone</name></advertiser><advertiser><id type="integer">13</id><name>Acme Corp</name></advertiser></advertisers>';
xmltosobject.readxml objPartnerCreds = new xmltosobject.readxml();
system.debug(objPartnerCreds);


 
I have this Custom Object Named Stored XML.

and one of the field stores an XML strings.

<?xml version="1.0" encoding="UTF-8"?><consumers xmlns="http://test.com/feed/">
<SupplyResult>
 <MarketId>xxxxxxxx</MarketId>
 <SupplyList>
    <member>
        <Quantity>9</Quantity>
        <InStock>5</InStock>
        <SellerSKU>Test- 1111</SellerSKU>
    </member>
  </SupplyList>
  </SupplyResult>


How do I parse this and store all the field on on a new Custom Object Named XML Parsed?

Thank you!
How do i fix this issue?

({
    doInit : function(component,event,helper){
        var action = component.get("c.UserCheck");
        action.setParams({
            "currentRecordId" : component.get("v.recordId"),
            "currentUserId" : $A.get("$SObjectType.CurrentUser.Id")
        });
        action.setCallback(this,function(response){
            if(response.getState() == "SUCCESS"){
                //alert("hello there!" + response.getReturnValue()); 
                console.log(response.getReturnValue());
                if(response.getReturnValue()==true){
                    document.getElementById("Modal").setAttribute("style","height:640px;display:block;");
                    console.log(response.getReturnValue());
                }
                else{
                     document.getElementById("Modal").setAttribute("style","height:640px;display:none;");
                }
            }
        })
        $A.enqueueAction(action);
        
          var action2 = component.get("c.getAccount");
         action2.setParams({
            "currentRecordId" : component.get("v.recordId")
        });
        action2.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
               // alert("hello there!" + response.getReturnValue());
                component.set("v.account", response.getReturnValue());
                console.log(response.getReturnValue());
                /*if(response.getReturnValue()==true){
                    document.getElementById("Modal").setAttribute("style","height:640px;display:block;");
                    console.log(response.getReturnValue());
                }
                else{
                     document.getElementById("Modal_Parent").setAttribute("style","height:640px;display:none;");
                }*/
            }
         });
         $A.enqueueAction(action2); 
    
    },

 
var action2 = component.get("c.getAccount");
        action2.setParams({
            "currentRecordId" : component.get("v.recordId")
        });
        action2.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.account", response.getReturnValue());
                console.log(response.getReturnValue());
            }
        });
        $A.enqueueAction(action2);
 
<aura:attribute name="account" type="Account" 
                    default="{ 'sobjectType': 'Account' }"/>
    <aura:attribute name="recordId" type="Id" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <div id="Modal_Parent" style="height:640px; width:1500px;">
        <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <header class="slds-modal__header">
                    <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Modal Test</h2>
                </header>
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                    <p>Display the Name </p>
                    <force:outputField value="{!v.account.Name}"/>
                    {!v.account.Name}
                    <p></p>
                </div>

            </div>
 
@AuraEnabled
    public static List<Account> getAccount(String currentRecordId) {
        System.debug('AccountRecord' + currentRecordId);
        return [select Id, Name from Account where Id =: currentRecordId];
    }

 
HI,

I have this This account and I have a child name renewal.

What i want is that the checkbox(which is a formula field) from the Renewal will be put into account as 2 checkboxes as well.


Wherein will named as renewal 1 and renewal 2 in the Account. How can I build a these in apex, wherein either of the two checkbox from the renewal will be put onto the account as well, but these will check every record of the renewal object, wherein if renewal 1 or renewal 2 isn't check, it will not check the renwal 1 or renewal 2.

ex.

Renewal object.

Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
Record 3, Renewal 2 is not Checked
= Renewal 1 Checked in Account

Record 1, Renewal 1 is Not Checked
Record 2, Renewal 1 is Not Checked
Record 3, Renewal 2 is Checked
= Renewal 2 are not Checked in Account

Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
Record 3, Renewal 1 and 2 are not Checked
= Renewal 1 and Renewal 2 are not Checked in Account since a
public class Renewal {
    public void GotoAccount(List<Renewal__c> renmem) {
        List<Account> accountsToUpdate = new List<Account>();
        List<Id> renid = new List<Id>();
        Set<Id> ids; 
        
        for(Renewal__c ren : renmem){
                renid.add(ren.Account__c);
                }
        
        renmem = [SELECT Id, Renewal1__c, Renewal2__c, Renewal__c.Account__c,  FROM Renewal__c WHERE Id IN :renmem];
		
        for (Renewal__c p : renmem ) {
           IF(( /*What Condition */))
                accountsToUpdate = new List<Account>();
                ids = new Set<Id>(); 
                if(!ids.contains(p.Account__c)){
                    Account a = new Account(
                        Id = p.Account__c,
                        Renewal1__c = p.Renewal1__c,
                        Renewal2__c = p.Renewal1__c);
                    ids.add(p.Account__c);
                    accountsToUpdate.add(a);
                }
           }
          
        update accountsToUpdate;
        
    }
}

record isn't checked either of the two.

meaning if there is missing unchecked on the Renewal, it wil not make either Renewal 1 or Renewal 2 checked.
HI,

I have this This account and I have a child name renewal.

What i want is that the checkbox(which is a formula field) from the Renewal will be put into account as 2 checkboxes as well.


Wherein will named as renewal 1 and renewal 2 in the Account. How can I build a these in apex, wherein either of the two checkbox from the renewal will be put onto the account as well, but these will check every record of the renewal object, wherein if renewal 1 or renewal 2 isn't check, it will not check the renwal 1 or renewal 2.

ex.

Renewal object.

Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
= Renewal 1 is Checked in Account

Record 1, Renewal 1 is Not Checked
Record 2, Renewal 2 is Checked
= Renewal 2 is Checked in Account

Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
Record 3, Renewal 1 and 2 are not Checked
= Renewal 1 and Renewal 2 are not Checked in Account



Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
Record 3, Renewal 2 is not Checked
= Renewal 1 Checked in Account

Record 1, Renewal 1 is Not Checked
Record 2, Renewal 1 is Not Checked
Record 3, Renewal 2 is Checked
= Renewal 2 are not Checked in Account

Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
Record 3, Renewal 1 and 2 are not Checked
= Renewal 1 and Renewal 2 are not Checked in Account since a record isn't checked either of the two.

meaning if there is missing unchecked on the Renewal, it wil not make either Renewal 1 or Renewal 2 checked.
 
public class Renewal {
    public void GotoAccount(List<Renewal__c> renmem) {
        List<Account> accountsToUpdate = new List<Account>();
        List<Id> renid = new List<Id>();
        Set<Id> ids; 
        
        for(Renewal__c ren : renmem){
                renid.add(ren.Account__c);
                }
        
        renmem = [SELECT Id, Renewal1__c, Renewal2__c, Renewal__c.Account__c,  FROM Renewal__c WHERE Id IN :renmem];
		
        for (Renewal__c p : renmem ) {
           IF(( /*What Condition */))
                accountsToUpdate = new List<Account>();
                ids = new Set<Id>(); 
                if(!ids.contains(p.Account__c)){
                    Account a = new Account(
                        Id = p.Account__c,
                        Renewal1__c = p.Renewal1__c,
                        Renewal2__c = p.Renewal1__c);
                    ids.add(p.Account__c);
                    accountsToUpdate.add(a);
                }
           }
          
        update accountsToUpdate;
        
    }
}

 
I have these class wherein when I create or update the StatusGet__c to Completed it works, wherein it checks the (Indicator1__c)checkbox, and when I create != Completed it Unchecks(Indicator1__c), but my problem is that everytime I craete a new record  != Complete it overrides the checkbox, wherein what I want is that if there is a record StatusGet__c = Completed on the list of record the Indicator1__c will still be checked even if they add records != compelted

public class TaskTriggerHandles{
    public void  getAcct(List<Task> taskacct) {
        List<Account> accountsToUpdate = new List<Account>();
        
        taskacct = [SELECT Id, whatid,StatusGet__c FROM Task WHERE Id IN :taskacct];
        system.debug('taskacct' + taskacct );
        for (Task p : taskacct) {
        if(p.StatusGet__c ==  'Completed ')
           {
                Account a = new Account(
                    Id = p.whatid,
                    Indicator1__c= true);
                
                accountsToUpdate.add(a);
            system.debug('a' + a);
       }
        else if(p.StatusGet__c !=  'Completed')
        {
         Account a = new Account(
                    Id = p.whatid,
                    Indicator1__c= false);
                
                accountsToUpdate.add(a);
            system.debug('a' + a);
        }
        update accountsToUpdate;
        system.debug('accountsToUpdate' + accountsToUpdate);
         }
    }
}
I have these roll up and I want to translate these to Apex Class/Trigger, wherein this fields are currently on the child object wherein results will roll up into account

User-added image
How to create an account lookup on the child object via flow? I having trouble on passing the if of account to the child object.

Scenario is that

1. Get the Account ID and Name
2. There will be a decision wherein in Decision A it would create a child record on the account, and on the child it will lookup on the account.

Please help.

Thank you!
I have this flow, but it doesn't seem to be populate the Account ID, All are populated except for the Account wherein it looks up on the account. did I miss something? because what I want is on the guided Action it records what is being input and lastly the accountUser-added image
Hi,

I have his code wherein I want to track when an OpportunityLine Item is deleted. already done the create and update but not the delete. can you help me? I have done this as well in process builder

trigger trackOppProduct on OpportunityLineItem (after insert, after update, after delete) {
List<History_Tracking__c> hisTrackList = new List<History_Tracking__c>();
//
// Iterate through the OpportunityLineItems and create the History Tracking Record.
//
for (Integer i=0; i < Trigger.new.size(); i++) {
OpportunityLineItem newCM = Trigger.new[i];
if(Trigger.isInsert) {
hisTrackList.add(new History_Tracking__c(OpportunityLineItem_Record_Id__c = newCM.Id,
Object_Name__c = ‘OpportunityLineItem’,
Field_Name__c = ‘Status’,
Previous_Value__c = ”,
Current_Value__c = newCM.Status,
Modified_Date_Time__c = System.now(),
Modified_By__c = UserInfo.getUserId()
));
} else if(Trigger.old[i].Status != newCM.Status){
OpportunityLineItem oldCM = Trigger.old[i];
hisTrackList.add(new History_Tracking__c(OpportunityLineItem_Record_Id__c = newCM.Id,
Object_Name__c = ‘OpportunityLineItem’,
Field_Name__c = ‘Status’,
Previous_Value__c = oldCM.Status,
Current_Value__c = newCM.Status,
Modified_Date_Time__c = System.now(),
Modified_By__c = UserInfo.getUserId()
));
}
}
if(!hisTrackList.isEmpty()) {
insert hisTrackList;
}
}
I am planning to create a history or audit trail on Opportunity Product or Line Item, I am currently stuck in deleting and creating a history when deleted, can it be done using the process builder wherein when a record is deleted it will create a record on opp prod history object. I have created update and create, how can I achieve these on delete and if it is in apex how can I achieve these?
How to call this apex class to make it a batch job?
 
public class ApplicationYearsinService{

    public static void YearsinService(List<Application__c> appList){
        //Declares the Variables, List, ID to be used
        Date dat = System.today();
        Integer yr = dat.year();   
        Map<Id, Set<Integer>> setofYear = new Map<Id, Set<Integer>>();
        Set<Id> accountIdSet = new set<Id>();
        
        //Gets the values of the Account(Account__c from the Application
        for(Application__c cs: appList ){
            accountIdSet.add(cs.Account__c);            
        }
        
        //Query in the Application to get the value from the Account
        for(Application__c p : [SELECT ID, Account__c, Received_Date__c from Application__c where Account__c IN : accountIdSet ]){
            if(p.Received_Date__c != null){
                if(setofYear.containskey(p.Account__c)){
                    if(p.Received_Date__c != NULL) {
                        setofYear.get(p.Account__c).add(p.Received_Date__c.Year());
                    }
                }
                else {
                    setofYear.put(p.Account__c, new Set<Integer>{p.Received_Date__c.Year()});
                }     
            }
        }
        
        Map<String, List<Application__c>> appMap = new Map<String ,List<Application__c>>();
        Map<String, Account> lisAcct = new  Map<String, Account>();
        List<Account> acctToUpdate = new  List<Account>();
        List<Account> accountListToLoop = [Select Id, YearsinService__c, (Select Id FROM Applications__r LIMIT 1) from Account where Id=:accountIdSet];
        for(Account acc: accountListToLoop){
            lisAcct.put(acc.Id+'', acc);
        }       
        for(Account act : accountListToLoop ){
            if(setofYear.containskey(act.id)){
                act.YearsinService__c = setofYear.get(act.id).size();
                acctToUpdate.add(act);
                lisAcct.remove(act.Id+'');
            }
            else {
                act.YearsinService__c = 0;
                acctToUpdate.add(act);
            }
        }
        Database.upsert(acctToUpdate, false); 
    }
}

 
How do I assign a permission set on  newly created partner user?
 
public class AssignPermissionSet {
    
    public static void assignperm(List<user> userlist){
        Set<ID> usersId = new Set<Id>();
        Set<Id> contactIdsSet = new Set<Id>();
        List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment>();
        
        
        for (User u : [Select Id, Name, ProfileId FROM User Where Id IN : userlist]){ // Add fields as per your requirement...
            if(u.ProfileId == '00e360003429432'){
            PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = '0PS33609skjojsae', AssigneeId = u.Id);
            permissionSetList.add(psa);
                }
        }
        insert permissionSetList;
    }
}

 
HI 

I am encountering and error while doing a data load.

here is my code when dataloading. is there anything that needs to be optimize in here so far?
 
public class depToAccount {
    public static void deptpAccountV1(List<Dependent__c> depmem) {
        Set<Id> accountIdSet = new Set<Id>();
        Set<Id> coverIdSet = new Set<Id>();
        Map<Id, List<Dependent__c>> atoDep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ctomeddep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> cto19belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ato19belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> cto20belowdep = new Map<Id, List<Dependent__c>>();
        Map<Id, List<Dependent__c>> ato20updep = new Map<Id, List<Dependent__c>>();//
        List<CampaignMember> cmList = new List<CampaignMember>();
        
        Map<Id, Account> accountToUpdateMap = new Map<Id, Account>();
        
        
        for(Dependent__c depm : depmem){
            if(depm.status__c == 'ACTIVE' && depm.Catg__c == 'Vision'){
                if(depm.Account__c != null){
                    accountIdSet.add(depm.Account__c);
                }
                if(depm.Cover__c != null){
                    coverIdSet.add(depm.Cover__c); 
                }
            }
        }
        
        List<Dependent__c> existingDependent = [SELECT Id, Account__c, Account__r.Name, Cover__c, Cover__r.Comply__c,Rel__c, status__c, Catg__c, Age_Today__c 
                                                            FROM Dependent__c 
                                                            WHERE ((Cover__c IN: coverIdSet AND Cover__c != null)
                                                                   OR (Account__c IN: accountIdSet AND Account__c != null))
                                                            AND status__c ='ACTIVE' AND Plan_Name__c != NULL aND Catg__c != NULL];
        for(Dependent__c depM : existingDependent){
            if(depM.Age_Today__c < 19){
                if(cto19belowdep.containsKey(depM.Cover__c)){
                    cto19belowdep.get(depM.Cover__c).add(depM);
                }
                else {
                    cto19belowdep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
                
                if(ato19belowdep.containsKey(depM.Account__c)){
                    ato19belowdep.get(depM.Account__c).add(depM);
                }
                else {
                    ato19belowdep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
            if(depM.Age_Today__c >= 19){
                if(cto20belowdep.containsKey(depM.Cover__c)){
                    cto20belowdep.get(depM.Cover__c).add(depM);
                }
                else {
                    cto20belowdep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
                
                if(ato20updep.containsKey(depM.Account__c)){
                    ato20updep.get(depM.Account__c).add(depM);
                }
                else {
                    ato20updep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
            if(depM.Catg__c == 'Vision'){
                if(ctomeddep.containsKey(depM.Cover__c)){
                    ctomeddep.get(depM.Cover__c).add(depM);
                }
                else {
                    ctomeddep.put(depM.Cover__c, new List<Dependent__c>{ depM });
                }
            }
            
            if(depM.Catg__c == 'Dental'){
                if(atoDep.containsKey(depM.Account__c)){
                    atoDep.get(depM.Account__c).add(depM);
                }
                else {
                    atoDep.put(depM.Account__c, new List<Dependent__c>{ depM });
                }
            }
        }
        Map<Id, Account> acctAttesAppMap = new Map<Id, Account>([Select ID,Good__c,Age_in_Numbers__pc,PersonContactId,Phone__c ,NumberofYears__c  FROM Account where ID IN : accountIdSet ]);
        
        for(Id acctId : accountIdSet){
            for(Dependent__c depM : existingDependent){
                for(Id covId : coverIdSet){
                    if(cto19belowdep.containsKey(covId) && depM.Cover__c==covId){ 
                        for(Dependent__c depU19 : cto19belowdep.get(covId)){
                            if(depU19.Age_Today__c < 19){ 
 
                                if((atoDep.containsKey(acctId)) || (acctAttesAppMap.get(acctId).Good__c == true) || (acctAttesAppMap.get(acctId ).NumberofYears__c > 0 )){ 
                                    if(ctomeddep.containsKey(covId)){
                                        for(Dependent__c depMemMedi : ctomeddep.get(covId)){ 
                                            accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=true, Comply__c=false));
                                        }
                                    }
                                    
                                }
                                else {
                                    if((!atoDep.containsKey(acctId)) || (acctAttesAppMap.get(acctId).Good__c == false) || (acctAttesAppMap.get(acctId ).NumberofYears__c == 0 )){ 
                                        if(ctomeddep.containsKey(covId)){
                                            for(Dependent__c depMemMedi : ctomeddep.get(covId)){
                                                accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=false, Comply__c=false));
                                            }
                                        }
                                        
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c != NULL ){
                                        {
                                           
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Doctor_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));

                                            
                                        }
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c == NULL && acctAttesAppMap.get(acctId).Age_in_Numbers__pc >= 19){
                                        {
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Nurse_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));
                                        }
                                    }
                                    IF(acctAttesAppMap.get(acctId).Phone__c == NULL &&  acctAttesAppMap.get(acctId).Age_in_Numbers__pc < 19){
                                        {
                                            cmList.add( new CampaignMember(
                                                CampaignId  = System.Label.Staff_Campaign,
                                                ContactId = acctAttesAppMap.get(acctId).PersonContactId,
                                                Status = 'Completed'
                                            ));
                                        }
                                    }
                                }
                            }
                            
                        }
                    else if(cto20belowdep.containsKey(covId) && depM.Cover__c==covId){
                        for(Dependent__c depU20 : cto20belowdep.get(covId)){
                            if(depU20.Age_Today__c >= 19){ 
                                if(atoDep.containsKey(acctId) ){
                                    if(ctomeddep.containsKey(covId)){
                                        for(Dependent__c depMemMedi : ctomeddep.get(covId)){
                                            accountToUpdateMap.put(depMemMedi.Account__c, new Account(Id=depMemMedi.Account__c, Compliant__c=false, Comply__c=true));
                                        }
                                    }
                                }
                            }
                            
                        }
                    }
                    if(depM.Cover__r.Comply__c==true && depM.Cover__c == covId){
                        if(ctomeddep.containsKey(covId)) 
                            for(Dependent__c CMmed : ctomeddep.get(covId)){
                                accountToUpdateMap.put(CMmed.Account__c, new Account(Id=CMmed.Account__c, Compliant__c=false, Comply__c=true));
                            }
                    } 
                    
                }
            }
        }
        database.insert(cmlist, false);
        update accountToUpdateMap.values();
        
    }
    
}

 
Hi

I am getting this issue to many soql, is there something wrong with my code when try to save a record this error appers that too many soql
public class AccountTask {
    
    
    
    public static void accountTaskCopy(List<Account> acclist){
        Id EmailRT = SObjectType.Task.getRecordTypeInfosByDeveloperName().get('Email').getRecordTypeId();
        Id CallRT = SObjectType.Task.getRecordTypeInfosByDeveloperName().get('Call').getRecordTypeId(); 
        
        Set<Id> forWhatID = new Set<Id>();
        Set<Id> accID = new Set<Id>();
        Set<Id> coverageIds = new Set<Id>();
        Map<ID, List<CM__c>> accountIdToListCMOMap = new Map<Id, List<CM__c>>(); 
        Map<ID, List<CM__c>> coverageIdToListCVMMap = new Map<Id, List<CM__c>>();
        Map<ID, List<Task>> accountIdToListTaskCompletedMap = new Map<Id, List<Task>>();
        Map<ID, List<Task>> accountIdToListTaskNotCompletedMap = new Map<Id, List<Task>>();
        Map<Id, Account> accountsToUpdate = new Map<Id, Account>();
       
        for(Account acc: acclist){
            {
            accID.add(acc.ID);
            }
       }

        
        for(Task tsk : [SELECT ID,whatid FROM TASK where WHATID IN : accID]){
            if(tsk.WhatID != Null && tsk.WhatID.getSObjectType() == Account.SobjectType){
                forWhatID.add(tsk.WhatId);
                System.debug('forWhatID' + forWhatID);
            }
        }
         
        List<CM__c> existingCMs = [SELECT Id, Account__c, Account__r.Name, CVR__c, Coverage__r.Good__c,rel__c, status__c, BusinessType__c, Age_Today__c 
                                                            FROM CM__c 
                                                            WHERE (CVR__c != null AND Account__c IN: forWhatID AND Account__c != null) AND status__c ='ACTIVE' AND BusinessType__c = 'Medical'];
        
        for(CM__c cMo : existingCMs){
            if(accountIdToListCMOMap.containsKey(cMo.Account__c)){
                accountIdToListCMOMap.get(cMo.Account__c).add(cMo);
            }
            else{
                accountIdToListCMOMap.put(cMo.Account__c, new List<CM__c>{cMo});
            }
            
            if(coverageIdToListCVMMap.containsKey(cMo.CVR__c)){
                coverageIdToListCVMMap.get(cMo.CVR__c).add(cMo);
            }
            else{
                coverageIdToListCVMMap.put(cMo.CVR__c, new List<CM__c>{cMo});
            }
            
            coverageIds.add(cMo.CVR__c);
        }
        
        List<CM__c> existingCMFromCov = [SELECT Id, Account__c, Account__r.Name, CVR__c, Coverage__r.Good__c,rel__c, status__c, BusinessType__c, Age_Today__c 
                                                                   FROM CM__c 
                                                                   WHERE (CVR__c != null AND CVR__c IN: coverageIds AND Account__c != null) AND status__c ='ACTIVE' AND BusinessType__c = 'Medical'];
        for(CM__c cMo : existingCMFromCov){
            if(coverageIdToListCVMMap.containsKey(cMo.CVR__c)){
                coverageIdToListCVMMap.get(cMo.CVR__c).add(cMo);
            }
            else{
                coverageIdToListCVMMap.put(cMo.CVR__c, new List<CM__c>{cMo});
            }
        }
        System.debug('accountIdToListCMOMap ' + accountIdToListCMOMap);
        System.debug('coverageIdToListCVMMap ' + coverageIdToListCVMMap);
        
        
        List<Task> taskCompletedOrInvalidPhone = [SELECT Id, whatid, CallCustom__c, RecordtypeId 
                                                  FROM Task 
                                                  WHERE Whatid IN :forWhatID 
                                                  AND (CallCustom__c = 'Completed Campaign Requirements' OR CallCustom__c = 'Invalid Phone') AND WhatID != null];
        for(Task tsk : taskCompletedOrInvalidPhone){
            if(accountIdToListTaskCompletedMap.containsKey(tsk.WhatId)){
                accountIdToListTaskCompletedMap.get(tsk.WhatId).add(tsk);
            }
            else{
                accountIdToListTaskCompletedMap.put(tsk.WhatId, new List<Task>{tsk});
            }
        }
        
        List<Task> taskNotCompleteCampaign = [SELECT Id, whatid,CallCustom__c, RecordtypeId  FROM Task WHERE Whatid IN :forWhatID AND RecordTypeID =: CallRT AND (CallCustom__c = 'Left Message' OR  CallCustom__c = 'Unable to Reach') AND WhatID != null ];
        for(Task tsk : taskNotCompleteCampaign){
            if(accountIdToListTaskNotCompletedMap.containsKey(tsk.WhatId)){
                accountIdToListTaskNotCompletedMap.get(tsk.WhatId).add(tsk);
            }
            else{
                accountIdToListTaskNotCompletedMap.put(tsk.WhatId, new List<Task>{tsk});
            }
        }
        
        System.debug('accountIdToListTaskCompletedMap ' + accountIdToListTaskCompletedMap);
        System.debug('accountIdToListTaskNotCompletedMap ' + accountIdToListTaskNotCompletedMap);
        
        for(Id acctId : forWhatID){
            System.debug('acctId ' + acctId);
            if(accountIdToListTaskCompletedMap.containsKey(acctId)){
            system.debug('acctIdlist' + accountIdToListTaskCompletedMap);
                if(accountIdToListCMOMap.containsKey(acctId)){
                    for(CM__c cMo : accountIdToListCMOMap.get(acctId)){
                        System.debug('cMo ' + cMo);
                        if(coverageIdToListCVMMap.containsKey(cMo.CVR__c)){
                            for(CM__c covMem2 : coverageIdToListCVMMap.get(cMo.CVR__c)){
                                System.debug('covMem2 ' + covMem2);
                                accountsToUpdate.put(covMem2.Account__c, new Account(Id=covMem2.Account__c, PDC__c=true));
                            }
                        }
                        
                    } 
                } 
            }
        
        }
        
        System.debug('accountsToUpdate ' + accountsToUpdate);
        update accountsToUpdate.values();
        
    }
}

 
I have this Custom Object Named Stored XML.

and one of the field stores an XML strings.

<?xml version="1.0" encoding="UTF-8"?><consumers xmlns="http://test.com/feed/">
<SupplyResult>
 <MarketId>xxxxxxxx</MarketId>
 <SupplyList>
    <member>
        <Quantity>9</Quantity>
        <InStock>5</InStock>
        <SellerSKU>Test- 1111</SellerSKU>
    </member>
  </SupplyList>
  </SupplyResult>


How do I parse this and store all the field on on a new Custom Object Named XML Parsed?

Thank you!
How do i fix this issue?

({
    doInit : function(component,event,helper){
        var action = component.get("c.UserCheck");
        action.setParams({
            "currentRecordId" : component.get("v.recordId"),
            "currentUserId" : $A.get("$SObjectType.CurrentUser.Id")
        });
        action.setCallback(this,function(response){
            if(response.getState() == "SUCCESS"){
                //alert("hello there!" + response.getReturnValue()); 
                console.log(response.getReturnValue());
                if(response.getReturnValue()==true){
                    document.getElementById("Modal").setAttribute("style","height:640px;display:block;");
                    console.log(response.getReturnValue());
                }
                else{
                     document.getElementById("Modal").setAttribute("style","height:640px;display:none;");
                }
            }
        })
        $A.enqueueAction(action);
        
          var action2 = component.get("c.getAccount");
         action2.setParams({
            "currentRecordId" : component.get("v.recordId")
        });
        action2.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
               // alert("hello there!" + response.getReturnValue());
                component.set("v.account", response.getReturnValue());
                console.log(response.getReturnValue());
                /*if(response.getReturnValue()==true){
                    document.getElementById("Modal").setAttribute("style","height:640px;display:block;");
                    console.log(response.getReturnValue());
                }
                else{
                     document.getElementById("Modal_Parent").setAttribute("style","height:640px;display:none;");
                }*/
            }
         });
         $A.enqueueAction(action2); 
    
    },

 
var action2 = component.get("c.getAccount");
        action2.setParams({
            "currentRecordId" : component.get("v.recordId")
        });
        action2.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.account", response.getReturnValue());
                console.log(response.getReturnValue());
            }
        });
        $A.enqueueAction(action2);
 
<aura:attribute name="account" type="Account" 
                    default="{ 'sobjectType': 'Account' }"/>
    <aura:attribute name="recordId" type="Id" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <div id="Modal_Parent" style="height:640px; width:1500px;">
        <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <header class="slds-modal__header">
                    <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Modal Test</h2>
                </header>
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                    <p>Display the Name </p>
                    <force:outputField value="{!v.account.Name}"/>
                    {!v.account.Name}
                    <p></p>
                </div>

            </div>
 
@AuraEnabled
    public static List<Account> getAccount(String currentRecordId) {
        System.debug('AccountRecord' + currentRecordId);
        return [select Id, Name from Account where Id =: currentRecordId];
    }

 
I have these class wherein when I create or update the StatusGet__c to Completed it works, wherein it checks the (Indicator1__c)checkbox, and when I create != Completed it Unchecks(Indicator1__c), but my problem is that everytime I craete a new record  != Complete it overrides the checkbox, wherein what I want is that if there is a record StatusGet__c = Completed on the list of record the Indicator1__c will still be checked even if they add records != compelted

public class TaskTriggerHandles{
    public void  getAcct(List<Task> taskacct) {
        List<Account> accountsToUpdate = new List<Account>();
        
        taskacct = [SELECT Id, whatid,StatusGet__c FROM Task WHERE Id IN :taskacct];
        system.debug('taskacct' + taskacct );
        for (Task p : taskacct) {
        if(p.StatusGet__c ==  'Completed ')
           {
                Account a = new Account(
                    Id = p.whatid,
                    Indicator1__c= true);
                
                accountsToUpdate.add(a);
            system.debug('a' + a);
       }
        else if(p.StatusGet__c !=  'Completed')
        {
         Account a = new Account(
                    Id = p.whatid,
                    Indicator1__c= false);
                
                accountsToUpdate.add(a);
            system.debug('a' + a);
        }
        update accountsToUpdate;
        system.debug('accountsToUpdate' + accountsToUpdate);
         }
    }
}

Hey Guys,

 

Im struggling abit with figuring out how to parse some xml into a custom object. Ive been working with the xmlstreamreader example, but I cant quite wrap my head around how step through the xml elements values that I want to insert into my custom object....

 

The xml response Im getting back from my webcallout looks like this:

 

<advertisers type="array">
  <advertiser>
    <id type="integer">7</id>
    <name>ABC Telecom</name>
  </advertiser>
  <advertiser>
    <id type="integer">106</id>
    <name>ABC_Ozone</name>
  </advertiser><advertiser>
    <id type="integer">13</id>
    <name>Acme Corp</name>
  </advertiser>
</advertisers>

 

My goal is loop through this and extract the value of id and name of each advertiser. I would then like to insert the id and name of each advertiser into a custom object. I would use the name field for the name of the advertiser and I have a custom field realationship setup to store the id value.

 

Any help is much appreciated.

  • August 05, 2011
  • Like
  • 0