• hmoh1920
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 45
    Questions
  • 50
    Replies

Hi,

 

I have this error when i open e-mail pdf attachment  "File does not begin with '%PDF-'"

 

this is my batch class to send email.

I do not know where is the problem! please help me.

 

note: AppelCotisation is my vf page genered pdf, i use this page in another class and execute successfully.

 

 

global class BatchT20 implements Database.Batchable<sObject>{



String OppId;
String varRech;
Decimal TaxeOpp=0;
Datetime StartDate;
Datetime EndDate;
 
string AdresseCity;
string AdressePostalCode;
string AdresseStreet;


string NomContrat;
string Numerodepolice;
decimal PrimeTTC;
decimal PrimeTTCPeriode;


        
global final String query ='SELECT id,name FROM Opportunity';    
   
//------------------------------------------------------------------------------------------------------------------------

global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator(query);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){


//calcul de la marge temporaire
    string Datedeffet;
    string Datedecheance;
    Datetime dateJour = datetime.now();

    Date dateRef = Date.newInstance(dateJour.year(),dateJour.month(),dateJour.day()-20);
    Date dateMax = Date.newInstance(dateJour.year()-1,dateJour.month()-1,dateJour.day());



                   //-------------------------------------------------------------------------//

List<Quittance__c>  QuittFac = [SELECT Id, Opportunit__c, CreatedDate, Facturation_Avoir__c, varBalance__c, Total_pay__c,
                               Montantdesecheances__c, Nbre_Rappel_Cotisation__c,
                               Opportunit__r.Accountid, Opportunit__r.Date_d_effet__c, Opportunit__r.Type_de_produit__c,
                               Opportunit__r.Statut_Police__c, Opportunit__r.id, Opportunit__r.name, Opportunit__r.Pricebook2.name,
                               Opportunit__r.Date_d_ech_ance_de_la_police__c, Opportunit__r.Account.BillingCity,
                               Opportunit__r.Account.BillingPostalCode, Opportunit__r.Account.BillingStreet,
                               Opportunit__r.Primes_TTC__c, Opportunit__r.Prime_TTC_periode__c
                               
                               FROM Quittance__c
                               where
                               ((Opportunit__r.Date_d_effet__c=:dateRef and Opportunit__r.Type_de_produit__c!='Produit'
                               
                               and (Opportunit__r.Statut_Police__c='Nouvelle'
                               or Opportunit__r.Statut_Police__c='Renouvellement'
                               or Opportunit__r.Statut_Police__c='Avenant'))
                               
                               and Facturation_Avoir__c='Facturation' and varBalance__c<0)];


                   //-------------------------------------------------------------------------//
                   

List <Contact> contact =[Select Id, AccountId, Salutation, FirstName, LastName, Email, Destinataire__c From Contact where Destinataire__c='Oui'];          


                   //-------------------------------------------------------------------------//
                   
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 
                    List<String> contactids=new List<String>();
    
                
            //-----------------------//
              Integer K=0, s;
              k = QuittFac.size();     
              for ( s=0;s<k;s++)
                {
                     //-------------//
                      if (k!=0)           
                        {
  OppId=QuittFac[s].Opportunit__r.id;                         
  StartDate = datetime.newInstance(QuittFac[s].Opportunit__r.Date_d_effet__c.year(), QuittFac[s].Opportunit__r.Date_d_effet__c.month(), QuittFac[s].Opportunit__r.Date_d_effet__c.day());              
  EndDate = datetime.newInstance(QuittFac[s].Opportunit__r.Date_d_ech_ance_de_la_police__c.year(), QuittFac[s].Opportunit__r.Date_d_ech_ance_de_la_police__c.month(), QuittFac[s].Opportunit__r.Date_d_ech_ance_de_la_police__c.day());
              
  Datedeffet = StartDate.format('dd/MM/yyyy');
  Datedecheance = EndDate.format('dd/MM/yyyy');                            
                            
                         varRech=QuittFac[s].Opportunit__r.Accountid;
                         NomContrat =QuittFac[s].Opportunit__r.Pricebook2.name;
                         
                         PrimeTTC=QuittFac[s].Opportunit__r.Primes_TTC__c;
                         PrimeTTCPeriode=QuittFac[s].Opportunit__r.Prime_TTC_periode__c;
                         
                         
                         AdresseCity = QuittFac[s].Opportunit__r.Account.BillingCity;
                         AdressePostalCode = QuittFac[s].Opportunit__r.Account.BillingPostalCode;
                         AdresseStreet = QuittFac[s].Opportunit__r.Account.BillingStreet;
                         
                      

                         PageReference AppelCotisation = Page.AppelCotisation;
                         AppelCotisation.getParameters().put('id',OppId);
                          
                         Messaging.EmailFileAttachment myEQuote = new Messaging.EmailFileAttachment();
                         
 
                          
                                 
                         Blob htmBlob = AppelCotisation.getContent();                      
                                                        
                                   
                                    Integer M=0, n;
                                    M = contact.size();
                                    for ( n=0;n<M;n++)
                                        {
                                         
                                           if (M!=0 && contact[n].AccountId == varRech && contact[n].Email!=null )           
                                             {
                                                             
                                                 String ContactId =contact[n].Id ;
                                                 String Salutation =contact[n].Salutation ;
                                                 String prenomContact=contact[n].FirstName;
                                                 String nomContact=contact[n].LastName;     
            
                    
                                                 contactids.add(contact[n].Email);
   
   

                                                 mail.setSubject('Rappel 1');  
                               
                       
                                                 mail.setSenderDisplayName('Test@test.com');
                                                 mail.setReplyTo('test@test.com');
                                                 mail.setSenderDisplayName('test');
                                                 
                                                 
            Attachment a = new Attachment(parentId = OppId, name=QuittFac[s].Opportunit__r.name + '.pdf', body = htmBlob, isPrivate=false);
        
            // Insert the attachment
            insert a;
     
     mail.setHtmlBody('html e_mail');


                                                 mail.setWhatId(OppId);
                                                
                                                 mail.setTargetObjectId(ContactId);
                  
                                                 
                                         myEQuote.setFileName(QuittFac[s].Opportunit__r.name.replace('/',' - ')+'.pdf');
                                         myEQuote.setBody(htmBlob);
                      
                                         mail.setFileAttachments(new Messaging.EmailFileAttachment[] {myEQuote});                                                
                                                 
                                     
                      
                                                 Messaging.sendEmail(New Messaging.SingleEmailMessage[]{mail});              
                
                                                 contactids.clear();  
                            
                                             }
                                        }     
                                  
                           QuittFac[s].Nbre_Rappel_Cotisation__c='Rappel1';        
                                                                                                                    
                        }
                 }                    
        
        List<Database.SaveResult> dsrs = Database.update(QuittFac, false);
        for(Database.SaveResult dsr : dsrs){ }           
                    
}
global void finish(Database.BatchableContext BC){
     
}
}

 

 

thanks.

 

 


moh.

Hi,

 

 

how to send a wireless print pdf file??

 

 

 

thanks.

 

moh.

Hi,

 

I have this code :

 

global void execute(SchedulableContext ctx)
{

public List<String> account_email{get;set;}
public Map<string,string> Map_usr{get;set;}

Map_usr=new Map<string,string>();

 

account =[Select (Select Etape_de_cr_ation__c From Opportunities where Etape_de_cr_ation__c='Etape2'),
 (Select Id, Email, Destinataire__c From Contacts where Destinataire__c='Oui') From Account a];

 


        for(Account c:account)
        {

            system.debug('____id__'+c.id+'____Email_____'+c.Email+'___DATE_______'+c.Destinataire__c);

//error at this line :Save error: Invalid field Email for SObject Account


            Map_usr.put(c.id,c.Email);

            if(c.Email!=null)

                account_email.add(c.Email);

        }

       if(account_email.size()>0)

           sendmail(account_email);

}

 

my question is: how to recover the data (email) of the query?

 

thanks for your help!

 

 

cordially

moh.

 

 

 

Hi,

i have add an apex batch to clone many opportunity and product, i have this erreur "  Lot Apex    Terminé    First error: Too many SOQL queries: 201 "

it is possible to force nombre of request according !

 

it is the type of license that I limit the number of request?

 

thanks for your answer

 

 

 

 

 

cordially

 Moh.

Hi,

 

How data recording  can load the data loader to a custom object.

I have 6000 recording  is loaded, it is possible?

 

 

Thanks.

Hi,

 

How retrieve a variable declared in my controller from my batch.

 

I call the batch from a method in my controller and this variable is opportunity id.

 


 

thanks.

Hi,

this is my controller and my apex page:

<apex:page standardController="opportunity" extensions="myControllerExtension">
    <apex:form >
        <apex:pageBlock >  
           <apex:pageBlockSection title="Information Avenant">

                    //to display the name of the master opportunity and can edit
                  <apex:inputField value="{!opportunity.name}"/> <p/>
                  <apex:outputField value="{!opportunity.N_police_d_origine__c}"/> <p/>
                  <apex:inputField value="{!opportunity.Date_d_avenant__c}"/> <p/>
                  <apex:inputField value="{!opportunity.Statut_Police__c}"/> <p/>   
              </apex:pageBlockSection>   
             <apex:pageBlockButtons >
                   <apex:commandButton value="Enregistrer" action="{!enregistrer}"/>
                   <apex:commandButton value="cancel" action="{!cancel}"/>
             </apex:pageBlockButtons>
                           </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 

public class myControllerExtension {


private String name;


   public Opportunity Opp {get;set;}
   public Opportunity OppAcc {get;set;}
   

   
 
 
   ApexPages.StandardController controller;   
   public myControllerExtension(ApexPages.StandardController c)
   
   {
          Opp = (Opportunity)c.getRecord();
   }
     

      
 
 
 
 
        public PageReference Avenant()
      {
        return Page.Avenant;
      }
   
   
     public PageReference cancel()
     {
            PageReference opportunityPage = new ApexPages.StandardController(opp).view();
            opportunityPage.setRedirect(true);
            return opportunityPage;
     }
    
    
   public PageReference enregistrer() {

//add a news code to crate a new opportunity

}

 

 

how to retrieve the data entered in the apex page and create a new opportunity?

 

thanks.

 

 

Hi,

a like add in my visual page in bouton save.

 

this button will create a new record opportunity and not updated of the recording in court!

 

please how do?

 

 

 

thanks.

Hi,

 

please, how sandbox i can have ?

i have 2 developpeurs, and i like have 2 sand box, is possible?

 

 

Thanks.

Hi,

I coded this batch:

 

global class BalanceCalculBatchV3 implements Database.Batchable<sObject>{
String IDVar;
decimal var1=0, var2=0;
date dateEcheance;

        
global final String query ='SELECT id,name FROM Opportunity limit 4';        

global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator(query);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){

 List<Opportunity> opps = [select id,  Date_d_ech_ance_de_la_police__c, Total_montant_pay__c
                            from Opportunity];
   
 
 
 List<paiement__c> paiement = [SELECT Id, CreatedDate, montant_pay__c ,Encaissement_remboursement__c, Montant_rem__c,
                                        Opportunit__c FROM paiement__c];  
                                        
                        
 List<Quittance__c> quittance = [SELECT Id, Date_due1__c, Date_due10__c, Date_due11__c, Date_due12__c, Date_due2__c,
                                   Date_due3__c, Date_due4__c, Date_due5__c, Date_due6__c, Date_due7__c, Date_due8__c,
                                   Date_due9__c, Date_pay_del__c, DateDue__c, Echeance_paiement__c, Echeance1__c,
                                   Echeance10__c, Echeance11__c, Echeance12__c, Echeance2__c, Echeance3__c, Echeance4__c,
                                   Echeance5__c, Echeance6__c, Echeance7__c, Echeance8__c, Echeance9__c, Opportunit__c,
                                   Facturation_Avoir__c, Montant_d_avoir__c
                                   FROM Quittance__c];
 
 
/******************************************************************************************************************************/
    
    Integer l;
    l = opps.size();
if(l!=Null) {                       
    for (Integer i = 0; i<l; i++)
              {
                  IDVar=opps[i].Id;
                          
             Integer m;
             m = paiement.size();
if(m!=Null) {                      
         for (Integer s = 0; s<m; s++)
              {
              if(paiement[s].Opportunit__c== IDVar)
              {
                  
                         if(paiement[s].Encaissement_remboursement__c=='Encaissement')
                           {
                                var1 += paiement[s].montant_pay__c;
                           }
                         if(paiement[s].Encaissement_remboursement__c=='Remboursement')
                           {
                                var1 -= paiement[s].Montant_rem__c;
                           }
                }
               }
           }                                       
/******************************************************************************************************************************/                  
    dateEcheance=opps[i].Date_d_ech_ance_de_la_police__c;      

          
/******************************************************************************************************************************/                   
//calcul au niveau de la quittance.
Integer h;
h = quittance.size();     
if(h!=null)
{
     for (Integer n = 0; n<h; n++)
         {

           if (quittance[n].Opportunit__c== IDVar)
             {
        
           if(quittance[n].Facturation_Avoir__c=='Avoir')
             {
               var2 -= quittance[n].Montant_d_avoir__c;
             }
           if(quittance[n].Facturation_Avoir__c=='Facturation')
             {
/****************************************En fonction des 4 modes de paiement*****************************************/
/*******************************************Paiement annuel*********************************************************/

               if (quittance[n].Echeance_paiement__c =='Annuel' && quittance[n].Date_due1__c<=datetime.now())
                {
                      var2+=quittance[n].Echeance1__c;
                }

/******************************************Paiement Semestriel*******************************************************/

         if (quittance[n].Echeance_paiement__c =='Semestriel' && quittance[n].Date_due1__c<=datetime.now())
          {
              if(quittance[n].Date_due2__c<=datetime.now())
               {
                var2+=quittance[n].Echeance1__c+quittance[n].Echeance2__c;
               }else
               {
                var2+=quittance[n].Echeance1__c;
               }
          }
   // other traitement

                   
                          }
}                          
                    }
}
//calcul du montant final
opps[i].Total_montant_pay__c = var1-var2;  
 
                           
/****************************************************************************************************************/                  
                  
var1=0;
var2=0;
              }
}  

        List<Database.SaveResult> dsrs = Database.update(opps, false);
 


    
}

}

 

 

i have an  800 opportunity in my objet Opportunity;

 

when executing, I get this error:  First error: Too many script statements: 1000001.

please help me to resolve this problem.

 

thanks.

Hi,

 

i have this batch code:

 

 

global class BalanceCalculBatch implements Database.Batchable<sObject>{
String IDVar;
decimal var1=0, var2=0;
date dateEcheance;


String email;
Id toUserId;
Id fromUserId;

        
global final String query ='SELECT id,name FROM Opportunity limit 1';        

global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator(query);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){

  List<Opportunity> opps = [select id,  Date_d_ech_ance_de_la_police__c, Total_montant_pay__c
                            from Opportunity where Date_d_effet__c > 2011-12-31];
   
   
    Integer l;
    l = opps.size();
if(l!=Null) {                       
    for (Integer i = 0; i<l; i++)
              {
                  IDVar=opps[i].Id;
/******************************************************************************************************************************/
         
          List<paiement__c> paiement = [SELECT Id, CreatedDate, montant_pay__c ,Encaissement_remboursement__c, Montant_rem__c,
                                        Opportunit__c FROM paiement__c where Opportunit__c=:IDVar];
                                        
             Integer m;
             m = paiement.size();
if(m!=Null) {                      
         for (Integer s = 0; s<m; s++)
              {
                  
                         if(paiement[s].Encaissement_remboursement__c=='Encaissement')
                           {
                                var1 += paiement[s].montant_pay__c;
                           }
                         if(paiement[s].Encaissement_remboursement__c=='Remboursement')
                           {
                                var1 -= paiement[s].Montant_rem__c;
                           }
               }
           }                                       
/******************************************************************************************************************************/                  
    dateEcheance=opps[i].Date_d_ech_ance_de_la_police__c;      
    List<Quittance__c> quittance = [SELECT Id, Date_due1__c, Date_due10__c, Date_due11__c, Date_due12__c, Date_due2__c,
                                   Date_due3__c, Date_due4__c, Date_due5__c, Date_due6__c, Date_due7__c, Date_due8__c,
                                   Date_due9__c, Date_pay_del__c, DateDue__c, Echeance_paiement__c, Echeance1__c,
                                   Echeance10__c, Echeance11__c, Echeance12__c, Echeance2__c, Echeance3__c, Echeance4__c,
                                   Echeance5__c, Echeance6__c, Echeance7__c, Echeance8__c, Echeance9__c, Opportunit__c,
                                   Facturation_Avoir__c, Montant_d_avoir__c
                                   FROM Quittance__c where Opportunit__c =:IDVar];
          
/******************************************************************************************************************************/                   
//calcul au niveau de la quittance.
Integer h;
h = quittance.size();     
if(h!=null)
{
     for (Integer n = 0; n<h; n++)
         {                         
           if(quittance[n].Facturation_Avoir__c=='Avoir')
             {
               var2 -= quittance[n].Montant_d_avoir__c;
             }
           if(quittance[n].Facturation_Avoir__c=='Facturation')
             {
/****************************************En fonction des 4 modes de paiement*****************************************/
/*******************************************Paiement annuel*********************************************************/

               if (quittance[n].Echeance_paiement__c =='Annuel' && quittance[n].Date_due1__c<=datetime.now())
                {
                      var2+=quittance[n].Echeance1__c;
                }

/******************************************Paiement Semestriel*******************************************************/

         if (quittance[n].Echeance_paiement__c =='Semestriel' && quittance[n].Date_due1__c<=datetime.now())
          {
              if(quittance[n].Date_due2__c<=datetime.now())
               {
                var2+=quittance[n].Echeance1__c+quittance[n].Echeance2__c;
               }else
               {
                var2+=quittance[n].Echeance1__c;
               }
          }
                  
                          }                    
                    }
}
//calcul du montant final
opps[i].Total_montant_pay__c = var1-var2;  
 
                           
/****************************************************************************************************************/                  
                  update opps[i];
var1=0;
var2=0;
              }
}  
    
}
global void finish(Database.BatchableContext BC){
    
   AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
      TotalJobItems, CreatedBy.Email
      FROM AsyncApexJob WHERE Id =
      :BC.getJobId()];
   // Send an email to the Apex job's submitter notifying of job completion.
    
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {a.CreatedBy.Email};
   mail.setToAddresses(toAddresses);
   mail.setSubject('Apex Sharing Recalculation ' + a.Status);
   mail.setPlainTextBody
   ('The batch Apex job processed ' + a.TotalJobItems +
   ' batches with '+ a.NumberOfErrors + ' failures.');
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
   
}



}

 

when I execute, I have a this error:

First error: Too many SOQL queries: 201

 

plese helpe me; there's a means to force the execution?

 

 

 

thanks


 

 

Hi,

i write a batch and  test method into this batch, my code of this batch is 87% couvred into my sand box  but  when I try to deploy in production I get an error only 12% of the batch code is covered.

 

this code of my test metode:

/***********************************************************************/

public static testmethod void testbatch()
{
    
  Test.startTest();
  BalanceCalculBatch ch = new BalanceCalculBatch();
  ID batchprocessid = Database.executeBatch(ch);
  Test.stopTest();
           
}

 

/*********************************************************************/

 

 

this is my match code:

 

/*********************************************************************/

global class BalanceCalculBatch implements Database.Batchable<sObject>{
String IDVar;
decimal var1=0, var2=0;
date dateEcheance;


String email;
Id toUserId;
Id fromUserId;

        
global final String query ='SELECT id,name FROM Opportunity';        

global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator(query);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){

  List<Opportunity> opps = [select id,  Date_d_ech_ance_de_la_police__c, Total_montant_pay__c
                            from Opportunity  where Date_d_ech_ance_de_la_police__c > 2011-12-31];
   
   
    Integer l;
    l = opps.size();
if(l!=Null) {                       
    for (Integer i = 0; i<l; i++)
              {
                  IDVar=opps[i].Id;

 

//my traitement code

 

}

}

}

 

 

 

 

 

Help me, where is the problems?

 

thanks.

 

 

 

Moh.

 

Hi,

 

I want renamed my test class in production in order to deploy my code  sandbox.

my test class in the production is named  "test"  and in sandbox is named  "testClass"

 

how to rename

 

 

thanks.

Hi,

 

 

I get an error "  testcode: Type is not visible: test    " when I deploys my sand box to the production.

 

 

"testcode" is the name of my  test class.

 

I renamed my class test with "test" but I got an error at this level "Test.startTest();" in thecode of my  test  class. this error is " Methode does not exist or incorrect signature: Test.startTest()".

 

please help me.

 

thanks.

 

 

 

moh.

Hi,

 


I tried to execute a test class I had this error!

"

Visualforce Error


java.lang.reflect.InvocationTargetException

 

"

 

before  today my class exectute well!

 

please , is salesforce problem or is to my class test?

 

thanks.

Hi,

 

I like add an custom error message for my trigger into try{}catch....

 

please how?

 

 

thanks.

 

 

 

M.H

 

 

Hi,

 

I write a  batch class for my project; i want to test: plese help me to write in test class in order to covered my class.

 

Thanks.

 

this my batch class

 

 

 

global class BalanceCalculBatch implements Database.Batchable<sObject>{
String IDVar;
decimal var1=0, var2=0;
date dateEcheance;

String email;


global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator([SELECT id,name FROM Opportunity]);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){

  List<Opportunity> opps = [select id from Opportunity  where Date_d_ech_ance_de_la_police__c > 2011-12-31];
   
   
    Integer l;
    l = opps.size();
if(l!=Null) {                       
    for (Integer i = 0; i<l; i++)
              {
                  IDVar=opps[i].Id;
/******************************************************************************************************************************/
         
          List<paiement__c> paiement = [SELECT Id, montant_pay__c ,Encaissement_remboursement__c, Montant_rem__c,
                                        Opportunit__c FROM paiement__c where Opportunit__c=:IDVar];
                                        
             Integer m;
             m = paiement.size();
if(m!=Null) {                      
         for (Integer s = 0; s<m; s++)
              {
                  
                         if(paiement[s].Encaissement_remboursement__c=='Encaissement')
                           {
                                var1 += paiement[s].montant_pay__c;
                           }
                         if(paiement[s].Encaissement_remboursement__c=='Remboursement')
                           {
                                var1 -= paiement[s].Montant_rem__c;
                           }
               }
           }                                       
/******************************************************************************************************************************/                  
    dateEcheance=opps[i].Date_d_ech_ance_de_la_police__c;      
    List<Quittance__c> quittance = [SELECT Id, Date_due1__c, Echeance_paiement__c, Echeance1__c,
                                   Opportunit__c, Facturation_Avoir__c, Montant_d_avoir__c
                                   FROM Quittance__c where Opportunit__c =:IDVar];
          
/******************************************************************************************************************************/                   
Integer h;
h = quittance.size();     
if(h!=null)
{
     for (Integer n = 0; n<h; n++)
         {                         
           if(quittance[n].Facturation_Avoir__c=='Avoir')
             {
               var2 -= quittance[n].Montant_d_avoir__c;
             }
           if(quittance[n].Facturation_Avoir__c=='Facturation')
             {
/****************************************************************************************************/

               if (quittance[n].Echeance_paiement__c =='Annuel' && quittance[n].Date_due1__c<=datetime.now())
                {
                      var2+=quittance[n].Echeance1__c;
                }
                   
              }                    
         }
}

opps[i].Total_montant_pay__c = var1-var2;  
 
                           
/****************************************************************************************************************/                  
                  update opps[i];
var1=0;
var2=0;
              }
}  
    
}
global void finish(Database.BatchableContext BC){
    
   AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
      TotalJobItems, CreatedBy.Email
      FROM AsyncApexJob WHERE Id =
      :BC.getJobId()];
   // Send an email to the Apex job's submitter notifying of job completion.
    
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {a.CreatedBy.Email};
   mail.setToAddresses(toAddresses);
   mail.setSubject('Apex Sharing Recalculation ' + a.Status);
   mail.setPlainTextBody
   ('The batch Apex job processed ' + a.TotalJobItems +
   ' batches with '+ a.NumberOfErrors + ' failures.');
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
   
}



}

 

Hi,

i coded in this schedule class and i add in my test class, but  i have 0% couverd in my schedule class!

 

this is my  schedule:

global class Sch01 implements Schedulable{


   global void execute(SchedulableContext sc) {


       

      AccountOwnerReassignment acc = new AccountOwnerReassignment();
     database.executebatch(acc);

   }
    
}

 

and this is my test class:

 

@isTest
private class test {

public static testmethod void t63()
{
Sch01 sco = new Sch01();

String sch = '0 0 23 * * ?';

system.schedule('Contract Creates', sch, sco);    
}
}

 

please, where is the problem?

 

thanks.

 

Hi,

I write a schedule :

 

global class Sch01 implements Schedulable{


   global void execute(SchedulableContext sc) {


     AccountOwnerReassignment acc = new AccountOwnerReassignment();


     database.executebatch(acc);

   }
}

 

and this test class;

static testmethod void t62()
{


Test.startTest();
        Sch01 sh = new Sch01();
        String sch = '0 0 5 * * ?';
        system.schedule('Schedule TEST', sch, sh);
Test.stopTest();      
        
}

 

Ihave this error :Save error: Method does not exist or incorrect signature: Test.startTest().

 

Please, what is the problem??

 

thanks!

 

M.H

 

Hi,

 

I like to execute my schedule (sche01), every 10 minutes;


how to plan it?

 

 

thanks.

 

 

M.H

Hi,

 

I have this error when i open e-mail pdf attachment  "File does not begin with '%PDF-'"

 

this is my batch class to send email.

I do not know where is the problem! please help me.

 

note: AppelCotisation is my vf page genered pdf, i use this page in another class and execute successfully.

 

 

global class BatchT20 implements Database.Batchable<sObject>{



String OppId;
String varRech;
Decimal TaxeOpp=0;
Datetime StartDate;
Datetime EndDate;
 
string AdresseCity;
string AdressePostalCode;
string AdresseStreet;


string NomContrat;
string Numerodepolice;
decimal PrimeTTC;
decimal PrimeTTCPeriode;


        
global final String query ='SELECT id,name FROM Opportunity';    
   
//------------------------------------------------------------------------------------------------------------------------

global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator(query);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){


//calcul de la marge temporaire
    string Datedeffet;
    string Datedecheance;
    Datetime dateJour = datetime.now();

    Date dateRef = Date.newInstance(dateJour.year(),dateJour.month(),dateJour.day()-20);
    Date dateMax = Date.newInstance(dateJour.year()-1,dateJour.month()-1,dateJour.day());



                   //-------------------------------------------------------------------------//

List<Quittance__c>  QuittFac = [SELECT Id, Opportunit__c, CreatedDate, Facturation_Avoir__c, varBalance__c, Total_pay__c,
                               Montantdesecheances__c, Nbre_Rappel_Cotisation__c,
                               Opportunit__r.Accountid, Opportunit__r.Date_d_effet__c, Opportunit__r.Type_de_produit__c,
                               Opportunit__r.Statut_Police__c, Opportunit__r.id, Opportunit__r.name, Opportunit__r.Pricebook2.name,
                               Opportunit__r.Date_d_ech_ance_de_la_police__c, Opportunit__r.Account.BillingCity,
                               Opportunit__r.Account.BillingPostalCode, Opportunit__r.Account.BillingStreet,
                               Opportunit__r.Primes_TTC__c, Opportunit__r.Prime_TTC_periode__c
                               
                               FROM Quittance__c
                               where
                               ((Opportunit__r.Date_d_effet__c=:dateRef and Opportunit__r.Type_de_produit__c!='Produit'
                               
                               and (Opportunit__r.Statut_Police__c='Nouvelle'
                               or Opportunit__r.Statut_Police__c='Renouvellement'
                               or Opportunit__r.Statut_Police__c='Avenant'))
                               
                               and Facturation_Avoir__c='Facturation' and varBalance__c<0)];


                   //-------------------------------------------------------------------------//
                   

List <Contact> contact =[Select Id, AccountId, Salutation, FirstName, LastName, Email, Destinataire__c From Contact where Destinataire__c='Oui'];          


                   //-------------------------------------------------------------------------//
                   
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 
                    List<String> contactids=new List<String>();
    
                
            //-----------------------//
              Integer K=0, s;
              k = QuittFac.size();     
              for ( s=0;s<k;s++)
                {
                     //-------------//
                      if (k!=0)           
                        {
  OppId=QuittFac[s].Opportunit__r.id;                         
  StartDate = datetime.newInstance(QuittFac[s].Opportunit__r.Date_d_effet__c.year(), QuittFac[s].Opportunit__r.Date_d_effet__c.month(), QuittFac[s].Opportunit__r.Date_d_effet__c.day());              
  EndDate = datetime.newInstance(QuittFac[s].Opportunit__r.Date_d_ech_ance_de_la_police__c.year(), QuittFac[s].Opportunit__r.Date_d_ech_ance_de_la_police__c.month(), QuittFac[s].Opportunit__r.Date_d_ech_ance_de_la_police__c.day());
              
  Datedeffet = StartDate.format('dd/MM/yyyy');
  Datedecheance = EndDate.format('dd/MM/yyyy');                            
                            
                         varRech=QuittFac[s].Opportunit__r.Accountid;
                         NomContrat =QuittFac[s].Opportunit__r.Pricebook2.name;
                         
                         PrimeTTC=QuittFac[s].Opportunit__r.Primes_TTC__c;
                         PrimeTTCPeriode=QuittFac[s].Opportunit__r.Prime_TTC_periode__c;
                         
                         
                         AdresseCity = QuittFac[s].Opportunit__r.Account.BillingCity;
                         AdressePostalCode = QuittFac[s].Opportunit__r.Account.BillingPostalCode;
                         AdresseStreet = QuittFac[s].Opportunit__r.Account.BillingStreet;
                         
                      

                         PageReference AppelCotisation = Page.AppelCotisation;
                         AppelCotisation.getParameters().put('id',OppId);
                          
                         Messaging.EmailFileAttachment myEQuote = new Messaging.EmailFileAttachment();
                         
 
                          
                                 
                         Blob htmBlob = AppelCotisation.getContent();                      
                                                        
                                   
                                    Integer M=0, n;
                                    M = contact.size();
                                    for ( n=0;n<M;n++)
                                        {
                                         
                                           if (M!=0 && contact[n].AccountId == varRech && contact[n].Email!=null )           
                                             {
                                                             
                                                 String ContactId =contact[n].Id ;
                                                 String Salutation =contact[n].Salutation ;
                                                 String prenomContact=contact[n].FirstName;
                                                 String nomContact=contact[n].LastName;     
            
                    
                                                 contactids.add(contact[n].Email);
   
   

                                                 mail.setSubject('Rappel 1');  
                               
                       
                                                 mail.setSenderDisplayName('Test@test.com');
                                                 mail.setReplyTo('test@test.com');
                                                 mail.setSenderDisplayName('test');
                                                 
                                                 
            Attachment a = new Attachment(parentId = OppId, name=QuittFac[s].Opportunit__r.name + '.pdf', body = htmBlob, isPrivate=false);
        
            // Insert the attachment
            insert a;
     
     mail.setHtmlBody('html e_mail');


                                                 mail.setWhatId(OppId);
                                                
                                                 mail.setTargetObjectId(ContactId);
                  
                                                 
                                         myEQuote.setFileName(QuittFac[s].Opportunit__r.name.replace('/',' - ')+'.pdf');
                                         myEQuote.setBody(htmBlob);
                      
                                         mail.setFileAttachments(new Messaging.EmailFileAttachment[] {myEQuote});                                                
                                                 
                                     
                      
                                                 Messaging.sendEmail(New Messaging.SingleEmailMessage[]{mail});              
                
                                                 contactids.clear();  
                            
                                             }
                                        }     
                                  
                           QuittFac[s].Nbre_Rappel_Cotisation__c='Rappel1';        
                                                                                                                    
                        }
                 }                    
        
        List<Database.SaveResult> dsrs = Database.update(QuittFac, false);
        for(Database.SaveResult dsr : dsrs){ }           
                    
}
global void finish(Database.BatchableContext BC){
     
}
}

 

 

thanks.

 

 


moh.

Hi,

 

I have this code :

 

global void execute(SchedulableContext ctx)
{

public List<String> account_email{get;set;}
public Map<string,string> Map_usr{get;set;}

Map_usr=new Map<string,string>();

 

account =[Select (Select Etape_de_cr_ation__c From Opportunities where Etape_de_cr_ation__c='Etape2'),
 (Select Id, Email, Destinataire__c From Contacts where Destinataire__c='Oui') From Account a];

 


        for(Account c:account)
        {

            system.debug('____id__'+c.id+'____Email_____'+c.Email+'___DATE_______'+c.Destinataire__c);

//error at this line :Save error: Invalid field Email for SObject Account


            Map_usr.put(c.id,c.Email);

            if(c.Email!=null)

                account_email.add(c.Email);

        }

       if(account_email.size()>0)

           sendmail(account_email);

}

 

my question is: how to recover the data (email) of the query?

 

thanks for your help!

 

 

cordially

moh.

 

 

 

Hi,

i have add an apex batch to clone many opportunity and product, i have this erreur "  Lot Apex    Terminé    First error: Too many SOQL queries: 201 "

it is possible to force nombre of request according !

 

it is the type of license that I limit the number of request?

 

thanks for your answer

 

 

 

 

 

cordially

 Moh.

Hi,

 

How data recording  can load the data loader to a custom object.

I have 6000 recording  is loaded, it is possible?

 

 

Thanks.

Hi,

 

How retrieve a variable declared in my controller from my batch.

 

I call the batch from a method in my controller and this variable is opportunity id.

 


 

thanks.

Hi,

this is my controller and my apex page:

<apex:page standardController="opportunity" extensions="myControllerExtension">
    <apex:form >
        <apex:pageBlock >  
           <apex:pageBlockSection title="Information Avenant">

                    //to display the name of the master opportunity and can edit
                  <apex:inputField value="{!opportunity.name}"/> <p/>
                  <apex:outputField value="{!opportunity.N_police_d_origine__c}"/> <p/>
                  <apex:inputField value="{!opportunity.Date_d_avenant__c}"/> <p/>
                  <apex:inputField value="{!opportunity.Statut_Police__c}"/> <p/>   
              </apex:pageBlockSection>   
             <apex:pageBlockButtons >
                   <apex:commandButton value="Enregistrer" action="{!enregistrer}"/>
                   <apex:commandButton value="cancel" action="{!cancel}"/>
             </apex:pageBlockButtons>
                           </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 

public class myControllerExtension {


private String name;


   public Opportunity Opp {get;set;}
   public Opportunity OppAcc {get;set;}
   

   
 
 
   ApexPages.StandardController controller;   
   public myControllerExtension(ApexPages.StandardController c)
   
   {
          Opp = (Opportunity)c.getRecord();
   }
     

      
 
 
 
 
        public PageReference Avenant()
      {
        return Page.Avenant;
      }
   
   
     public PageReference cancel()
     {
            PageReference opportunityPage = new ApexPages.StandardController(opp).view();
            opportunityPage.setRedirect(true);
            return opportunityPage;
     }
    
    
   public PageReference enregistrer() {

//add a news code to crate a new opportunity

}

 

 

how to retrieve the data entered in the apex page and create a new opportunity?

 

thanks.

 

 

Hi,

a like add in my visual page in bouton save.

 

this button will create a new record opportunity and not updated of the recording in court!

 

please how do?

 

 

 

thanks.

Hi,

 

please, how sandbox i can have ?

i have 2 developpeurs, and i like have 2 sand box, is possible?

 

 

Thanks.

Hi,

I coded this batch:

 

global class BalanceCalculBatchV3 implements Database.Batchable<sObject>{
String IDVar;
decimal var1=0, var2=0;
date dateEcheance;

        
global final String query ='SELECT id,name FROM Opportunity limit 4';        

global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator(query);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){

 List<Opportunity> opps = [select id,  Date_d_ech_ance_de_la_police__c, Total_montant_pay__c
                            from Opportunity];
   
 
 
 List<paiement__c> paiement = [SELECT Id, CreatedDate, montant_pay__c ,Encaissement_remboursement__c, Montant_rem__c,
                                        Opportunit__c FROM paiement__c];  
                                        
                        
 List<Quittance__c> quittance = [SELECT Id, Date_due1__c, Date_due10__c, Date_due11__c, Date_due12__c, Date_due2__c,
                                   Date_due3__c, Date_due4__c, Date_due5__c, Date_due6__c, Date_due7__c, Date_due8__c,
                                   Date_due9__c, Date_pay_del__c, DateDue__c, Echeance_paiement__c, Echeance1__c,
                                   Echeance10__c, Echeance11__c, Echeance12__c, Echeance2__c, Echeance3__c, Echeance4__c,
                                   Echeance5__c, Echeance6__c, Echeance7__c, Echeance8__c, Echeance9__c, Opportunit__c,
                                   Facturation_Avoir__c, Montant_d_avoir__c
                                   FROM Quittance__c];
 
 
/******************************************************************************************************************************/
    
    Integer l;
    l = opps.size();
if(l!=Null) {                       
    for (Integer i = 0; i<l; i++)
              {
                  IDVar=opps[i].Id;
                          
             Integer m;
             m = paiement.size();
if(m!=Null) {                      
         for (Integer s = 0; s<m; s++)
              {
              if(paiement[s].Opportunit__c== IDVar)
              {
                  
                         if(paiement[s].Encaissement_remboursement__c=='Encaissement')
                           {
                                var1 += paiement[s].montant_pay__c;
                           }
                         if(paiement[s].Encaissement_remboursement__c=='Remboursement')
                           {
                                var1 -= paiement[s].Montant_rem__c;
                           }
                }
               }
           }                                       
/******************************************************************************************************************************/                  
    dateEcheance=opps[i].Date_d_ech_ance_de_la_police__c;      

          
/******************************************************************************************************************************/                   
//calcul au niveau de la quittance.
Integer h;
h = quittance.size();     
if(h!=null)
{
     for (Integer n = 0; n<h; n++)
         {

           if (quittance[n].Opportunit__c== IDVar)
             {
        
           if(quittance[n].Facturation_Avoir__c=='Avoir')
             {
               var2 -= quittance[n].Montant_d_avoir__c;
             }
           if(quittance[n].Facturation_Avoir__c=='Facturation')
             {
/****************************************En fonction des 4 modes de paiement*****************************************/
/*******************************************Paiement annuel*********************************************************/

               if (quittance[n].Echeance_paiement__c =='Annuel' && quittance[n].Date_due1__c<=datetime.now())
                {
                      var2+=quittance[n].Echeance1__c;
                }

/******************************************Paiement Semestriel*******************************************************/

         if (quittance[n].Echeance_paiement__c =='Semestriel' && quittance[n].Date_due1__c<=datetime.now())
          {
              if(quittance[n].Date_due2__c<=datetime.now())
               {
                var2+=quittance[n].Echeance1__c+quittance[n].Echeance2__c;
               }else
               {
                var2+=quittance[n].Echeance1__c;
               }
          }
   // other traitement

                   
                          }
}                          
                    }
}
//calcul du montant final
opps[i].Total_montant_pay__c = var1-var2;  
 
                           
/****************************************************************************************************************/                  
                  
var1=0;
var2=0;
              }
}  

        List<Database.SaveResult> dsrs = Database.update(opps, false);
 


    
}

}

 

 

i have an  800 opportunity in my objet Opportunity;

 

when executing, I get this error:  First error: Too many script statements: 1000001.

please help me to resolve this problem.

 

thanks.

Hi,

i write a batch and  test method into this batch, my code of this batch is 87% couvred into my sand box  but  when I try to deploy in production I get an error only 12% of the batch code is covered.

 

this code of my test metode:

/***********************************************************************/

public static testmethod void testbatch()
{
    
  Test.startTest();
  BalanceCalculBatch ch = new BalanceCalculBatch();
  ID batchprocessid = Database.executeBatch(ch);
  Test.stopTest();
           
}

 

/*********************************************************************/

 

 

this is my match code:

 

/*********************************************************************/

global class BalanceCalculBatch implements Database.Batchable<sObject>{
String IDVar;
decimal var1=0, var2=0;
date dateEcheance;


String email;
Id toUserId;
Id fromUserId;

        
global final String query ='SELECT id,name FROM Opportunity';        

global Database.querylocator start(Database.BatchableContext BC){
            return Database.getQueryLocator(query);}

global void execute(Database.BatchableContext BC, List<Sobject> scope){

  List<Opportunity> opps = [select id,  Date_d_ech_ance_de_la_police__c, Total_montant_pay__c
                            from Opportunity  where Date_d_ech_ance_de_la_police__c > 2011-12-31];
   
   
    Integer l;
    l = opps.size();
if(l!=Null) {                       
    for (Integer i = 0; i<l; i++)
              {
                  IDVar=opps[i].Id;

 

//my traitement code

 

}

}

}

 

 

 

 

 

Help me, where is the problems?

 

thanks.

 

 

 

Moh.

 

Hi,

 

I want renamed my test class in production in order to deploy my code  sandbox.

my test class in the production is named  "test"  and in sandbox is named  "testClass"

 

how to rename

 

 

thanks.

Hi,

 

 

I get an error "  testcode: Type is not visible: test    " when I deploys my sand box to the production.

 

 

"testcode" is the name of my  test class.

 

I renamed my class test with "test" but I got an error at this level "Test.startTest();" in thecode of my  test  class. this error is " Methode does not exist or incorrect signature: Test.startTest()".

 

please help me.

 

thanks.

 

 

 

moh.

Hi,

 


I tried to execute a test class I had this error!

"

Visualforce Error


java.lang.reflect.InvocationTargetException

 

"

 

before  today my class exectute well!

 

please , is salesforce problem or is to my class test?

 

thanks.