• RichardG
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

I have a trigger which enable to verify for each insert if there are yet a Lead or Account with the same mail.

If there is Lead, there are no problem, my trigger run correctly. But when there is already an account, I have an error : 

SearchDoubleAndFusionAccount: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.SearchDoubleAndFusionAccount: line 124, column 1

 

Can I modify an Account just after the insert ? 

 

Here is my trigger :

trigger SearchDoubleAndFusionAccount on Account (after insert) {
    if(checkRecursive.runOnce())
    {
        Set<ID> ids = Trigger.newMap.keySet();
        Set<String> accountMail = new Set<String>();// liste des nouveaux id
        List<Account> updatedAccount = new List<Account>();
        List<Lead> deletedLead = new List<Lead>();
        List<Account> deletedAccount = new List<Account>();
        String demande ='';
        
        for (Account a : trigger.new)// ajout des nouveaux id
        {
            accountMail.add(a.Adresse_mail__c);
            System.debug(a.Adresse_mail__c);
        }
        
        List<Account>accounts = [SELECT Id, Salutation, FirstName , Adresse_mail__c, LastName, Numero_client__c, PersonLeadSource, D_sinscription_la_newsletter__c, Inscription_la_newsletter__c, Raison_de_la_d_sinscription__c, Date_de_d_sinscription_la_newsletter__c, Date_d_inscription_la_newsletter__c   FROM Account];
        List<Lead> leads= [SELECT  Id, Salutation, FirstName , Adresse_mail__c, LastName, Num_ro_piste__c, LeadSource,Phone, Telephone_portable__c, Rating,Type_d_utilisation__c , Origine_connaissance_Kiwatch__c, Client__c, D_sinscription_la_newsletter__c, Inscription_la_newsletter__c, Raison_de_la_d_sinscription__c, Date_de_d_sinscription_la_newsletter__c, Date_d_inscription_la_newsletter__c, Street, City, State, Country, PostalCode  FROM Lead ];
        
        for (Account anew : trigger.new)
        {
            for(Account acc : accounts){
                if(acc.Id == anew.Id)
                {
                    System.debug('Id egal'+ ' '+acc.Id+ ' '+anew.Id);
                }
                else if(acc.Adresse_mail__c ==anew.Adresse_mail__c){
                    System.debug('Email egal'+ ' '+anew.Adresse_mail__c+' '+acc.Id+ ' '+anew.Id);
                    //champs identification du compte (non modifiable)
                    if(acc.Salutation == null){acc.Salutation = anew.Salutation;}
                    if(acc.FirstName == null){acc.FirstName = anew.FirstName;}
                    if(acc.LastName == null){acc.LastName = anew.LastName;}
                    if(acc.Numero_client__c == 0 || acc.Numero_client__c ==null ){acc.Numero_client__c = anew.Numero_client__c;}
                    if(acc.Adresse_mail__c == null){acc.Adresse_mail__c = anew.Adresse_mail__c;}
                    if(acc.PersonLeadSource == null){acc.PersonLeadSource = anew.PersonLeadSource;}
                    
                    
                    //information sur l'adresse. Si un est modifié, tous le sont
                    if(anew.PersonMailingStreet !=null || anew.PersonMailingCity !=null || anew.PersonMailingPostalCode !=null || anew.PersonMailingCountry !=null || anew.PersonMailingState !=null)
                    {
                        acc.PersonMailingStreet = anew.PersonMailingStreet;
                        acc.PersonMailingCity = anew.PersonMailingCity ;
                        acc.PersonMailingPostalCode = anew.PersonMailingPostalCode;
                        acc.PersonMailingCountry = anew.PersonMailingCountry;
                        acc.PersonMailingState = anew.PersonMailingState ;
                    }
                    
                    if(anew.PersonHomePhone !=null){acc .PersonHomePhone = anew.PersonHomePhone ;}
                    if(anew.PersonMobilePhone !=null){acc .PersonMobilePhone =  anew.PersonMobilePhone ;}          
                    if(anew.Rating !=null){acc .Rating = anew.Rating ;}
                    
                    if(anew.Type_d_utilisation__c !=null){acc .Type_d_utilisation__c = anew.Type_d_utilisation__c ;}
                    if(anew.demande__c !=null || anew.Demande_contact__c !=null || anew.Objet_demande__c !=null){
                        acc.demande__c = anew.demande__c;
                        acc.Demande_contact__c = anew.Demande_contact__c;
                        acc.Objet_demande__c = anew.Objet_demande__c;
                        demande = acc.LastName +'a fait une nouvelle demande de contact' + acc.Demande_contact__c+' :'+acc.Objet_demande__c+' '+acc.demande__c;
                        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                        String[] toAddresses = new String[] {'h.broussin@kiwatch.com'}; 
                        mail.setToAddresses(toAddresses); 
                        mail.setSubject('Mise à jour d\'une compte');
                        mail.setPlainTextBody(demande);
                        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                    }
                    

                    //champ relatif à la newsletter
                    if(anew.Inscription_la_newsletter__c == true){
                        if(acc.Inscription_la_newsletter__c == false){
                            acc.Inscription_la_newsletter__c = true;
                            System.debug( acc.Inscription_la_newsletter__c);
                            acc.Date_d_inscription_la_newsletter__c = anew.Date_d_inscription_la_newsletter__c;
                            acc.D_sinscription_la_newsletter__c = false;
                            System.debug('cas1');
                        }
                    }
                    if(anew.D_sinscription_la_newsletter__c == true){
                        if(acc.D_sinscription_la_newsletter__c == false){
                            acc.D_sinscription_la_newsletter__c = true;
                            acc.Date_de_d_sinscription_la_newsletter__c = anew.Date_de_d_sinscription_la_newsletter__c;
                            acc.Raison_de_la_d_sinscription__c = anew.Raison_de_la_d_sinscription__c;
                            acc.Inscription_la_newsletter__c = false;
                            System.debug('cas2');
                         }
                    }
                    
                    //champ concernant l'abonnement
                    if(anew.Date_d_abonnement__c !=null){acc.Date_d_abonnement__c = anew.Date_d_abonnement__c;}
                    if(anew.Date_fin_de_contrat__c !=null){acc.Date_fin_de_contrat__c = anew.Date_fin_de_contrat__c;}
                    if(anew.Raison_fin_de_contrat__c !=null){acc.Raison_fin_de_contrat__c = anew.Raison_fin_de_contrat__c;}
                    if(anew.Abonnement__c !=null){acc.Abonnement__c = anew.Abonnement__c;}
                    if(anew.Date_de_l_abonnement_actuel__c !=null){acc.Date_de_l_abonnement_actuel__c = anew.Date_de_l_abonnement_actuel__c;}
                    
                
                    updatedAccount.add(acc);
                    deletedAccount.add(anew);
                }
            }
              
            for (Lead ld : leads) {
                if(ld.Adresse_mail__c ==anew.Adresse_mail__c){
                    System.debug('Piste existante'+ ' '+anew.Adresse_mail__c+' '+ld.Id+ ' '+anew.Id);

                     //champs identification du compte (non modifiable)
                    if(ld.Salutation != null){anew.Salutation = ld.Salutation;}                  
                    if(ld.FirstName != null){anew.FirstName = ld.FirstName;}
                    if(ld.LastName != null){anew.LastName = ld.LastName;}
                    
                    anew.PersonLeadSource = ld.LeadSource;
                    
                    
                    //information sur l'adresse. Si un est modifié, tous le sont
                    if(anew.PersonMailingStreet ==null && anew.PersonMailingCity ==null && anew.PersonMailingPostalCode ==null && anew.PersonMailingCountry ==null && anew.PersonMailingState ==null)
                    {
                        anew.PersonMailingStreet = ld.Street;
                        anew.PersonMailingCity = ld.City ;
                        anew.PersonMailingPostalCode = ld.PostalCode;
                        anew.PersonMailingCountry = ld.Country;
                        anew.PersonMailingState = ld.State ;
                    }
                    
                    if(anew.PersonHomePhone ==null){anew.PersonHomePhone = ld.Phone ;}
                    if(anew.PersonMobilePhone ==null){anew.PersonMobilePhone =  ld.Telephone_portable__c ;}          
                    if(anew.Rating ==null){anew.Rating = ld.Rating ;}
                    
                    if(anew.Type_d_utilisation__c ==null){anew.Type_d_utilisation__c = ld.Type_d_utilisation__c ;}    
                    
                    //champ relatif à la newsletter
                     if(anew.Inscription_la_newsletter__c == false && anew.D_sinscription_la_newsletter__c == false){
                        if(ld.Inscription_la_newsletter__c == true){
                            anew.Inscription_la_newsletter__c = true;
                            anew.Date_d_inscription_la_newsletter__c = ld.Date_d_inscription_la_newsletter__c;
                            anew.D_sinscription_la_newsletter__c = ld.D_sinscription_la_newsletter__c;
                            anew.Date_de_d_sinscription_la_newsletter__c = ld.Date_de_d_sinscription_la_newsletter__c;
                        }
                    }

                    updatedAccount.add(anew);
                    deletedLead.add(ld);
                }
            }
        }       
        if(updatedAccount.size()>0){
            System.debug('mise à jour compte');
            update updatedAccount;
        }

        if(deletedLead.size()>0){
            for (Lead l : deletedLead){
                System.debug('suppression piste');
                MyFutureClass.DeleteLead(l.Id); 
            }
        }
        if(deletedAccount.size()>0){
            for (Account a : deletedAccount){
                System.debug('suppression compte');
                MyFutureClass.DeleteAccount(a.Id); 
            }
        }
    }
}

 

  • June 28, 2012
  • Like
  • 0

I am trying to install IDE (force.com-ide-installer-win32.exe). First I had some trouble with the proxy settings in pulse explorer. I manage to overcome this. Then the installer stops with an error in forceide.exe:

JVM terminated. Exit code=-1

-Dfile.encoding=UTF-8

-Xms256m

-Xmx1024m

-XX:PermSize=128M

-XX:MaxPermSize=512M

-Djava.class.path=C:\Programme\salesforce.com\Force.com IDE\../Common/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar

-os win32

-ws win32

-arch x86

-showsplash

-launcher C:\Programme\salesforce.com\Force.com IDE\forceide.exe

-name Forceide

--launcher.library C:\Programme\salesforce.com\Force.com

IDE\../Common/plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519\eclipse_1206.dll

-startup C:\Programme\salesforce.com\Force.com IDE\../Common/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar

-install C:\Programme\salesforce.com\Force.com IDE

-configuration C:\Programme\salesforce.com\Force.com IDE\configuration

-clean

-vm C:/Programme/Java/jre6/bin\client\jvm.dll

-vmargs

-Dfile.encoding=UTF-8

-Xms256m

-Xmx1024m

-XX:PermSize=128M

-XX:MaxPermSize=512M

-Djava.class.path=C:\Programme\salesforce.com\Force.com IDE\../Common/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar

 

Any idea how to fix it?

 

Thanks in advance.