• Avinash Ravi
  • NEWBIE
  • 70 Points
  • Member since 2015
  • 4i Apps Solutions


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 16
    Replies
Hi,

I have a custom button that is used to generate an order from a Quote. Whenever that is clicked, I want to display an error msg saying this will "create a single order for the Product. do you want to continue?"

How can I do that? Right now the custom button goes like this: /flow/Quote_to_Order?QuoteID={!Quote.Id}&retURL=/{!Quote.Id}
Hi All,

I'm trying to create a Formula Field that has an image like a button that says "Generate Contract". When clicked, it has to run a flow. I'm trying to create the hyperlink but the image isn't showing at all. Thoughts?

IF( AND(Ready_for_Contract__c = TRUE,  ISNULL(ContractId)),  

HYPERLINK("/flow/Opportunity_to_Contract&OpptyID=Opportunity.Id&retURL=/Opportunity.Id", IMAGE("/servlet/servlet.ImageServer?id=0154E000000DVxa&oid=00D4E000000D6rZ&lastMod=1470934396000", "Generate",30,130))  , "")
Hi, 

I have this custom button that I'm using to Activate an order when clicked. Now I want this button to be hidden or grayed out when order status = Activated.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 

this.disabled=true; 
var c = new sforce.SObject("Order"); 

c.id = "{!Order.Id}"; 
c.Status = 'Activated'; 
c.Sync__c = true; 
result = sforce.connection.update([c]); 

window.location.reload();

Can someone help me out?
I have this batch class that is not sending out an email when I query for an email template. The batch gets processed succcessfully with no errors but still doesn't send out an email.

It works when I use a plaintextbody instead of querying for a template. Can someone help me out?
 
global class sendEmailtoVolntr implements schedulable,Database.Batchable<sObject>,Database.Stateful
{

    global String Query = null;

    global sendEmailtoVolntr (){
  
       Query='Select Id,Name,For_Centre__c,For_Date__c,Leap_Centre__c,Leap_Centre__r.Name,Send_Email__c,Short_Description__c,Uploaded_By__c from Leap_Weekly_Curriculum__c where Send_Email__c = FALSE and For_Date__c >= TODAY';
   
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(SchedulableContext SC){
        sendEmailtoVolntr sendEmail= new sendEmailtoVolntr ();
        database.executebatch(sendEmail,1);
     }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
    
        List<Attachment> attachments = new List<Attachment> ();
        Map<Id,Attachment> attachmentId = new Map<Id,Attachment> ();
        Set<Id> LeapIds = new Set<Id> ();
        List<Leap_Weekly_Curriculum__c> leapCurrilist = new List<Leap_Weekly_Curriculum__c> ();
        List<Leap_Weekly_Curriculum__c> updateLeapList = new List<Leap_Weekly_Curriculum__c> ();
    
        for(sObject so : scope){ 
    
            Leap_Weekly_Curriculum__c leapCurri= (Leap_Weekly_Curriculum__c)so;
            LeapIds.add(leapcurri.Id);
            leapCurrilist.add(leapCurri);
           } 
        attachments = [SELECT Id,ParentId, Name, Body, ContentType FROM Attachment WHERE Parentid IN :LeapIds];
          //Assuming that there will be only one attachment for each Leap Curriculum record           
        for(Attachment att : attachments)
        {
            attachmentId.put(att.ParentId,att);
        }
        attachments.clear();
        
        for(Leap_Weekly_Curriculum__c LWC: leapCurrilist)
        {
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            List<Messaging.SingleEmailMessage> theEmails = new List<Messaging.SingleEmailMessage> ();
            List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            List<String> toAddresses = new List<String> ();
            String emailErrorReport = null;
            
            for(Volunteers__c vol: [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)])
            toAddresses.add(vol.Email__c);
            //List<Volunteers__c> volListTeamp = [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)];
            system.debug(toAddresses);
    
            efa.setFileName(attachmentId.get(LWC.Id).Name);
            efa.setBody(attachmentId.get(LWC.Id).Body);
            efa.setContentType(attachmentId.get(LWC.Id).ContentType);
            emailAttachments.add(efa);
            
            EmailTemplate template = [Select id, Body from EmailTemplate
                          where DeveloperName = 'Volunteer_Requirement_Update'];
            
            if(emailAttachments.size() > 0)
            {
                email.setToAddresses(toAddresses);
                //email.setSubject('test');
                email.setTemplateId(template.Id);
                email.setFileAttachments(emailAttachments);
                theEmails.add(email);
            }
            
            if(theEmails.size() > 0)
            {
                
                Messaging.SendEmailResult[] results = Messaging.sendEmail(theEmails,false);
                Messaging.SendEmailError[] errors = new List<Messaging.SendEmailError>();
                
                for( Messaging.SendEmailResult currentResult : results ) 
                {
                    errors = currentResult.getErrors();
                    if( null != errors ) 
                    {
                        for( Messaging.SendEmailError currentError : errors ) 
                        {
                            emailErrorReport = emailErrorReport + '(' +  currentError.getStatusCode() + ')' + currentError.getMessage() + '\r' ;
                        }
                    }
                }
    
                system.debug('error : ' + emailErrorReport);

             }

            System.debug('HEAP_SIZE Used:'+ Limits.getHeapSize()); 
            
            if(emailErrorReport != null){
                break;
            }
            else
            {
                LWC.send_EMail__c = TRUE;
                updateLeapList.add(LWC);  
            }
            
            if(updateLeapList.size()>0)
            update updateLeapList;
            
           /* if(emailErrorReport != null){
                System.abortJob(BC.getJobId()); 
                List<sObject> so = scope;
                Leap_Weekly_Curriculum__c lwcr= (Leap_Weekly_Curriculum__c )so[0];          
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresseser = new String[] {'rahmeshms@outlook.com'};
                mail.setToAddresses(toAddresseser);
                mail.setSubject('Email Job is aborted'); 
                mail.setPlainTextBody('The send email job is aborted due to Leap Curriculum : '+lwcr.Name+' '+lwcr.Short_Description__c+ ' '+lwcr.Id+ 'Please check the error report and take action accordingly.\n\n\t Error - '+emailErrorReport);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }*/
       } 
       
   }
global void finish(Database.BatchableContext BC){

    }


    
        }

 
I need to send out an email with attachment, whenever an attachment is added to a record. Is this possible via the proces builder or do I have no choice but to write a trigger?
Error: 
Attachmentstest
Fail
System.NullPointerException: Argument 1 cannot be null
Class.sendEmailtoVolntr.start: line 18, column 1

Main Class:
 
global class sendEmailtoVolntr implements schedulable,Database.Batchable<sObject>,Database.Stateful
{

public sendEmailtoVolntr(String c) {
    }
    global String Query = null;

    global sendEmailtoVolntr (){
  
       Query='Select Id,Name,For_Centre__c,For_Date__c,Leap_Centre__c,Leap_Centre__r.Name,Send_Email__c,Short_Description__c,Uploaded_By__c from Leap_Weekly_Curriculum__c where Send_Email__c = FALSE and For_Date__c >= TODAY';
   
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(SchedulableContext SC){
        sendEmailtoVolntr sendEmail= new sendEmailtoVolntr ();
        database.executebatch(sendEmail,1);
     }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
    
        List<Attachment> attachments = new List<Attachment> ();
        Map<Id,Attachment> attachmentId = new Map<Id,Attachment> ();
        Set<Id> LeapIds = new Set<Id> ();
        List<Leap_Weekly_Curriculum__c> leapCurrilist = new List<Leap_Weekly_Curriculum__c> ();
        List<Leap_Weekly_Curriculum__c> updateLeapList = new List<Leap_Weekly_Curriculum__c> ();
    
        for(sObject so : scope){ 
    
            Leap_Weekly_Curriculum__c leapCurri= (Leap_Weekly_Curriculum__c)so;
            LeapIds.add(leapcurri.Id);
            leapCurrilist.add(leapCurri);
           } 
        attachments = [SELECT Id,ParentId, Name, Body, ContentType FROM Attachment WHERE Parentid IN :LeapIds];
          //Assuming that there will be only one attachment for each Leap Curriculum record           
        for(Attachment att : attachments)
        {
            attachmentId.put(att.ParentId,att);
        }
        attachments.clear();
        
        for(Leap_Weekly_Curriculum__c LWC: leapCurrilist)
        {
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            List<Messaging.SingleEmailMessage> theEmails = new List<Messaging.SingleEmailMessage> ();
            List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            List<String> toAddresses = new List<String> ();
            String emailErrorReport = null;
            
            for(Volunteers__c vol: [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)])
            toAddresses.add(vol.Email__c);
            //List<Volunteers__c> volListTeamp = [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)];
            system.debug(toAddresses);
    
            efa.setFileName(attachmentId.get(LWC.Id).Name);
            efa.setBody(attachmentId.get(LWC.Id).Body);
            efa.setContentType(attachmentId.get(LWC.Id).ContentType);
            emailAttachments.add(efa);
            
            if(emailAttachments.size() > 0)
            {
                email.setToAddresses(toAddresses);
                email.setSubject('test');
                email.setPlainTextBody('For Leap Curriculum : ID -  ' + LWC.Id + ' Name - ' + LWC.Name + ' Short Description - ' + LWC.Short_Description__c + '.');
                email.setFileAttachments(emailAttachments);
                theEmails.add(email);
            }
            
            if(theEmails.size() > 0)
            {
                
                Messaging.SendEmailResult[] results = Messaging.sendEmail(theEmails,false);
                Messaging.SendEmailError[] errors = new List<Messaging.SendEmailError>();
                
                for( Messaging.SendEmailResult currentResult : results ) 
                {
                    errors = currentResult.getErrors();
                    if( null != errors ) 
                    {
                        for( Messaging.SendEmailError currentError : errors ) 
                        {
                            emailErrorReport = emailErrorReport + '(' +  currentError.getStatusCode() + ')' + currentError.getMessage() + '\r' ;
                        }
                    }
                }
    
                system.debug('error : ' + emailErrorReport);

             }

            System.debug('HEAP_SIZE Used:'+ Limits.getHeapSize()); 
            
            if(emailErrorReport != null){
                break;
            }
            else
            {
                LWC.send_EMail__c = TRUE;
                updateLeapList.add(LWC);  
            }
            
            if(updateLeapList.size()>0)
            update updateLeapList;
            
            if(emailErrorReport != null){
                System.abortJob(BC.getJobId()); 
                List<sObject> so = scope;
                Leap_Weekly_Curriculum__c lwcr= (Leap_Weekly_Curriculum__c )so[0];          
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresseser = new String[] {'rahmeshms@outlook.com'};
                mail.setToAddresses(toAddresseser);
                mail.setSubject('Email Job is aborted'); 
                mail.setPlainTextBody('The send email job is aborted due to Leap Curriculum : '+lwcr.Name+' '+lwcr.Short_Description__c+ ' '+lwcr.Id+ 'Please check the error report and take action accordingly.\n\n\t Error - '+emailErrorReport);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
       } 
       
   }
global void finish(Database.BatchableContext BC){

    }


    
        }

Test Class: 
 
@isTest
public with sharing class Attachmentstest{
public static testmethod void Attachmentstest()
{

        Leap_Weekly_Curriculum__c record = new Leap_Weekly_Curriculum__c();
        Attachment attachment1 = new Attachment();
        Leap_Centre__c lcr = new Leap_Centre__c();
        
       lcr.Name = 'Anaikkum Karangal';
       lcr.Location__c = 'test location';
       lcr.Primary_Representative__c = 'Avinash';
       lcr.Primary_Rep_s_Mobile__c = '9176473115';
       lcr.Primary_Rep_s_Email__c = 'asd@asd.com';
       
       insert lcr;
       
       record.Short_Description__c = 'test record';
       record.For_Centre__c = 'Anaikkum Karangal';
       record.For_Date__c = Date.Today() + 1;
       record.Send_Email__c = FALSE;
       record.Uploaded_By__c = 'Avinash'; 
       record.Leap_Centre__c = lcr.Id;
     
        // Insert the record
        insert record;
        system.debug(record);
        
        // Insert Attachments;
        attachment1.Name='Unit Test Attachment';
        attachment1.ParentId = record.Id;
        attachment1.body=Blob.valueOf('Unit Test Attachment Body');
        insert attachment1;
        
 String Query='Select Id,Name,For_Centre__c,For_Date__c,Leap_Centre__c,Leap_Centre__r.Name,Send_Email__c,Short_Description__c,Uploaded_By__c from Leap_Weekly_Curriculum__c where Send_Email__c = FALSE and For_Date__c >= TODAY';
 
       Test.startTest();
       sendEmailtoVolntr c = new sendEmailtoVolntr(query);
       Database.executeBatch(c);
       Test.stopTest();   
 
 }
     
 }

Don't understand what's going wrong.. please help out.
global class sendEmailtoVolntr implements schedulable,Database.Batchable<sObject>,Database.Stateful
{
    global String Query = null;

    global sendEmailtoVolntr (){
  
       Query='Select Id,Name,For_Centre__c,For_Date__c,Leap_Centre__c,Leap_Centre__r.Name,Send_Email__c,Short_Description__c,Uploaded_By__c from Leap_Weekly_Curriculum__c where Send_Email__c = FALSE and For_Date__c >= TODAY';
   
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(SchedulableContext SC){
        sendEmailtoVolntr sendEmail= new sendEmailtoVolntr ();
        database.executebatch(sendEmail,1);
     }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
    
        List<Attachment> attachments = new List<Attachment> ();
        Map<Id,Attachment> attachmentId = new Map<Id,Attachment> ();
        Set<Id> LeapIds = new Set<Id> ();
        List<Leap_Weekly_Curriculum__c> leapCurrilist = new List<Leap_Weekly_Curriculum__c> ();
        List<Leap_Weekly_Curriculum__c> updateLeapList = new List<Leap_Weekly_Curriculum__c> ();
    
        for(sObject so : scope){ 
    
            Leap_Weekly_Curriculum__c leapCurri= (Leap_Weekly_Curriculum__c)so;
            LeapIds.add(leapcurri.Id);
            leapCurrilist.add(leapCurri);
           } 
        attachments = [SELECT Id,ParentId, Name, Body, ContentType FROM Attachment WHERE Parentid IN :LeapIds];
          //Assuming that there will be only one attachment for each Leap Curriculum record           
        for(Attachment att : attachments)
        {
            attachmentId.put(att.ParentId,att);
        }
        attachments.clear();
        
        for(Leap_Weekly_Curriculum__c LWC: leapCurrilist)
        {
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            List<Messaging.SingleEmailMessage> theEmails = new List<Messaging.SingleEmailMessage> ();
            List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            List<String> toAddresses = new List<String> ();
            String emailErrorReport = null;
            
            for(Volunteers__c vol: [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)])
            toAddresses.add(vol.Email__c);
            //List<Volunteers__c> volListTeamp = [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)];
            system.debug(toAddresses);
    
            efa.setFileName(attachmentId.get(LWC.Id).Name);
            efa.setBody(attachmentId.get(LWC.Id).Body);
            efa.setContentType(attachmentId.get(LWC.Id).ContentType);
            emailAttachments.add(efa);
            
            if(emailAttachments.size() > 0)
            {
                email.setToAddresses(toAddresses);
                email.setSubject('test');
                email.setPlainTextBody('For Leap Curriculum : ID -  ' + LWC.Id + ' Name - ' + LWC.Name + ' Short Description - ' + LWC.Short_Description__c + '.');
                email.setFileAttachments(emailAttachments);
                theEmails.add(email);
            }
            
            if(theEmails.size() > 0)
            {
                
                Messaging.SendEmailResult[] results = Messaging.sendEmail(theEmails,false);
                Messaging.SendEmailError[] errors = new List<Messaging.SendEmailError>();
                
                for( Messaging.SendEmailResult currentResult : results ) 
                {
                    errors = currentResult.getErrors();
                    if( null != errors ) 
                    {
                        for( Messaging.SendEmailError currentError : errors ) 
                        {
                            emailErrorReport = emailErrorReport + '(' +  currentError.getStatusCode() + ')' + currentError.getMessage() + '\r' ;
                        }
                    }
                }
    
                system.debug('error : ' + emailErrorReport);

             }

            System.debug('HEAP_SIZE Used:'+ Limits.getHeapSize()); 
            
            if(emailErrorReport != null){
                break;
            }
            else
            {
                LWC.send_EMail__c = TRUE;
                updateLeapList.add(LWC);  
            }
            
            if(updateLeapList.size()>0)
            update updateLeapList;
            
            if(emailErrorReport != null){
                System.abortJob(BC.getJobId()); 
                List<sObject> so = scope;
                Leap_Weekly_Curriculum__c lwcr= (Leap_Weekly_Curriculum__c )so[0];          
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresseser = new String[] {'rahmeshms@outlook.com'};
                mail.setToAddresses(toAddresseser);
                mail.setSubject('Email Job is aborted'); 
                mail.setPlainTextBody('The send email job is aborted due to Leap Curriculum : '+lwcr.Name+' '+lwcr.Short_Description__c+ ' '+lwcr.Id+ 'Please check the error report and take action accordingly.\n\n\t Error - '+emailErrorReport);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
       } 
       
   }
global void finish(Database.BatchableContext BC){

    }


    
        }

I'm new to development and need help writing a test class for this batch class. I have no idea where to start or end. Please help out.

Thanks,
Avinash
Can someone help me understand this piece of code? I'm still a newbie and any help on the flow would be greatly appreciated
 
trigger AptsActivityHistoryTrigger on Task (before delete, before update) {
    String ERROR_MESSAGE = 'Update/Delete of Activity History entries are not permitted';
    String PROFILE_SYS_ADMIN = 'System Administrator';
    Id sysAdminProfileId=null;
    // Bulk processing NOT supported
    if (Trigger.size != 1) {
        return;
    } 
    //applicable for update and deletes only
    if (Trigger.isBefore) {
        if ((Trigger.isUpdate) || (Trigger.isDelete)) {
            Task taskObj = [select Id, whatId, status from Task where Id = :Trigger.old[0].Id];
            
            // parent is an agreement?
            List <Apttus__APTS_Agreement__c> agmts = [select Id from Apttus__APTS_Agreement__c where Id = :taskObj.whatId];

            // sys admin profile id
            List<Profile> profileList = [select Id, Name 
                            from Profile
                            where Name = :PROFILE_SYS_ADMIN];
                            
            if ((profileList != null) && (!profileList.isEmpty())) {    
                sysAdminProfileId = profileList[0].Id;
            }   

            if (agmts == null || agmts.size()<=0 || taskObj.Status != 'Completed' || sysAdminProfileId == UserInfo.getProfileId() ) {
                return;
            }
            
            //error to indicate action is not permitted
            String errMsg = ERROR_MESSAGE;            
            if (Trigger.isUpdate) {
                Trigger.new[0].addError(errMsg);
            } else {
                Trigger.old[0].addError(errMsg);
            }
        }       
    }
    return;

}
Can someone help me understand the flow on this codeblock? I'm still a newbie so any help on the flow would be greatly apprecieated
 
trigger AptsActivityHistoryTrigger on Task (before delete, before update) {
    String ERROR_MESSAGE = 'Update/Delete of Activity History entries are not permitted';
    String PROFILE_SYS_ADMIN = 'System Administrator';
    Id sysAdminProfileId=null;
    // Bulk processing NOT supported
    if (Trigger.size != 1) {
        return;
    } 
    //applicable for update and deletes only
    if (Trigger.isBefore) {
        if ((Trigger.isUpdate) || (Trigger.isDelete)) {
            Task taskObj = [select Id, whatId, status from Task where Id = :Trigger.old[0].Id];
            
            // parent is an agreement?
            List <Apttus__APTS_Agreement__c> agmts = [select Id from Apttus__APTS_Agreement__c where Id = :taskObj.whatId];

            // sys admin profile id
            List<Profile> profileList = [select Id, Name 
                            from Profile
                            where Name = :PROFILE_SYS_ADMIN];
                            
            if ((profileList != null) && (!profileList.isEmpty())) {    
                sysAdminProfileId = profileList[0].Id;
            }   

            if (agmts == null || agmts.size()<=0 || taskObj.Status != 'Completed' || sysAdminProfileId == UserInfo.getProfileId() ) {
                return;
            }
            
            //error to indicate action is not permitted
            String errMsg = ERROR_MESSAGE;            
            if (Trigger.isUpdate) {
                Trigger.new[0].addError(errMsg);
            } else {
                Trigger.old[0].addError(errMsg);
            }
        }       
    }
    return;

}

 
Hi All,

Can some help me understand the flow of actions on the below code block? Pardon me if lame, I'm still a newbie... Thanks
 
trigger AptsActivityHistoryTrigger on Task (before delete, before update) {
    String ERROR_MESSAGE = 'Update/Delete of Activity History entries are not permitted';
    String PROFILE_SYS_ADMIN = 'System Administrator';
    Id sysAdminProfileId=null;
    // Bulk processing NOT supported
    if (Trigger.size != 1) {
        return;
    } 
    //applicable for update and deletes only
    if (Trigger.isBefore) {
        if ((Trigger.isUpdate) || (Trigger.isDelete)) {
            Task taskObj = [select Id, whatId, status from Task where Id = :Trigger.old[0].Id];
            
            // parent is an agreement?
            List <Apttus__APTS_Agreement__c> agmts = [select Id from Apttus__APTS_Agreement__c where Id = :taskObj.whatId];

            // sys admin profile id
            List<Profile> profileList = [select Id, Name 
                            from Profile
                            where Name = :PROFILE_SYS_ADMIN];
                            
            if ((profileList != null) && (!profileList.isEmpty())) {    
                sysAdminProfileId = profileList[0].Id;
            }   

            if (agmts == null || agmts.size()<=0 || taskObj.Status != 'Completed' || sysAdminProfileId == UserInfo.getProfileId() ) {
                return;
            }
            
            //error to indicate action is not permitted
            String errMsg = ERROR_MESSAGE;            
            if (Trigger.isUpdate) {
                Trigger.new[0].addError(errMsg);
            } else {
                Trigger.old[0].addError(errMsg);
            }
        }       
    }
    return;

}

 
Hi All,

I've been trying to write a test class for this but not able to cover code at all! Newbie to SFDC and just learning APEX.. Please help out!
 
trigger updateLeapCentre on Volunteers__c (before update,after update) {

    Map<Id,LEap_Centre__c> LeapCentreMap = new Map<Id,Leap_Centre__c> ();
    Map<String,Leap_Centre__c> LeapCentredMap = new Map<String,Leap_Centre__c> ();
    Map<Id, Map<Id,LeapVolunteer__c >> leapVoluntrMap = new Map<Id, Map<Id,LeapVolunteer__c >> ();
    boolean leapFound = FALSE;
    String errorVol = 'There already exists an association for the Volunteer with the requested Centre. Please check and correct the data.';
    String errorLeap = 'There is no Leap Centre created for one of the requested centre. Please create Leap Centre first and then associate the volunteer to Centre.';
    for(Leap_Centre__c temp : [Select Id,Name from Leap_Centre__c])
    {
        LeapCentreMap.put(temp.Id,temp);
        LeapCentredMap.put(temp.Name,temp);
    } 
    List<LeapVolunteer__c > leapVolntrDeleteList = new List<LeapVolunteer__c > ();
    
    for(LeapVolunteer__c leapVol : [Select Id,Volunteer__c,Leap_Centre__c from LeapVolunteer__c  where Volunteer__c  IN : Trigger.newMap.keySet() ])
    {
        Map<Id,LeapVolunteer__c > tempMap = new Map<Id,LeapVolunteer__c > ();
        if(leapVoluntrMap.get(leapVol.Volunteer__c) == null)
        {
            tempMap.put(leapVol.Id,leapVol);
            leapVoluntrMap.put(leapVol.Volunteer__c,tempMap);
         }
         else
         {
             tempMap = leapVoluntrMap.get(leapVol.Volunteer__c);
             tempMap.put(leapVol.Id,leapVol);
             leapVoluntrMap.put(leapVol.Volunteer__c,tempMap);
         }
    }
    
    List<Volunteers__c> volList = new List<Volunteers__c> ();  
    
    if(trigger.isBefore && trigger.isUpdate)
    {
        for(Volunteers__c vol : Trigger.new)
        {
            Map<Id,LeapVolunteer__c > leapVoluntrCheckMap = new Map<Id,LeapVolunteer__c > ();
            leapVoluntrCheckMap = leapVoluntrMap.get(vol.Id);
            String [] centres = vol.Centre_Allocation__c != null ? vol.Centre_Allocation__c.split(';') : null ;
            
            if(trigger.oldMap.get(vol.Id).Centre_Allocation__c <> vol.Centre_Allocation__c)
            {
                 if(vol.Centre_Allocation__c != null)
                 {       
                    
                    system.debug('***'+centres+'***');
                    for(String centre : centres)
                    {
                        if(LeapCentredMap.get(centre) != null)
                        {
                            boolean volFound = FALSE;
                            system.debug('***'+centre+'***'+'&&&'+centre.trim()+'&&&');
                            if(leapVoluntrCheckMap != null)
                            {
                                for(Id iterator : leapVoluntrCheckMap.keySet())
                                {
                                    if(leapVoluntrCheckMap.get(iterator).Leap_Centre__c == LeapCentredMap.get(centre).Id)
                                    volFound = TRUE;
                                }
                            }
                            
                            if(volFound == FALSE)
                            {
                                LeapVolunteer__c leapVolInsert = new LeapVolunteer__c (Leap_Centre__c=LeapCentredMap.get(centre).Id,Volunteer__c=Vol.Id);
                                insert leapVolInsert;
                            }
                            
                        }  
                        else
                            vol.addError(errorLeap);
                     }
    
                  }
               
                  if(leapVoluntrCheckMap != null ? leapVoluntrCheckMap.size() > 0 ? TRUE : FALSE : FALSE )
                     {
                         for(Id iterator : leapVoluntrCheckMap.keySet())
                         {
                             if(vol.Centre_Allocation__c != null ? !vol.Centre_Allocation__c.contains(leapCentreMap.get(leapVoluntrCheckMap.get(iterator).Leap_Centre__c).Name) : TRUE)
                             leapVolntrDeleteList.add(leapVoluntrCheckMap.get(iterator));
                             
                         }
                     }
               }
        }
    }
    
    
    if(leapVolntrDeleteList != null ? leapVolntrDeleteList.size() > 0 ? TRUE : FALSE : FALSE )
    delete leapVolntrDeleteList;
}
Thanks in Advance!

 
I'm trying to write a trigger that will populate fields such as region, country, etc from the user who creates the record, i.e, the owner.
This is what I've gotten so far
trigger UpdateValonServiceAgmt on Apttus__APTS_Agreement__c (before insert, before update) {

Map<String, User> UserMap = new Map<String, User> ();
 for(User temp : [Select Id, Name from User])
 UserMap.put(temp.Name,temp);

List<User> userList = new List<User> ();  

for(Apttus__APTS_Agreement__c agmt: Trigger.new)
    {
     if(trigger.isBefore && trigger.isInsert)
     agmt.Business_Contact__c = UserMap.get(agmt.Owner).Id ;

    }
}

But I keep getting an error that says "Error: Compile Error: Incompatible key type Name for Map<Id,User> at line 12 column 33". Right now I'm trying to populate a field called Business Contact from the user record. Likewise, I have to fill out the region and country from the user record as well.

Please help out.

Thanks in Advance.
All,

I have this batch class that I'm using to send emails to specific people.. But I'm not sure how I'm supposed to write a test class for it. I've done it for simple insert and update operations but I have no idea where to start from with this. Can someone help me out?

Thanks in Advance.
global class sendEmailtoVolntr implements schedulable,Database.Batchable<sObject>,Database.Stateful
{
    global String Query = null;

    global sendEmailtoVolntr (){
  
       Query='Select Id,Name,For_Centre__c,For_Date__c,Leap_Centre__c,Leap_Centre__r.Name,Send_Email__c,Short_Description__c,Uploaded_By__c from Leap_Weekly_Curriculum__c where Send_Email__c = FALSE and For_Date__c >= TODAY';
   
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(SchedulableContext SC){
        sendEmailtoVolntr sendEmail= new sendEmailtoVolntr ();
        database.executebatch(sendEmail,1);
     }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
    
        List<Attachment> attachments = new List<Attachment> ();
        Map<Id,Attachment> attachmentId = new Map<Id,Attachment> ();
        Set<Id> LeapIds = new Set<Id> ();
        List<Leap_Weekly_Curriculum__c> leapCurrilist = new List<Leap_Weekly_Curriculum__c> ();
        List<Leap_Weekly_Curriculum__c> updateLeapList = new List<Leap_Weekly_Curriculum__c> ();
    
        for(sObject so : scope){ 
    
            Leap_Weekly_Curriculum__c leapCurri= (Leap_Weekly_Curriculum__c)so;
            LeapIds.add(leapcurri.Id);
            leapCurrilist.add(leapCurri);
           } 
        attachments = [SELECT Id,ParentId, Name, Body, ContentType FROM Attachment WHERE Parentid IN :LeapIds];
          //Assuming that there will be only one attachment for each Leap Curriculum record           
        for(Attachment att : attachments)
        {
            attachmentId.put(att.ParentId,att);
        }
        attachments.clear();
        
        for(Leap_Weekly_Curriculum__c LWC: leapCurrilist)
        {
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            List<Messaging.SingleEmailMessage> theEmails = new List<Messaging.SingleEmailMessage> ();
            List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            List<String> toAddresses = new List<String> ();
            String emailErrorReport = null;
            
            for(Volunteers__c vol: [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)])
            toAddresses.add(vol.Email__c);
            //List<Volunteers__c> volListTeamp = [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)];
            system.debug(toAddresses);
    
            efa.setFileName(attachmentId.get(LWC.Id).Name);
            efa.setBody(attachmentId.get(LWC.Id).Body);
            efa.setContentType(attachmentId.get(LWC.Id).ContentType);
            emailAttachments.add(efa);
            
            if(emailAttachments.size() > 0)
            {
                email.setToAddresses(toAddresses);
                email.setSubject('test');
                email.setPlainTextBody('For Leap Curriculum : ID -  ' + LWC.Id + ' Name - ' + LWC.Name + ' Short Description - ' + LWC.Short_Description__c + '.');
                email.setFileAttachments(emailAttachments);
                theEmails.add(email);
            }
            
            if(theEmails.size() > 0)
            {
                
                Messaging.SendEmailResult[] results = Messaging.sendEmail(theEmails,false);
                Messaging.SendEmailError[] errors = new List<Messaging.SendEmailError>();
                
                for( Messaging.SendEmailResult currentResult : results ) 
                {
                    errors = currentResult.getErrors();
                    if( null != errors ) 
                    {
                        for( Messaging.SendEmailError currentError : errors ) 
                        {
                            emailErrorReport = emailErrorReport + '(' +  currentError.getStatusCode() + ')' + currentError.getMessage() + '\r' ;
                        }
                    }
                }
    
                system.debug('error : ' + emailErrorReport);

             }

            System.debug('HEAP_SIZE Used:'+ Limits.getHeapSize()); 
            
            if(emailErrorReport != null){
                break;
            }
            else
            {
                LWC.send_EMail__c = TRUE;
                updateLeapList.add(LWC);  
            }
            
            if(updateLeapList.size()>0)
            update updateLeapList;
            
            if(emailErrorReport != null){
                System.abortJob(BC.getJobId()); 
                List<sObject> so = scope;
                Leap_Weekly_Curriculum__c lwcr= (Leap_Weekly_Curriculum__c )so[0];          
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresseser = new String[] {'rahmeshms@outlook.com'};
                mail.setToAddresses(toAddresseser);
                mail.setSubject('Email Job is aborted'); 
                mail.setPlainTextBody('The send email job is aborted due to Leap Curriculum : '+lwcr.Name+' '+lwcr.Short_Description__c+ ' '+lwcr.Id+ 'Please check the error report and take action accordingly.\n\n\t Error - '+emailErrorReport);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
       } 
       
   }
global void finish(Database.BatchableContext BC){

    }


    
        }

 
Hi All,

I'm trying to write a test class to this class below. But I'm not able to cover lines 12 & 20. Can someone help me out please? 
 
trigger orientationDateUpdate on Registrations__c (before insert, before update) {

if(Trigger.isInsert && Trigger.isBefore)
{
    for(Registrations__c temp : Trigger.new)
    {
        if(temp.Planned_Orientation_Date__c == null)
        {
            Date date1 = Date.newinstance(1900,1,7);
            Date date2 = Date.TODAY();
            
            if(date2.day()<7 && math.MOD(date1.daysBetween(date2),7) != 0 && math.MOD(date2.month(),2) != 0)
            {
                date2 = date2.addDays(7-math.MOD(date1.daysBetween(date2),7)); 
            }
            else
            {
                date2 = Date.newInstance(date2.year(), math.MOD(date2.month(),2) != 0 ? date2.month()+2 : date2.month()+1 , 1);
                if(math.MOD(date1.daysBetween(date2),7) != 0)
                date2 = date2.addDays(7-math.MOD(date1.daysBetween(date2),7));    
            }
            system.debug('******Planned Orientation Date ***** ' + date2 );
            temp.Planned_Orientation_Date__c = date2;
        }
    }
}

}
Thanks in Advance,

Avinash
 
Hi All,

I have a custom object called Leap_Weekly_Curriculum__c and I need a VF page that will help me input values into it and also upload a file which should get added to the attachments related list of the same record. Please help.
Hi All,

I have a VF form that I've embedded into my wordpress site. When someone fills it out and hits submit, the 'thank you' redirect url seems to open inside the same frame as the form (in the same parent page). Is there someway I can modify this to redirect from the form buttons to open into a new parent window?

Fill out the form or hit cancel in the below link and you'll see what I mean..

http://prayag.thezrox.in/about/become-a-superhero

Please help!
Hi All,

I need help creating a date formula field that will return the date for the first weekend of every odd month.

The field should calculate based on the record creation date and should return the date value for the first weekend of the closest odd month from then.

Pleas help.

Thanks,
Avinash
public with sharing class ThePrayagMarathon {

   public ThePrayagMarathon() {
   
   }
   
   public Registration__c Regs {get;set;}
   
   public PageReference save()
   { 
    
    if(Registration__c.Marathon_Category__c == null || Registration__c.Marathon_Distance__c == null || Registration__c.Name_of_the_Participant__c == null || Registration__c.DOB__c == null || Registration__c.Address_Line_1__c == null || Registration__c.City__c == null || Registration__c.State__c == null || Registration__c.Pin_Code__c == null || Registration__c.Email__c == null || Registration__c.Mobile_Number__c == null ||  Registration__c.Tee_Shirt_Size__c == null)
   {
    
    ApexPages.addMessage(new Apexpages.Message(ApexPages.severity.error,'Please fill all mandatory fields.'));
                return null;
   }
    
        System.debug('Entered into save');
        RecordType regRtype = [SELECT Name,id FROM RecordType WHERE SobjectType='Registration__c' and Name='Marathon' LIMIT 1];
        system.debug('Record type of inserted registration..'+regRtype.id);
        Regs.RecordTypeId = regRtype.id;
        Regs.type__c = 'New Participant'; 
        try {      
        insert regs;
        if(Regs.Marathon_Category__c == 'Rs. 700 /- For Ages Above 12')
        {pagereference Page = new pagereference('https://www.payumoney.com/paybypayumoney/#/37061');
        return Page;}
        else
        {pagereference Page = new pagereference('https://www.payumoney.com/paybypayumoney/#/37063');
        return Page;}
           } 
         catch(DMLException e) {
        return null;
        }      
        }
        
        public PageReference cancel()
        {pagereference Page = new pagereference('http://www.joinprayag.com');
        return Page;}
        
        
        public ThePrayagMarathon(ApexPages.StandardController controller) {
        this.regs = (Registration__c)controller.getRecord();
        system.debug('m here ....'+regs);            
        }

}
Hi,

I have a custom button that is used to generate an order from a Quote. Whenever that is clicked, I want to display an error msg saying this will "create a single order for the Product. do you want to continue?"

How can I do that? Right now the custom button goes like this: /flow/Quote_to_Order?QuoteID={!Quote.Id}&retURL=/{!Quote.Id}
Error: 
Attachmentstest
Fail
System.NullPointerException: Argument 1 cannot be null
Class.sendEmailtoVolntr.start: line 18, column 1

Main Class:
 
global class sendEmailtoVolntr implements schedulable,Database.Batchable<sObject>,Database.Stateful
{

public sendEmailtoVolntr(String c) {
    }
    global String Query = null;

    global sendEmailtoVolntr (){
  
       Query='Select Id,Name,For_Centre__c,For_Date__c,Leap_Centre__c,Leap_Centre__r.Name,Send_Email__c,Short_Description__c,Uploaded_By__c from Leap_Weekly_Curriculum__c where Send_Email__c = FALSE and For_Date__c >= TODAY';
   
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(SchedulableContext SC){
        sendEmailtoVolntr sendEmail= new sendEmailtoVolntr ();
        database.executebatch(sendEmail,1);
     }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
    
        List<Attachment> attachments = new List<Attachment> ();
        Map<Id,Attachment> attachmentId = new Map<Id,Attachment> ();
        Set<Id> LeapIds = new Set<Id> ();
        List<Leap_Weekly_Curriculum__c> leapCurrilist = new List<Leap_Weekly_Curriculum__c> ();
        List<Leap_Weekly_Curriculum__c> updateLeapList = new List<Leap_Weekly_Curriculum__c> ();
    
        for(sObject so : scope){ 
    
            Leap_Weekly_Curriculum__c leapCurri= (Leap_Weekly_Curriculum__c)so;
            LeapIds.add(leapcurri.Id);
            leapCurrilist.add(leapCurri);
           } 
        attachments = [SELECT Id,ParentId, Name, Body, ContentType FROM Attachment WHERE Parentid IN :LeapIds];
          //Assuming that there will be only one attachment for each Leap Curriculum record           
        for(Attachment att : attachments)
        {
            attachmentId.put(att.ParentId,att);
        }
        attachments.clear();
        
        for(Leap_Weekly_Curriculum__c LWC: leapCurrilist)
        {
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            List<Messaging.SingleEmailMessage> theEmails = new List<Messaging.SingleEmailMessage> ();
            List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            List<String> toAddresses = new List<String> ();
            String emailErrorReport = null;
            
            for(Volunteers__c vol: [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)])
            toAddresses.add(vol.Email__c);
            //List<Volunteers__c> volListTeamp = [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)];
            system.debug(toAddresses);
    
            efa.setFileName(attachmentId.get(LWC.Id).Name);
            efa.setBody(attachmentId.get(LWC.Id).Body);
            efa.setContentType(attachmentId.get(LWC.Id).ContentType);
            emailAttachments.add(efa);
            
            if(emailAttachments.size() > 0)
            {
                email.setToAddresses(toAddresses);
                email.setSubject('test');
                email.setPlainTextBody('For Leap Curriculum : ID -  ' + LWC.Id + ' Name - ' + LWC.Name + ' Short Description - ' + LWC.Short_Description__c + '.');
                email.setFileAttachments(emailAttachments);
                theEmails.add(email);
            }
            
            if(theEmails.size() > 0)
            {
                
                Messaging.SendEmailResult[] results = Messaging.sendEmail(theEmails,false);
                Messaging.SendEmailError[] errors = new List<Messaging.SendEmailError>();
                
                for( Messaging.SendEmailResult currentResult : results ) 
                {
                    errors = currentResult.getErrors();
                    if( null != errors ) 
                    {
                        for( Messaging.SendEmailError currentError : errors ) 
                        {
                            emailErrorReport = emailErrorReport + '(' +  currentError.getStatusCode() + ')' + currentError.getMessage() + '\r' ;
                        }
                    }
                }
    
                system.debug('error : ' + emailErrorReport);

             }

            System.debug('HEAP_SIZE Used:'+ Limits.getHeapSize()); 
            
            if(emailErrorReport != null){
                break;
            }
            else
            {
                LWC.send_EMail__c = TRUE;
                updateLeapList.add(LWC);  
            }
            
            if(updateLeapList.size()>0)
            update updateLeapList;
            
            if(emailErrorReport != null){
                System.abortJob(BC.getJobId()); 
                List<sObject> so = scope;
                Leap_Weekly_Curriculum__c lwcr= (Leap_Weekly_Curriculum__c )so[0];          
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresseser = new String[] {'rahmeshms@outlook.com'};
                mail.setToAddresses(toAddresseser);
                mail.setSubject('Email Job is aborted'); 
                mail.setPlainTextBody('The send email job is aborted due to Leap Curriculum : '+lwcr.Name+' '+lwcr.Short_Description__c+ ' '+lwcr.Id+ 'Please check the error report and take action accordingly.\n\n\t Error - '+emailErrorReport);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
       } 
       
   }
global void finish(Database.BatchableContext BC){

    }


    
        }

Test Class: 
 
@isTest
public with sharing class Attachmentstest{
public static testmethod void Attachmentstest()
{

        Leap_Weekly_Curriculum__c record = new Leap_Weekly_Curriculum__c();
        Attachment attachment1 = new Attachment();
        Leap_Centre__c lcr = new Leap_Centre__c();
        
       lcr.Name = 'Anaikkum Karangal';
       lcr.Location__c = 'test location';
       lcr.Primary_Representative__c = 'Avinash';
       lcr.Primary_Rep_s_Mobile__c = '9176473115';
       lcr.Primary_Rep_s_Email__c = 'asd@asd.com';
       
       insert lcr;
       
       record.Short_Description__c = 'test record';
       record.For_Centre__c = 'Anaikkum Karangal';
       record.For_Date__c = Date.Today() + 1;
       record.Send_Email__c = FALSE;
       record.Uploaded_By__c = 'Avinash'; 
       record.Leap_Centre__c = lcr.Id;
     
        // Insert the record
        insert record;
        system.debug(record);
        
        // Insert Attachments;
        attachment1.Name='Unit Test Attachment';
        attachment1.ParentId = record.Id;
        attachment1.body=Blob.valueOf('Unit Test Attachment Body');
        insert attachment1;
        
 String Query='Select Id,Name,For_Centre__c,For_Date__c,Leap_Centre__c,Leap_Centre__r.Name,Send_Email__c,Short_Description__c,Uploaded_By__c from Leap_Weekly_Curriculum__c where Send_Email__c = FALSE and For_Date__c >= TODAY';
 
       Test.startTest();
       sendEmailtoVolntr c = new sendEmailtoVolntr(query);
       Database.executeBatch(c);
       Test.stopTest();   
 
 }
     
 }

Don't understand what's going wrong.. please help out.
global class sendEmailtoVolntr implements schedulable,Database.Batchable<sObject>,Database.Stateful
{
    global String Query = null;

    global sendEmailtoVolntr (){
  
       Query='Select Id,Name,For_Centre__c,For_Date__c,Leap_Centre__c,Leap_Centre__r.Name,Send_Email__c,Short_Description__c,Uploaded_By__c from Leap_Weekly_Curriculum__c where Send_Email__c = FALSE and For_Date__c >= TODAY';
   
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(SchedulableContext SC){
        sendEmailtoVolntr sendEmail= new sendEmailtoVolntr ();
        database.executebatch(sendEmail,1);
     }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
    
        List<Attachment> attachments = new List<Attachment> ();
        Map<Id,Attachment> attachmentId = new Map<Id,Attachment> ();
        Set<Id> LeapIds = new Set<Id> ();
        List<Leap_Weekly_Curriculum__c> leapCurrilist = new List<Leap_Weekly_Curriculum__c> ();
        List<Leap_Weekly_Curriculum__c> updateLeapList = new List<Leap_Weekly_Curriculum__c> ();
    
        for(sObject so : scope){ 
    
            Leap_Weekly_Curriculum__c leapCurri= (Leap_Weekly_Curriculum__c)so;
            LeapIds.add(leapcurri.Id);
            leapCurrilist.add(leapCurri);
           } 
        attachments = [SELECT Id,ParentId, Name, Body, ContentType FROM Attachment WHERE Parentid IN :LeapIds];
          //Assuming that there will be only one attachment for each Leap Curriculum record           
        for(Attachment att : attachments)
        {
            attachmentId.put(att.ParentId,att);
        }
        attachments.clear();
        
        for(Leap_Weekly_Curriculum__c LWC: leapCurrilist)
        {
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            List<Messaging.SingleEmailMessage> theEmails = new List<Messaging.SingleEmailMessage> ();
            List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            List<String> toAddresses = new List<String> ();
            String emailErrorReport = null;
            
            for(Volunteers__c vol: [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)])
            toAddresses.add(vol.Email__c);
            //List<Volunteers__c> volListTeamp = [Select Email__c from Volunteers__c WHERE Centre_Allocation__c includes(:LWC.Leap_Centre__r.Name)];
            system.debug(toAddresses);
    
            efa.setFileName(attachmentId.get(LWC.Id).Name);
            efa.setBody(attachmentId.get(LWC.Id).Body);
            efa.setContentType(attachmentId.get(LWC.Id).ContentType);
            emailAttachments.add(efa);
            
            if(emailAttachments.size() > 0)
            {
                email.setToAddresses(toAddresses);
                email.setSubject('test');
                email.setPlainTextBody('For Leap Curriculum : ID -  ' + LWC.Id + ' Name - ' + LWC.Name + ' Short Description - ' + LWC.Short_Description__c + '.');
                email.setFileAttachments(emailAttachments);
                theEmails.add(email);
            }
            
            if(theEmails.size() > 0)
            {
                
                Messaging.SendEmailResult[] results = Messaging.sendEmail(theEmails,false);
                Messaging.SendEmailError[] errors = new List<Messaging.SendEmailError>();
                
                for( Messaging.SendEmailResult currentResult : results ) 
                {
                    errors = currentResult.getErrors();
                    if( null != errors ) 
                    {
                        for( Messaging.SendEmailError currentError : errors ) 
                        {
                            emailErrorReport = emailErrorReport + '(' +  currentError.getStatusCode() + ')' + currentError.getMessage() + '\r' ;
                        }
                    }
                }
    
                system.debug('error : ' + emailErrorReport);

             }

            System.debug('HEAP_SIZE Used:'+ Limits.getHeapSize()); 
            
            if(emailErrorReport != null){
                break;
            }
            else
            {
                LWC.send_EMail__c = TRUE;
                updateLeapList.add(LWC);  
            }
            
            if(updateLeapList.size()>0)
            update updateLeapList;
            
            if(emailErrorReport != null){
                System.abortJob(BC.getJobId()); 
                List<sObject> so = scope;
                Leap_Weekly_Curriculum__c lwcr= (Leap_Weekly_Curriculum__c )so[0];          
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresseser = new String[] {'rahmeshms@outlook.com'};
                mail.setToAddresses(toAddresseser);
                mail.setSubject('Email Job is aborted'); 
                mail.setPlainTextBody('The send email job is aborted due to Leap Curriculum : '+lwcr.Name+' '+lwcr.Short_Description__c+ ' '+lwcr.Id+ 'Please check the error report and take action accordingly.\n\n\t Error - '+emailErrorReport);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
       } 
       
   }
global void finish(Database.BatchableContext BC){

    }


    
        }

I'm new to development and need help writing a test class for this batch class. I have no idea where to start or end. Please help out.

Thanks,
Avinash
Hi All,

I've been trying to write a test class for this but not able to cover code at all! Newbie to SFDC and just learning APEX.. Please help out!
 
trigger updateLeapCentre on Volunteers__c (before update,after update) {

    Map<Id,LEap_Centre__c> LeapCentreMap = new Map<Id,Leap_Centre__c> ();
    Map<String,Leap_Centre__c> LeapCentredMap = new Map<String,Leap_Centre__c> ();
    Map<Id, Map<Id,LeapVolunteer__c >> leapVoluntrMap = new Map<Id, Map<Id,LeapVolunteer__c >> ();
    boolean leapFound = FALSE;
    String errorVol = 'There already exists an association for the Volunteer with the requested Centre. Please check and correct the data.';
    String errorLeap = 'There is no Leap Centre created for one of the requested centre. Please create Leap Centre first and then associate the volunteer to Centre.';
    for(Leap_Centre__c temp : [Select Id,Name from Leap_Centre__c])
    {
        LeapCentreMap.put(temp.Id,temp);
        LeapCentredMap.put(temp.Name,temp);
    } 
    List<LeapVolunteer__c > leapVolntrDeleteList = new List<LeapVolunteer__c > ();
    
    for(LeapVolunteer__c leapVol : [Select Id,Volunteer__c,Leap_Centre__c from LeapVolunteer__c  where Volunteer__c  IN : Trigger.newMap.keySet() ])
    {
        Map<Id,LeapVolunteer__c > tempMap = new Map<Id,LeapVolunteer__c > ();
        if(leapVoluntrMap.get(leapVol.Volunteer__c) == null)
        {
            tempMap.put(leapVol.Id,leapVol);
            leapVoluntrMap.put(leapVol.Volunteer__c,tempMap);
         }
         else
         {
             tempMap = leapVoluntrMap.get(leapVol.Volunteer__c);
             tempMap.put(leapVol.Id,leapVol);
             leapVoluntrMap.put(leapVol.Volunteer__c,tempMap);
         }
    }
    
    List<Volunteers__c> volList = new List<Volunteers__c> ();  
    
    if(trigger.isBefore && trigger.isUpdate)
    {
        for(Volunteers__c vol : Trigger.new)
        {
            Map<Id,LeapVolunteer__c > leapVoluntrCheckMap = new Map<Id,LeapVolunteer__c > ();
            leapVoluntrCheckMap = leapVoluntrMap.get(vol.Id);
            String [] centres = vol.Centre_Allocation__c != null ? vol.Centre_Allocation__c.split(';') : null ;
            
            if(trigger.oldMap.get(vol.Id).Centre_Allocation__c <> vol.Centre_Allocation__c)
            {
                 if(vol.Centre_Allocation__c != null)
                 {       
                    
                    system.debug('***'+centres+'***');
                    for(String centre : centres)
                    {
                        if(LeapCentredMap.get(centre) != null)
                        {
                            boolean volFound = FALSE;
                            system.debug('***'+centre+'***'+'&&&'+centre.trim()+'&&&');
                            if(leapVoluntrCheckMap != null)
                            {
                                for(Id iterator : leapVoluntrCheckMap.keySet())
                                {
                                    if(leapVoluntrCheckMap.get(iterator).Leap_Centre__c == LeapCentredMap.get(centre).Id)
                                    volFound = TRUE;
                                }
                            }
                            
                            if(volFound == FALSE)
                            {
                                LeapVolunteer__c leapVolInsert = new LeapVolunteer__c (Leap_Centre__c=LeapCentredMap.get(centre).Id,Volunteer__c=Vol.Id);
                                insert leapVolInsert;
                            }
                            
                        }  
                        else
                            vol.addError(errorLeap);
                     }
    
                  }
               
                  if(leapVoluntrCheckMap != null ? leapVoluntrCheckMap.size() > 0 ? TRUE : FALSE : FALSE )
                     {
                         for(Id iterator : leapVoluntrCheckMap.keySet())
                         {
                             if(vol.Centre_Allocation__c != null ? !vol.Centre_Allocation__c.contains(leapCentreMap.get(leapVoluntrCheckMap.get(iterator).Leap_Centre__c).Name) : TRUE)
                             leapVolntrDeleteList.add(leapVoluntrCheckMap.get(iterator));
                             
                         }
                     }
               }
        }
    }
    
    
    if(leapVolntrDeleteList != null ? leapVolntrDeleteList.size() > 0 ? TRUE : FALSE : FALSE )
    delete leapVolntrDeleteList;
}
Thanks in Advance!

 
Hi All,

I'm trying to write a test class to this class below. But I'm not able to cover lines 12 & 20. Can someone help me out please? 
 
trigger orientationDateUpdate on Registrations__c (before insert, before update) {

if(Trigger.isInsert && Trigger.isBefore)
{
    for(Registrations__c temp : Trigger.new)
    {
        if(temp.Planned_Orientation_Date__c == null)
        {
            Date date1 = Date.newinstance(1900,1,7);
            Date date2 = Date.TODAY();
            
            if(date2.day()<7 && math.MOD(date1.daysBetween(date2),7) != 0 && math.MOD(date2.month(),2) != 0)
            {
                date2 = date2.addDays(7-math.MOD(date1.daysBetween(date2),7)); 
            }
            else
            {
                date2 = Date.newInstance(date2.year(), math.MOD(date2.month(),2) != 0 ? date2.month()+2 : date2.month()+1 , 1);
                if(math.MOD(date1.daysBetween(date2),7) != 0)
                date2 = date2.addDays(7-math.MOD(date1.daysBetween(date2),7));    
            }
            system.debug('******Planned Orientation Date ***** ' + date2 );
            temp.Planned_Orientation_Date__c = date2;
        }
    }
}

}
Thanks in Advance,

Avinash
 
Hi All,

I have a custom object called Leap_Weekly_Curriculum__c and I need a VF page that will help me input values into it and also upload a file which should get added to the attachments related list of the same record. Please help.
public with sharing class ThePrayagMarathon {

   public ThePrayagMarathon() {
   
   }
   
   public Registration__c Regs {get;set;}
   
   public PageReference save()
   { 
    
    if(Registration__c.Marathon_Category__c == null || Registration__c.Marathon_Distance__c == null || Registration__c.Name_of_the_Participant__c == null || Registration__c.DOB__c == null || Registration__c.Address_Line_1__c == null || Registration__c.City__c == null || Registration__c.State__c == null || Registration__c.Pin_Code__c == null || Registration__c.Email__c == null || Registration__c.Mobile_Number__c == null ||  Registration__c.Tee_Shirt_Size__c == null)
   {
    
    ApexPages.addMessage(new Apexpages.Message(ApexPages.severity.error,'Please fill all mandatory fields.'));
                return null;
   }
    
        System.debug('Entered into save');
        RecordType regRtype = [SELECT Name,id FROM RecordType WHERE SobjectType='Registration__c' and Name='Marathon' LIMIT 1];
        system.debug('Record type of inserted registration..'+regRtype.id);
        Regs.RecordTypeId = regRtype.id;
        Regs.type__c = 'New Participant'; 
        try {      
        insert regs;
        if(Regs.Marathon_Category__c == 'Rs. 700 /- For Ages Above 12')
        {pagereference Page = new pagereference('https://www.payumoney.com/paybypayumoney/#/37061');
        return Page;}
        else
        {pagereference Page = new pagereference('https://www.payumoney.com/paybypayumoney/#/37063');
        return Page;}
           } 
         catch(DMLException e) {
        return null;
        }      
        }
        
        public PageReference cancel()
        {pagereference Page = new pagereference('http://www.joinprayag.com');
        return Page;}
        
        
        public ThePrayagMarathon(ApexPages.StandardController controller) {
        this.regs = (Registration__c)controller.getRecord();
        system.debug('m here ....'+regs);            
        }

}