• Ron08
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Can someone please help with populating nested maps:

I have 2 maps:
map<id, map<id, string>> map1 = new map<id, map<id, string>>();
map<id, map<id, string>> map2 = new map<id, map<id, string>>();

lets say map1 contains values:
outterid1, innerid1, String1
outterid1, innerid1, String2
outterid1, innerid2, String1
outterid2, innerid1, String1

I need populate map2 using values from map1 as below
outterid1, innerid1, String1;String2
outterid1, innerid2, String1
outterid2, innerid1, String1

Thanks.
  • November 20, 2019
  • Like
  • 0
Can anyone help with the below code please, I am able to create the new lead and task however not able to delete the case 
trigger TriggerOnCase on Case (after insert ) {

    list<string> emailsInCase = new List<string>();
    list<lead> leadstoInsert = new List<lead>();
    list<task> TaskToInsert = new list<task>();
    list<case> casetodelete = new List<case>();
    for(case c : trigger.new){
        emailsInCase.add(c.SuppliedEmail);
    }
    
    list<lead> HasLead = [select id, email from lead where email in : emailsInCase];
    //list<contact> Hascontact = [select id, email from contact where email in : emailsInCase];
   
    for(case c1 : trigger.new){
        if((HasLead.size()==0 ) ){
            system.debug('lead'+HasLead.size());
            system.debug('emailsInCase'+emailsInCase);
            system.debug('leadstoInsert'+leadstoInsert);
            lead l = new lead();
            l.Company = 'ggg';
            l.email = c1.suppliedEmail;
            l.LastName = c1.SuppliedName;
            l.OwnerId = '005580000015thg';
            l.Status = 'Open - Not Contacted';
            leadstoInsert.add(l);
            casetodelete.add(c1);
            
        }
        system.debug('lead'+leadstoInsert);
        system.debug('lead'+TaskToInsert);
    }
    insert leadstoInsert;
    for(lead l :leadstoInsert){
        task t = new task();
            t.whoid= l.id;
            t.subject = 'vvv';
            t.status = 'Not started';
            t.Priority = 'Normal';
            t.OwnerId = l.OwnerId;
            TaskToInsert.add(t);
    }
    insert TaskToInsert;
    for(case cas : casetodelete ){ // unable to delete ??
        delete cas;
    }
}

Please help!
Any suggestions on optimisations also welcome!!
Thanks
  • November 04, 2017
  • Like
  • 0
My trigger.oldMap does not seem to return old values if the amount is changed?

Trigger:
trigger TestFunctions on Opportunity (after insert,  after update, after delete, after undelete) {
    if(checkRecursive.runOnce())
    {
    
    if(trigger.isinsert|| trigger.isundelete){
        testFuncClass1.handleInsert(trigger.new);
    }
    if(trigger.isupdate|| trigger.isdelete){
       testFuncClass2.handleupdate(trigger.newmap, trigger.oldmap);
        //system.debug('trigger.oldmap'+trigger.oldmap);
    }
        
    }     
}

Class:
public class testFuncClass2 {
    public static void handleUpdate(map<id, opportunity> updateNewOpps, map<id, opportunity>updateOldOpps){
        if(recusrssionPreventController.flag){

            for(opportunity o : [select id, amount from opportunity where id in : updateNewOpps.keySet()]) {
                system.debug(o);// returns new value
            }  
            for(opportunity o2 : [select id, amount from opportunity where id in : updateOldOpps.keySet()]) {
                system.debug(o2);// returns new value???
            }  
            system.debug(updateNewOpps);//Returns correct values
            system.debug(updateOldOpps);//Returns correct values
            
    }
    }
}

Can anyone please help?
  • October 08, 2017
  • Like
  • 0
I have a trigger on Opps and need to execute some logic if the opp is associated to only one Account Record type. How do I do this?

trigger UpdateTeamMember on Opportunity (After insert, after update) {
    if(trigger.isUpdate){
        for(opportunity o : trigger.new){
            if(o.account.recordtypeid == 'xxxxx') >> does not work?

Any ideas?
  • April 03, 2017
  • Like
  • 1
I have a trigger on Opps and need to execute some logic if the opp is associated to only one Account Record type. How do I do this?

trigger UpdateTeamMember on Opportunity (After insert, after update) {
    if(trigger.isUpdate){
        for(opportunity o : trigger.new){
            if(o.account.recordtypeid == 'xxxxx') >> does not work?

Any ideas?
  • April 03, 2017
  • Like
  • 1
Can anyone help with the below code please, I am able to create the new lead and task however not able to delete the case 
trigger TriggerOnCase on Case (after insert ) {

    list<string> emailsInCase = new List<string>();
    list<lead> leadstoInsert = new List<lead>();
    list<task> TaskToInsert = new list<task>();
    list<case> casetodelete = new List<case>();
    for(case c : trigger.new){
        emailsInCase.add(c.SuppliedEmail);
    }
    
    list<lead> HasLead = [select id, email from lead where email in : emailsInCase];
    //list<contact> Hascontact = [select id, email from contact where email in : emailsInCase];
   
    for(case c1 : trigger.new){
        if((HasLead.size()==0 ) ){
            system.debug('lead'+HasLead.size());
            system.debug('emailsInCase'+emailsInCase);
            system.debug('leadstoInsert'+leadstoInsert);
            lead l = new lead();
            l.Company = 'ggg';
            l.email = c1.suppliedEmail;
            l.LastName = c1.SuppliedName;
            l.OwnerId = '005580000015thg';
            l.Status = 'Open - Not Contacted';
            leadstoInsert.add(l);
            casetodelete.add(c1);
            
        }
        system.debug('lead'+leadstoInsert);
        system.debug('lead'+TaskToInsert);
    }
    insert leadstoInsert;
    for(lead l :leadstoInsert){
        task t = new task();
            t.whoid= l.id;
            t.subject = 'vvv';
            t.status = 'Not started';
            t.Priority = 'Normal';
            t.OwnerId = l.OwnerId;
            TaskToInsert.add(t);
    }
    insert TaskToInsert;
    for(case cas : casetodelete ){ // unable to delete ??
        delete cas;
    }
}

Please help!
Any suggestions on optimisations also welcome!!
Thanks
  • November 04, 2017
  • Like
  • 0
I have a trigger on Opps and need to execute some logic if the opp is associated to only one Account Record type. How do I do this?

trigger UpdateTeamMember on Opportunity (After insert, after update) {
    if(trigger.isUpdate){
        for(opportunity o : trigger.new){
            if(o.account.recordtypeid == 'xxxxx') >> does not work?

Any ideas?
  • April 03, 2017
  • Like
  • 1