-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
11Questions
-
20Replies
automatically export lead/account from salesforce to third party app with rest api
I need to automatically export lead and account (on insert or update) to a third party app, but I can't determine which solution fit perfectly my requirement.
I know there is an outbound messages function that can automatically send messages via soap and I already tested it, but the third party app is rest api only. most of use cases in API documentation talk about processing messages from our app to Salesforce, but not in the other way!
what is the best solution to do that?
- alexj
- November 08, 2016
- Like
- 0
Test which execute two triggers
I want to know if a test method can execute two triggers.
My test class should test a trigger after insert lead but to test this, i should insert account and i have a trigger after insert account too.
I feel that only the first trigger run.
Can you help me to understand ?
- alexj
- July 17, 2012
- Like
- 0
test trigger after insert Lead and Account
Is it possible to call two trigger on a test ?
My problem is that I must insert account to test my trigger after insert Lead and I have too a trigger after insert account.
When I test my class, the first trigger is tested but not the second and my code isn't correctly covered.
How can I not run trigger for the insert of account which is just initialization and run the trigger for the insert of lead ?
- alexj
- July 06, 2012
- Like
- 0
Problem with test trigger
I have created a trigger with test a trigger after insert.
The problem is that the trigger run on the initialization of leads and accounts and don't run on insert which is between test.startTest et test.stopTest.
@isTest public class TestinsertLead { static testMethod void TestInsertListLead(){ //initialisation des variables List <Lead> ld = new List<Lead>(); List <Account> acc = new List<Account>(); for(integer i = 0; i<2; i++){ Lead lead = new Lead( Salutation = 'M.', FirstName ='Hélène', LastName = 'test', Adresse_mail__c = 'test'+i+'@mail.com',//test0@mail.com, test1@mail.com LeadSource = 'Newsletter', Origine_connaissance_Kiwatch__c ='', Num_ro_piste__c = 0, demande__c = 'par mail', Demande_contact__c = 'demande', Objet_demande__c = 'objet'); ld.add(lead); } for(integer i = 2; i<4; i++){ Account account= new Account( Salutation = '', FirstName ='', LastName = 'test', Adresse_mail__c = 'test'+i+'@mail.com',//test2@mail.com, test3@mail.com PersonLeadSource = 'Newsletter', Numero_client__c = 0, Demande_contact__c = 'sdkljfqsd', Objet_demande__c = 'sdfklsqfdkjs', Raison_fin_de_contrat__c ='', Abonnement__c='Pro'); acc.add(account); } insert ld;System.debug('insert of init leads ok'); insert acc;System.debug('insert of init accounts ok'); //début du test Test.startTest(); List <Lead> newLeads= new List<Lead>(); for(integer i = 1; i<3; i++){ Lead lead = new Lead( Salutation = 'M.', FirstName ='Hélène', LastName = 'test', Adresse_mail__c = 'test'+i+'@mail.com',//test1@mail.com, test2@mail.com LeadSource = 'Newsletter', Origine_connaissance_Kiwatch__c ='', Num_ro_piste__c = 0, demande__c = 'par mail', Demande_contact__c = 'demande', Objet_demande__c = 'objet'); newLeads.add(lead); } insert newLeads;System.debug('insert of test leads ok'); Test.stopTest() ; } }
When I display debug, I see :
|DEBUG|insert piste : test0@mail.com |DEBUG|insert piste : test1@mail.com |DEBUG|insert of init leads ok |DEBUG|insert of init accounts ok |DEBUG|insert of test leads ok
- alexj
- July 05, 2012
- Like
- 0
test trigger after insert Lead and Account
I have created two triggers to manage the double between Lead and Account (SearchDoubleAndFusionLead and SearchDoubleAndFusionAccount). The two triggers are similar and run correctly.
I have to cover triggers with test class to deploy my test on my prod.
I have write a test class (TestSearchDoubleAndFusion) to test thes trigger. On this class I insert leads and accounts with the same email what it run triggers.
I feel that the test run only the first insert and doesn't consider the case where I insert a account while there are already a lead with the same email and vice versa.
I feel that it run trigger for inserts out of start.Test and stopTest but not for the inserts between.
Below one of trigger and the test
trigger SearchDoubleAndFusionLead on Lead (after insert) { if(checkRecursive.runOnce()) { Set<ID> ids = Trigger.newMap.keySet(); Set<String> leadmail = new Set<String>(); List<Lead> updatedLead = new List<Lead>(); List<Account> updatedAccount = new List<Account>(); List<Lead> deletedLead = new List<Lead>(); String demande =''; boolean existingAccount = false; String URL = ' https://cs16.salesforce.com/'; for (Lead l : trigger.new)// ajout des nouveaux id { leadmail .add(l.Adresse_mail__c); System.debug(l.Adresse_mail__c); } //récupération pistes et comptes existants List<Lead> leads = [SELECT ... from Lead]; List<Account>accounts = [SELECT ... FROM Account] ; existingAccount = false; for (Lead lnew : trigger.new) { if(lnew.demande__c !=null || lnew.Demande_contact__c !=null || lnew.Objet_demande__c !=null){ demande = lnew.Salutation+' '+lnew.FirstName+' '+ lnew.LastName +' a fait une nouvelle demande de contact ' + lnew.Demande_contact__c+' : \n'+lnew.Objet_demande__c+'\n'+lnew.demande__c+' \n'+URL +lnew.Id; } for(Account acc : accounts) { if(acc .Adresse_mail__c == lnew.Adresse_mail__c){ existingAccount = true; System.debug('compte existant'); //champs identification de la piste (non modifiable) if(acc.Salutation == null){acc.Salutation = lnew.Salutation;} if(acc.FirstName == null){acc.FirstName = lnew.FirstName;} if(acc.LastName == null){acc.LastName = lnew.LastName;} if(acc.Adresse_mail__c == null){acc.Adresse_mail__c = lnew.Adresse_mail__c;} //information sur l'adresse. Si un est modifié, tous le sont if(lnew.Street !=null || lnew.City !=null || lnew.PostalCode !=null || lnew.Country !=null || lnew.State !=null) { acc.PersonMailingStreet = lnew.Street; acc.PersonMailingCity = lnew.City ; acc.PersonMailingPostalCode = lnew.PostalCode; acc.PersonMailingCountry = lnew.Country; acc.PersonMailingState = lnew.State ; } if(lnew.Phone !=null){acc.PersonHomePhone = lnew.Phone ;} if(lnew.Telephone_portable__c !=null){acc .PersonMobilePhone = lnew.Telephone_portable__c ;} if(lnew.Rating !=null){acc .Rating = lnew.Rating ;} if(lnew.Company ==null){acc.Soci_t__c = lnew.Company;} if(lnew.Type_d_utilisation__c !=null){acc .Type_d_utilisation__c = lnew.Type_d_utilisation__c ;} if(lnew.locataire__c !=null){acc.locataire__c = lnew.locataire__c;} if(lnew.proprietaire__c !=null){acc.proprietaire__c = lnew.proprietaire__c;} if(lnew.demande__c !=null || lnew.Demande_contact__c !=null || lnew.Objet_demande__c !=null){ acc.demande__c = lnew.demande__c; acc.Demande_contact__c = lnew.Demande_contact__c; acc.Objet_demande__c = lnew.Objet_demande__c; demande = acc.Salutation+' '+acc.FirstName+' '+ acc.LastName +' a fait une nouvelle demande de contact ' + acc.Demande_contact__c+' : \n'+acc.Objet_demande__c+'\n'+acc.demande__c+'\n'+URL +acc.Id; } //champ relatif à la newsletter if(lnew.Inscription_la_newsletter__c == true){ if(acc.Inscription_la_newsletter__c == false){ acc.Inscription_la_newsletter__c = true; acc.Date_d_inscription_la_newsletter__c = lnew.Date_d_inscription_la_newsletter__c; acc.D_sinscription_la_newsletter__c = false; } } if(lnew.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 = lnew.Date_de_d_sinscription_la_newsletter__c; acc.Raison_de_la_d_sinscription__c = lnew.Raison_de_la_d_sinscription__c; acc.Inscription_la_newsletter__c = false; } } //champ relatif au jeu : pas de mise à jour possible if(acc.accept_jeux__c == false && lnew.accepte_jeux__c == true){ acc.accept_jeux__c= lnew.accepte_jeux__c; acc.Date_inscription_au_jeu__c = lnew.Date_inscription_au_jeu__c; acc.Email_parr__c = lnew.Email_parr__c; acc.Email_parrainage_2__c = lnew.Email_parrainage_2__c; acc.Email_parrainage_3__c = lnew.Email_parrainage_3__c; acc.Email_parrainage_4__c = lnew.Email_parrainage_4__c; acc.Email_parrainage_5__c = lnew.Email_parrainage_5__c; } updatedAccount.add(acc); deletedLead.add(lnew); } } for (Lead ld : leads) { if(ld.Id == lnew.Id) { System.debug('Id egal'+ ' '+ld.Id+ ' '+lnew.Id); } else if(ld.Adresse_mail__c == lnew.Adresse_mail__c) { System.debug('piste existante'+ ld.Adresse_mail__c+ ' '+ld.Id+ ' '+lnew.Id); if(!existingAccount){ if(ld.Salutation == null){ld.Salutation = lnew.Salutation;} if(ld.FirstName == null){ld.FirstName = lnew.FirstName;} if(ld.LastName == null){ld.LastName = lnew.LastName;} if(ld.Num_ro_piste__c == 0 || ld.Num_ro_piste__c ==null ){ld.Num_ro_piste__c = lnew.Num_ro_piste__c;} if(ld.Adresse_mail__c == null){ld.Adresse_mail__c = lnew.Adresse_mail__c;} //if(ld.LeadSource == null){ld.LeadSource = lnew.LeadSource;} if(ld.Client__c == null){ld.Client__c = lnew.Client__c;} //information sur l'adresse. Si un est modifié, tous le sont if(lnew.Street !=null || lnew.City !=null || lnew.PostalCode !=null || lnew.Country !=null || lnew.State !=null) { ld .Street = lnew.Street; ld .City = lnew.City ; ld .PostalCode = lnew.PostalCode; ld .Country = lnew.Country; ld .State = lnew.State ; } if(lnew.Phone !=null){ld .Phone = lnew.Phone ;} if(lnew.Telephone_portable__c !=null){ld .Telephone_portable__c = lnew.Telephone_portable__c ;} if(lnew.Rating !=null){ld .Rating = lnew.Rating ;} if(lnew.Status !=null){ld .Status = lnew.Status ;} if(lnew.Company !=null){ld.Company = lnew.Company ;} if(lnew.Type_d_utilisation__c !=null){ld .Type_d_utilisation__c = lnew.Type_d_utilisation__c ;} if(lnew.locataire__c !=null){ld.locataire__c = lnew.locataire__c;} if(lnew.proprietaire__c !=null){ld.proprietaire__c = lnew.proprietaire__c;} if(lnew.videosurveillance__c !=null){ld.videosurveillance__c = lnew.videosurveillance__c;} if(lnew.pas_de_systeme__c !=null){ld.pas_de_systeme__c = lnew.pas_de_systeme__c;} if(lnew.alarme__c !=null){ld.alarme__c = lnew.alarme__c;} if(lnew.alarme_et_videosurveillance__c !=null){ld.alarme_et_videosurveillance__c = lnew.alarme_et_videosurveillance__c;} if(lnew.demande__c !=null || lnew.Demande_contact__c !=null || lnew.Objet_demande__c !=null){ ld.demande__c = lnew.demande__c; ld.Demande_contact__c = lnew.Demande_contact__c; ld.Objet_demande__c = lnew.Objet_demande__c; System.debug('ld '+ld.Id+' lnew '+lnew.Id); demande = ld.Salutation+' '+ld.FirstName+' '+ ld.LastName +' a fait une nouvelle demande de contact ' + ld.Demande_contact__c+' :\n'+ld.Objet_demande__c+'\n'+ld.demande__c+'\n'+URL +ld.Id; } //champ relatif à la newsletter if(lnew.Inscription_la_newsletter__c == true){ if(ld.Inscription_la_newsletter__c == false){ ld.Inscription_la_newsletter__c = true; System.debug( ld.Inscription_la_newsletter__c); ld.Date_d_inscription_la_newsletter__c = lnew.Date_d_inscription_la_newsletter__c; ld.D_sinscription_la_newsletter__c = false; } } else if(lnew.D_sinscription_la_newsletter__c == true){ if(ld.D_sinscription_la_newsletter__c == false){ ld.D_sinscription_la_newsletter__c = true; ld.Date_de_d_sinscription_la_newsletter__c = lnew.Date_de_d_sinscription_la_newsletter__c; ld.Raison_de_la_d_sinscription__c = lnew.Raison_de_la_d_sinscription__c; ld.Inscription_la_newsletter__c = false; } } // System.debug('mise à jour nl'); //champ relatif au jeu : pas de mise à jour possible if(ld.accepte_jeux__c == false && lnew.accepte_jeux__c == true){ ld.accepte_jeux__c = lnew.accepte_jeux__c; ld.Date_inscription_au_jeu__c = lnew.Date_inscription_au_jeu__c; ld.Email_parr__c = lnew.Email_parr__c; ld.Email_parrainage_2__c = lnew.Email_parrainage_2__c; ld.Email_parrainage_3__c = lnew.Email_parrainage_3__c; ld.Email_parrainage_4__c = lnew.Email_parrainage_4__c; ld.Email_parrainage_5__c = lnew.Email_parrainage_5__c; } updatedLead.add(ld); deletedLead.add(lnew); } else deletedLead.add(ld); } } if(lnew.demande__c !=null || lnew.Demande_contact__c !=null || lnew.Objet_demande__c !=null){ System.debug(demande); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {'h.broussin@kiwatch.com'}; mail.setToAddresses(toAddresses); mail.setSubject('Demande de contact'); mail.setPlainTextBody(demande); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } if(updatedLead.size()>0){ System.debug('mise à jour'); update updatedLead; } if(updatedAccount.size()>0){ System.debug('mise à jour compte'); update updatedAccount; } if(deletedLead.size()>0){ for (Lead l : deletedLead){ System.debug(l.Id); MyFutureClass.DeleteLead(l.Id); } } } }
public class TestSearchDoubleAndFusion { static testMethod void TestInsertListLead(){ System.debug('insert leads'); List <Lead> ld = new List<Lead>(); for(integer i = 0; i<2; i++){ Lead lnew = new Lead( Salutation = '', FirstName ='', LastName = 'test', Adresse_mail__c = 'test@mail.com', LeadSource = 'Newsletter', Origine_connaissance_Kiwatch__c ='', Num_ro_piste__c = 0, Client__c = false, accepte_jeux__c = true, Email_parr__c = 'h.broussin@kiwatch.com', Email_parrainage_2__c = '', Email_parrainage_3__c = '', Email_parrainage_4__c = '', Email_parrainage_5__c = '', Street = '39, rue des étoiles', City = 'laval', State = 'pays de loire', PostalCode = '53000', Country = 'france', Phone = '0900000000', Telephone_portable__c = '070809101112', Rating = 'Froid', Status = 'En cours', Inscription_la_newsletter__c = true, D_sinscription_la_newsletter__c = false, Raison_de_la_d_sinscription__c = '', locataire__c = true, proprietaire__c = false, alarme__c = false, videosurveillance__c = false, alarme_et_videosurveillance__c = false, pas_de_systeme__c = true, Type_d_utilisation__c = 'Pro', demande__c = 'par tel', Demande_contact__c = 'gfsdf', Objet_demande__c = 'sdf'); ld.add(lnew); } insert ld; System.debug('lead correctement insérer'); Account a = new Account( Salutation = '', FirstName ='', LastName = 'test', Adresse_mail__c = 'test@mail.com', PersonLeadSource = 'Newsletter', Numero_client__c = 0, PersonMailingStreet = '39, rue des étoiles', PersonMailingCity = 'laval', PersonMailingState = 'pays de loire', PersonMailingPostalCode = '53000', PersonMailingCountry = 'france', PersonHomePhone = '0900000000', PersonMobilePhone = '070809101112', Rating = 'Froid', Inscription_la_newsletter__c = false, D_sinscription_la_newsletter__c = false, Raison_de_la_d_sinscription__c = '', Type_d_utilisation__c = 'Pro', demande__c = 'par mail', Demande_contact__c = 'sdkljfqsd', Objet_demande__c = 'sdfklsqfdkjs', Raison_fin_de_contrat__c ='', Abonnement__c='Pro'); test.startTest(); System.debug('debut test'); insert a; System.debug('compte insérer'); test.stopTest(); } static testMethod void TestInsertListAccount(){ System.debug('insert accounts'); List <Account> acc = new List<Account>(); for(integer i = 0; i<2; i++){ Account anew = new Account( Salutation = '', FirstName ='', LastName = 'test', Adresse_mail__c = 'test@mail.com', PersonLeadSource = 'Newsletter', Numero_client__c = 0, PersonMailingStreet = '39, rue des étoiles', PersonMailingCity = 'laval', PersonMailingState = 'pays de loire', PersonMailingPostalCode = '53000', PersonMailingCountry = 'france', PersonHomePhone = '0900000000', PersonMobilePhone = '070809101112', Rating = 'Froid', Inscription_la_newsletter__c = false, D_sinscription_la_newsletter__c = false, Raison_de_la_d_sinscription__c = '', Type_d_utilisation__c = 'Pro', demande__c = 'par mail', Demande_contact__c = 'sdkljfqsd', Objet_demande__c = 'sdfklsqfdkjs', Raison_fin_de_contrat__c ='', Abonnement__c='Pro'); acc.add(anew); } insert acc; Lead l = new Lead( Salutation = '', FirstName ='', LastName = 'test', Adresse_mail__c = 'test@mail.com', LeadSource = 'Newsletter', Origine_connaissance_Kiwatch__c ='', Num_ro_piste__c = 0, Client__c = false, accepte_jeux__c = true, // Date_inscription_au_jeu__c = , Email_parr__c = 'h.broussin@kiwatch.com', Email_parrainage_2__c = '', Email_parrainage_3__c = '', Email_parrainage_4__c = '', Email_parrainage_5__c = '', Street = '39, rue des étoiles', City = 'laval', State = 'pays de loire', PostalCode = '53000', Country = 'france', Phone = '0900000000', Telephone_portable__c = '070809101112', Rating = 'Froid', Status = 'En cours', Inscription_la_newsletter__c = true, D_sinscription_la_newsletter__c = false, Raison_de_la_d_sinscription__c = '', locataire__c = true, proprietaire__c = false, alarme__c = false, videosurveillance__c = false, alarme_et_videosurveillance__c = false, pas_de_systeme__c = true, Type_d_utilisation__c = 'Pro', demande__c = 'par tel', Demande_contact__c = 'gfsdf', Objet_demande__c = 'sdf'); test.startTest(); System.debug('debut test'); insert l; System.debug('lead insérer'); test.stopTest(); } }
- alexj
- July 04, 2012
- Like
- 0
System.FinalException: Record is read-only
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); } } } }
- alexj
- June 28, 2012
- Like
- 0
cannot operate on trigger.new or trigger.old
Hi,
I try to create an trigger which verify before the insert of lead if there has already a lead with the same mail. It is the case, I update the "old" lead and I delete the lead which would be created.
I have an error when I try to delete :
SearchDoubleAndFusion: execution of BeforeInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old: Trigger.SearchDoubleAndFusion: line 48, column 1
How can I delete this lead ?
trigger SearchDoubleAndFusion on Lead (before insert, before update) { if(checkRecursive.runOnce()) { Set<String> leadmail = new Set<String>();// liste des nouveaux id List<Lead> updatedLead = new List<Lead>(); List<Lead> deletedLead = new List<Lead>(); for (Lead l : trigger.new)// ajout des nouveaux id { leadmail .add(l.Adresse_mail__c); System.debug(l.Adresse_mail__c); } List<Lead> leads = [SELECT Id, Salutation, FirstName , Adresse_mail__c, LastName, Num_ro_piste__c from Lead /*where id in: leadId*/]; for (Lead lnew : trigger.new) { for (Lead ld : leads) { if(ld.Id == lnew.Id) { System.debug('Id egal'+ ' '+ld.Id+ ' '+lnew.Id); } else if(ld.Adresse_mail__c == lnew.Adresse_mail__c) { System.debug('mail egal'+ ld.Adresse_mail__c+ ' '+ld.Id+ ' '+lnew.Id); if(ld.Salutation == null){ld.Salutation = lnew.Salutation;} if(ld.FirstName == null){ld.FirstName = lnew.FirstName;} if(ld.LastName == null){ld.LastName = lnew.LastName;} if(ld.Num_ro_piste__c == 0 || ld.Num_ro_piste__c ==null ){ld.Num_ro_piste__c = lnew.Num_ro_piste__c;} if(ld.Adresse_mail__c == null){ld.Adresse_mail__c = lnew.Adresse_mail__c;} if(ld.LeadSource == null){ld.LeadSource = lnew.LeadSource;} if(ld.Client__c == null){ld.Client__c = lnew.Client__c;} if(ld.Origine_connaissance_Kiwatch__c == null){ld.Origine_connaissance_Kiwatch__c = lnew.Origine_connaissance_Kiwatch__c;} updatedLead.add(ld); deletedLead.add(lnew); } } } if(updatedLead.size()>0){ System.debug('mise à jour'); update updatedLead; } if(deletedLead.size()>0){ System.debug('mise à jour'); delete deletedLead; } } }
- alexj
- June 26, 2012
- Like
- 0
System.FinalException: Record is read-only
Hi
I have created an apex class to verify if there is a new account isn't on the lead and if it's the case, I retrieve the value of the lead to update my account.
But when I try an exemple, I have an error : System.FinalException: Record is read-only
My apex class is :
//mise à jour de compte si doublons global class VerifNoLead implements Database.Batchable<sObject> { global final String query; global final Account compte; global VerifNoLead (String q, Account ld) { query = q; compte= ld; } global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<sObject> scope){ for(sObject s : scope){ Lead leadO = (Lead)s; //champs identification du compte (non modifiable) if(leadO.Salutation != null){compte.Salutation = leadO.Salutation;} System.debug(compte.Salutation); if(leadO.FirstName != null){compte.FirstName = leadO.FirstName;} if(leadO.LastName != null){compte.LastName = leadO.LastName;} compte.PersonLeadSource = leadO.LeadSource; //information sur l'adresse. Si un est modifié, tous le sont if(compte.PersonMailingStreet ==null && compte.PersonMailingCity ==null && compte.PersonMailingPostalCode ==null && compte.PersonMailingCountry ==null && compte.PersonMailingState ==null) { compte.PersonMailingStreet = leadO.Street; compte.PersonMailingCity = leadO.City ; compte.PersonMailingPostalCode = leadO.PostalCode; compte.PersonMailingCountry = leadO.Country; compte.PersonMailingState = leadO.State ; } if(compte.PersonHomePhone ==null){compte.PersonHomePhone = leadO.Phone ;} if(compte.PersonMobilePhone ==null){compte.PersonMobilePhone = leadO.Telephone_portable__c ;} if(compte.Rating ==null){compte.Rating = leadO.Rating ;} if(compte.Type_d_utilisation__c ==null){compte.Type_d_utilisation__c = leadO.Type_d_utilisation__c ;} //champ relatif à la newsletter if(compte.Inscription_la_newsletter__c == false && compte.D_sinscription_la_newsletter__c == false){ if(leadO.Inscription_la_newsletter__c == true){ compte.Inscription_la_newsletter__c = true; compte.Date_d_inscription_la_newsletter__c = leadO.Date_d_inscription_la_newsletter__c; compte.D_sinscription_la_newsletter__c = leadO.D_sinscription_la_newsletter__c; compte.Date_de_d_sinscription_la_newsletter__c = leadO.Date_de_d_sinscription_la_newsletter__c; } } //System.debug(compte.Id); if(compte.Id != null){update compte;System.debug('mise à jour ok'); } else {System.debug ('erreur compte');} if(leadO.Id != null){delete leadO; System.debug('leadO.id !=null');} else{System.debug('erreur leadO');} } } global void finish(Database.BatchableContext BC){ System.debug('fini'); } public static testmethod void testVerifNoLead (){ List <Lead> ld = new List<Lead>(); for(integer i = 0; i<2; i++){ Lead l = new Lead(Adresse_mail__c='test'+i+'@mail.com',LastName='test', Inscription_la_newsletter__c =true); ld.add(l); } insert ld; Test.startTest() ; Account lnew = new Account( Salutation = 'M.', FirstName ='Hélène', LastName = 'test', Adresse_mail__c = 'test1@mail.com', PersonLeadSource = 'Newsletter', // Origine_connaissance_Kiwatch__c ='', Numero_client__c = 0, /*accepte_jeux__c = true, Date_inscription_au_jeu__c = , Email_parr__c = 'h.broussin@kiwatch.com', Email_parrainage_2__c = '', Email_parrainage_3__c = '', Email_parrainage_4__c = '', Email_parrainage_5__c = '',*/ // PersonMailingStreet = '',//'39, rue des étoiles', // PersonMailingCity = '',//'laval', // PersonMailingState = '',//'pays de loire', // PersonMailingPostalCode = '',//'53000', // PersonMailingCountry = '',//'france', PersonHomePhone = '0900000000', PersonMobilePhone = '070809101112', Rating = 'Froid', // Date_d_inscription_la_newsletter__c = '29/05/2012', // Date_de_d_sinscription_la_newsletter__c = '', Inscription_la_newsletter__c = false, D_sinscription_la_newsletter__c = false, Raison_de_la_d_sinscription__c = '', /*locataire__c = true, proprietaire__c = false, alarme__c = false, videosurveillance__c = false, alarme_et_videosurveillance__c = false, pas_de_systeme__c = true,*/ Type_d_utilisation__c = 'Pro', demande__c = '', Demande_contact__c = '', Objet_demande__c = '', //Date_d_abonnement__c, //Date_fin_de_contrat__c, Raison_fin_de_contrat__c ='', //Date_de_l_abonnement_actuel__c, Abonnement__c='Pro'); String query = 'SELECT Salutation, FirstName , Adresse_mail__c, LastName, Num_ro_piste__c, LeadSource, 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, Phone, Telephone_portable__c FROM Lead WHERE Adresse_mail__c=\'' + lnew.Adresse_mail__c + '\' LIMIT 2'; VerifNoLead batchApex = new VerifNoLead(query, lnew ); ID batchprocessid = Database.executeBatch(batchApex); Test.StopTest(); } }
and my trigger :
trigger RechercheDoubleCompte on Account(after insert) { for (Account a : Trigger.new) { String query = 'SELECT 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 WHERE Adresse_mail__c=\'' + a.Adresse_mail__c + '\' AND Id!=\'' + a.Id + '\' LIMIT 100'; String query2 = 'SELECT 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 WHERE Adresse_mail__c=\'' + a.Adresse_mail__c + '\' LIMIT 100'; UpdateFieldAccount batchApex = new UpdateFieldAccount(query, a ); ID batchprocessid = Database.executeBatch(batchApex); VerifNoLead batchApex2 = new VerifNoLead(query2, a ); ID batchprocessid2 = Database.executeBatch(batchApex2); } }
- alexj
- June 04, 2012
- Like
- 0
no perspective force.com
Hi,
I have install eclipse Version: 3.4.2 and the plugin force.com
But I can't find the Perspective
I have add the path to the file eclipse.ini :
org.eclipse.platform
--launcher.XXMaxPermSize
256M
-framework
plugins\org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx256m
-vm
C:\Program Files\Java\jre7\bin\javaw.exe
But there is no changement
- alexj
- May 30, 2012
- Like
- 0
deployement from sandbox to production
Hi, I have developped an appex class with this test class. My code is correctly covered and the work suits me. I would like deploy this class on my production.The developpment is on my sandbox.
I haven't found a clear documentation about deployement from sandbox to production. what is the different steps?
Thank you for your help,
- alexj
- May 29, 2012
- Like
- 0
problem with class batch
Hi,
I have a problem with Batch class. Yesterday my class run correctly but I don't know what change I have do and that can't execute correctly.
My problem is that the fonction execute isn't realize and i don't understand why.
I have create a simple class to understand but it the same problem.
Below, my class and the result of test.
Code Coverage BatchDelete (Code Covered: 75%)
global class BatchDelete implements Database.Batchable<sObject> {
public String query; global BatchDelete(String q){
query=q;
}
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
delete scope;
System.debug('fin execution');
}
global void finish(Database.BatchableContext BC){
}
public static testMethod void testBathDelete(){
List <Lead> ld = new List<Lead>();
for(integer i = 0; i<3; i++){
Lead l = new Lead(Adresse_mail__c='testLead'+i+'@mail.com',LastName='nouveauprenom');
ld.add(l);
}
insert ld;
Test.StartTest();
String q= 'SELECT ID, Name FROM Account LIMIT 3';
BatchDelete BD = new BatchDelete(q);
ID batchprocessid = Database.executeBatch(BD);
Test.StopTest();
}
}
- alexj
- April 25, 2012
- Like
- 0
test trigger after insert Lead and Account
Is it possible to call two trigger on a test ?
My problem is that I must insert account to test my trigger after insert Lead and I have too a trigger after insert account.
When I test my class, the first trigger is tested but not the second and my code isn't correctly covered.
How can I not run trigger for the insert of account which is just initialization and run the trigger for the insert of lead ?
- alexj
- July 06, 2012
- Like
- 0
Problem with test trigger
I have created a trigger with test a trigger after insert.
The problem is that the trigger run on the initialization of leads and accounts and don't run on insert which is between test.startTest et test.stopTest.
@isTest public class TestinsertLead { static testMethod void TestInsertListLead(){ //initialisation des variables List <Lead> ld = new List<Lead>(); List <Account> acc = new List<Account>(); for(integer i = 0; i<2; i++){ Lead lead = new Lead( Salutation = 'M.', FirstName ='Hélène', LastName = 'test', Adresse_mail__c = 'test'+i+'@mail.com',//test0@mail.com, test1@mail.com LeadSource = 'Newsletter', Origine_connaissance_Kiwatch__c ='', Num_ro_piste__c = 0, demande__c = 'par mail', Demande_contact__c = 'demande', Objet_demande__c = 'objet'); ld.add(lead); } for(integer i = 2; i<4; i++){ Account account= new Account( Salutation = '', FirstName ='', LastName = 'test', Adresse_mail__c = 'test'+i+'@mail.com',//test2@mail.com, test3@mail.com PersonLeadSource = 'Newsletter', Numero_client__c = 0, Demande_contact__c = 'sdkljfqsd', Objet_demande__c = 'sdfklsqfdkjs', Raison_fin_de_contrat__c ='', Abonnement__c='Pro'); acc.add(account); } insert ld;System.debug('insert of init leads ok'); insert acc;System.debug('insert of init accounts ok'); //début du test Test.startTest(); List <Lead> newLeads= new List<Lead>(); for(integer i = 1; i<3; i++){ Lead lead = new Lead( Salutation = 'M.', FirstName ='Hélène', LastName = 'test', Adresse_mail__c = 'test'+i+'@mail.com',//test1@mail.com, test2@mail.com LeadSource = 'Newsletter', Origine_connaissance_Kiwatch__c ='', Num_ro_piste__c = 0, demande__c = 'par mail', Demande_contact__c = 'demande', Objet_demande__c = 'objet'); newLeads.add(lead); } insert newLeads;System.debug('insert of test leads ok'); Test.stopTest() ; } }
When I display debug, I see :
|DEBUG|insert piste : test0@mail.com |DEBUG|insert piste : test1@mail.com |DEBUG|insert of init leads ok |DEBUG|insert of init accounts ok |DEBUG|insert of test leads ok
- alexj
- July 05, 2012
- Like
- 0
System.FinalException: Record is read-only
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); } } } }
- alexj
- June 28, 2012
- Like
- 0
cannot operate on trigger.new or trigger.old
Hi,
I try to create an trigger which verify before the insert of lead if there has already a lead with the same mail. It is the case, I update the "old" lead and I delete the lead which would be created.
I have an error when I try to delete :
SearchDoubleAndFusion: execution of BeforeInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old: Trigger.SearchDoubleAndFusion: line 48, column 1
How can I delete this lead ?
trigger SearchDoubleAndFusion on Lead (before insert, before update) { if(checkRecursive.runOnce()) { Set<String> leadmail = new Set<String>();// liste des nouveaux id List<Lead> updatedLead = new List<Lead>(); List<Lead> deletedLead = new List<Lead>(); for (Lead l : trigger.new)// ajout des nouveaux id { leadmail .add(l.Adresse_mail__c); System.debug(l.Adresse_mail__c); } List<Lead> leads = [SELECT Id, Salutation, FirstName , Adresse_mail__c, LastName, Num_ro_piste__c from Lead /*where id in: leadId*/]; for (Lead lnew : trigger.new) { for (Lead ld : leads) { if(ld.Id == lnew.Id) { System.debug('Id egal'+ ' '+ld.Id+ ' '+lnew.Id); } else if(ld.Adresse_mail__c == lnew.Adresse_mail__c) { System.debug('mail egal'+ ld.Adresse_mail__c+ ' '+ld.Id+ ' '+lnew.Id); if(ld.Salutation == null){ld.Salutation = lnew.Salutation;} if(ld.FirstName == null){ld.FirstName = lnew.FirstName;} if(ld.LastName == null){ld.LastName = lnew.LastName;} if(ld.Num_ro_piste__c == 0 || ld.Num_ro_piste__c ==null ){ld.Num_ro_piste__c = lnew.Num_ro_piste__c;} if(ld.Adresse_mail__c == null){ld.Adresse_mail__c = lnew.Adresse_mail__c;} if(ld.LeadSource == null){ld.LeadSource = lnew.LeadSource;} if(ld.Client__c == null){ld.Client__c = lnew.Client__c;} if(ld.Origine_connaissance_Kiwatch__c == null){ld.Origine_connaissance_Kiwatch__c = lnew.Origine_connaissance_Kiwatch__c;} updatedLead.add(ld); deletedLead.add(lnew); } } } if(updatedLead.size()>0){ System.debug('mise à jour'); update updatedLead; } if(deletedLead.size()>0){ System.debug('mise à jour'); delete deletedLead; } } }
- alexj
- June 26, 2012
- Like
- 0
System.FinalException: Record is read-only
Hi
I have created an apex class to verify if there is a new account isn't on the lead and if it's the case, I retrieve the value of the lead to update my account.
But when I try an exemple, I have an error : System.FinalException: Record is read-only
My apex class is :
//mise à jour de compte si doublons global class VerifNoLead implements Database.Batchable<sObject> { global final String query; global final Account compte; global VerifNoLead (String q, Account ld) { query = q; compte= ld; } global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<sObject> scope){ for(sObject s : scope){ Lead leadO = (Lead)s; //champs identification du compte (non modifiable) if(leadO.Salutation != null){compte.Salutation = leadO.Salutation;} System.debug(compte.Salutation); if(leadO.FirstName != null){compte.FirstName = leadO.FirstName;} if(leadO.LastName != null){compte.LastName = leadO.LastName;} compte.PersonLeadSource = leadO.LeadSource; //information sur l'adresse. Si un est modifié, tous le sont if(compte.PersonMailingStreet ==null && compte.PersonMailingCity ==null && compte.PersonMailingPostalCode ==null && compte.PersonMailingCountry ==null && compte.PersonMailingState ==null) { compte.PersonMailingStreet = leadO.Street; compte.PersonMailingCity = leadO.City ; compte.PersonMailingPostalCode = leadO.PostalCode; compte.PersonMailingCountry = leadO.Country; compte.PersonMailingState = leadO.State ; } if(compte.PersonHomePhone ==null){compte.PersonHomePhone = leadO.Phone ;} if(compte.PersonMobilePhone ==null){compte.PersonMobilePhone = leadO.Telephone_portable__c ;} if(compte.Rating ==null){compte.Rating = leadO.Rating ;} if(compte.Type_d_utilisation__c ==null){compte.Type_d_utilisation__c = leadO.Type_d_utilisation__c ;} //champ relatif à la newsletter if(compte.Inscription_la_newsletter__c == false && compte.D_sinscription_la_newsletter__c == false){ if(leadO.Inscription_la_newsletter__c == true){ compte.Inscription_la_newsletter__c = true; compte.Date_d_inscription_la_newsletter__c = leadO.Date_d_inscription_la_newsletter__c; compte.D_sinscription_la_newsletter__c = leadO.D_sinscription_la_newsletter__c; compte.Date_de_d_sinscription_la_newsletter__c = leadO.Date_de_d_sinscription_la_newsletter__c; } } //System.debug(compte.Id); if(compte.Id != null){update compte;System.debug('mise à jour ok'); } else {System.debug ('erreur compte');} if(leadO.Id != null){delete leadO; System.debug('leadO.id !=null');} else{System.debug('erreur leadO');} } } global void finish(Database.BatchableContext BC){ System.debug('fini'); } public static testmethod void testVerifNoLead (){ List <Lead> ld = new List<Lead>(); for(integer i = 0; i<2; i++){ Lead l = new Lead(Adresse_mail__c='test'+i+'@mail.com',LastName='test', Inscription_la_newsletter__c =true); ld.add(l); } insert ld; Test.startTest() ; Account lnew = new Account( Salutation = 'M.', FirstName ='Hélène', LastName = 'test', Adresse_mail__c = 'test1@mail.com', PersonLeadSource = 'Newsletter', // Origine_connaissance_Kiwatch__c ='', Numero_client__c = 0, /*accepte_jeux__c = true, Date_inscription_au_jeu__c = , Email_parr__c = 'h.broussin@kiwatch.com', Email_parrainage_2__c = '', Email_parrainage_3__c = '', Email_parrainage_4__c = '', Email_parrainage_5__c = '',*/ // PersonMailingStreet = '',//'39, rue des étoiles', // PersonMailingCity = '',//'laval', // PersonMailingState = '',//'pays de loire', // PersonMailingPostalCode = '',//'53000', // PersonMailingCountry = '',//'france', PersonHomePhone = '0900000000', PersonMobilePhone = '070809101112', Rating = 'Froid', // Date_d_inscription_la_newsletter__c = '29/05/2012', // Date_de_d_sinscription_la_newsletter__c = '', Inscription_la_newsletter__c = false, D_sinscription_la_newsletter__c = false, Raison_de_la_d_sinscription__c = '', /*locataire__c = true, proprietaire__c = false, alarme__c = false, videosurveillance__c = false, alarme_et_videosurveillance__c = false, pas_de_systeme__c = true,*/ Type_d_utilisation__c = 'Pro', demande__c = '', Demande_contact__c = '', Objet_demande__c = '', //Date_d_abonnement__c, //Date_fin_de_contrat__c, Raison_fin_de_contrat__c ='', //Date_de_l_abonnement_actuel__c, Abonnement__c='Pro'); String query = 'SELECT Salutation, FirstName , Adresse_mail__c, LastName, Num_ro_piste__c, LeadSource, 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, Phone, Telephone_portable__c FROM Lead WHERE Adresse_mail__c=\'' + lnew.Adresse_mail__c + '\' LIMIT 2'; VerifNoLead batchApex = new VerifNoLead(query, lnew ); ID batchprocessid = Database.executeBatch(batchApex); Test.StopTest(); } }
and my trigger :
trigger RechercheDoubleCompte on Account(after insert) { for (Account a : Trigger.new) { String query = 'SELECT 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 WHERE Adresse_mail__c=\'' + a.Adresse_mail__c + '\' AND Id!=\'' + a.Id + '\' LIMIT 100'; String query2 = 'SELECT 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 WHERE Adresse_mail__c=\'' + a.Adresse_mail__c + '\' LIMIT 100'; UpdateFieldAccount batchApex = new UpdateFieldAccount(query, a ); ID batchprocessid = Database.executeBatch(batchApex); VerifNoLead batchApex2 = new VerifNoLead(query2, a ); ID batchprocessid2 = Database.executeBatch(batchApex2); } }
- alexj
- June 04, 2012
- Like
- 0
no perspective force.com
Hi,
I have install eclipse Version: 3.4.2 and the plugin force.com
But I can't find the Perspective
I have add the path to the file eclipse.ini :
org.eclipse.platform
--launcher.XXMaxPermSize
256M
-framework
plugins\org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx256m
-vm
C:\Program Files\Java\jre7\bin\javaw.exe
But there is no changement
- alexj
- May 30, 2012
- Like
- 0
deployement from sandbox to production
Hi, I have developped an appex class with this test class. My code is correctly covered and the work suits me. I would like deploy this class on my production.The developpment is on my sandbox.
I haven't found a clear documentation about deployement from sandbox to production. what is the different steps?
Thank you for your help,
- alexj
- May 29, 2012
- Like
- 0
problem with class batch
Hi,
I have a problem with Batch class. Yesterday my class run correctly but I don't know what change I have do and that can't execute correctly.
My problem is that the fonction execute isn't realize and i don't understand why.
I have create a simple class to understand but it the same problem.
Below, my class and the result of test.
Code Coverage BatchDelete (Code Covered: 75%)
global class BatchDelete implements Database.Batchable<sObject> {
public String query; global BatchDelete(String q){
query=q;
}
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
delete scope;
System.debug('fin execution');
}
global void finish(Database.BatchableContext BC){
}
public static testMethod void testBathDelete(){
List <Lead> ld = new List<Lead>();
for(integer i = 0; i<3; i++){
Lead l = new Lead(Adresse_mail__c='testLead'+i+'@mail.com',LastName='nouveauprenom');
ld.add(l);
}
insert ld;
Test.StartTest();
String q= 'SELECT ID, Name FROM Account LIMIT 3';
BatchDelete BD = new BatchDelete(q);
ID batchprocessid = Database.executeBatch(BD);
Test.StopTest();
}
}
- alexj
- April 25, 2012
- Like
- 0