• Mike@COL
  • NEWBIE
  • 50 Points
  • Member since 2011

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

Is it possible to share logic between test classes. The example I have is creating a test class for a trigger on a task. I have to first create an account and then a contact and finally a task. Is there some way to place creation of the account and contact in a separate class and call the class whenever I need to create them? I thought that this was made possible in the last release but I can't find it anywhere.

Hi there,

 

I want to add several attachments to one email and sending this out.

I have no idea, where to add several attachments to the email in the code below. The two attachments are both pdf and less than 200KB.

 

If you can give me a hint, it would be great.

 

my first idea was to change

1.a Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();

to

1.b List<Messaging.Emailfileattachment> efa = new List<Messaging.Emailfileattachment>();

 

but than I am running to the issue not to be able to add the EmailFileAttachment to the (Messaging.SingleEmailMessage) email.

 

Here the code from the VisualForce Document http://www.salesforce.com/us/developer/docs/pages/Content/pages_email_sending_attachments.htm modified by me.

 

 

public class sendEmail {
    public String subject { get; set; }
    public String body { get; set; }

    private final Account account;

    // Create a constructor that populates the Account object 
    
    public sendEmail() {
        account = [SELECT Name, 
                  (SELECT Contact.Name, Contact.Email FROM Account.Contacts) 
                   FROM Account 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public PageReference send() {
        // Define the email 
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        // Reference the attachment page and pass in the account ID 
        Integer numAtts=[SELECT count() FROM attachment WHERE parentid=: account.Id];
        system.debug('Number of Attachments Atts = '+ numAtts);
        List<Attachment> allAttachment = new List<Attachment>();
    	allAttachment = [SELECT Id, Name, ContentType, Body FROM Attachment WHERE parentid =: account.Id];
        // Create the email attachment 
        //List<Messaging.Emailfileattachment> efa = new List<Messaging.Emailfileattachment>();
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
		// try{ 
		if(numAtts > 0){
				for (Integer i = 0; i < numAtts; i++){
					system.debug(allAttachment[i].Name);
					efa.setFileName(allAttachment[i].Name);
					efa.setBody(allAttachment[i].Body);
					efa.setContentType(allAttachment[i].ContentType);
				}
		}
		 // } catch (ListException  e){
			// |DEBUG|List index out of bounds: 2
		 //         system.debug( e.getMessage() );
		// } 

        String addresses;
        if (account.Contacts[0].Email != null) {
            addresses = account.Contacts[0].Email;
            // Loop through the whole list of contacts and their emails 
    
            for (Integer i = 1; i < account.Contacts.size(); i++) {
                if (account.Contacts[i].Email != null) {
                    addresses += ':' + account.Contacts[i].Email;
                }
            }
        }

        String[] toAddresses = addresses.split(':', 0);

        // Sets the paramaters of the email 
    
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( body );
        //email.setFileAttachments(new Messaging.EmailFileAttachment[] {List<efa>()});
        if(numAtts > 0){
        	email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
        }

        // Sends the email 
        Messaging.SendEmailResult [] r = 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});   
        return null;
    }
}

 

 

 

Citrix Online is growing and we're looking for an experienced software developer to join our CRM Systems team and help us extend our use of the SalesForce.com platform. We’re passionate about building solid integrations that will last, so we’re looking for someone with a talent for designing and implementing robust software solutions.

The CRM Systems team is a small group responsible for the architecture, development and operation of SalesForce.com and the more than 30 external and internal tools that are integrated with it.

Daily activities include:
• Design/develop/maintain integrations with SalesForce.com. These integrations may include Java, APEX, VisualForce, HTML, JavaScript or SQL code. They may also involve working with Oracle databases, ETL tools such as Oracle Data Integrator or Talend, or other third party tools.
• Investigate and resolve bug reports.
• Review code and test changes made by other team members.
• Communicate with project stakeholders to clarify requirements and receive their approval of completed projects.
• Groom and estimate stories in the backlog.
• Participate in a daily Scrum stand-up meeting.
• Check the logs of automated processes and integrations for errors.

Citrix OSD is headquartered in Santa Barbara, CA, and has software development centers located in San Francisco, Germany and India. We offer a fun and fast-paced work environment, flexible scheduling, generous paid time off, as well as a competitive salary and benefits package–including a 401(k) plan, health, dental and vision insurance. Relocation assistance may be available for qualified employees

 

EDUCATION & EXPERIENCE REQUIRED
• BS degree or equivalent in computer science, electrical engineering, or related field is preferred, with approximately 5 years of directly related work experience. No actual work experience may be required for individuals holding a MS or higher degree in one of these fields. Equivalent experience may be substituted for formal education.
• Proficiency in one or more object oriented languages (e.g. C++ or Java), and one or more scripting languages (e.g. Unix shell, PERL, Java script). Knowledge and experience with OOAD principles and methodologies (e.g. UML). Knowledge and experience with basic software lifecycle process.
• Proficiency in Windows, Java and/or Unix programming required.
• Strong working knowledge of networking and data communications is a plus.
• Knowledge and experience with Internet technologies (e.g. HTML, XML, TCP/IP) highly desired
• Knowledge and experience with relational database technologies (SQL, schema design) highly desired
• Knowledge of more advanced programming environments and concepts highly desired (e.g. J2EE, multi-threaded programming)
• Knowledge of SW Engineering Process and Configuration Management tools.

 

To be considered for this position please apply on our website at http://www.citrixonline.com/careers.tmpl and search for Req#13398

This should be simple, but I can complete this class that inserts records from a Map

 

I've filed up a map that contains Contact ID's, Dates and a Unique Number called MRN__c.  Now I am trying to insert records that are filled with in the map into the Referral_Entry__c object at the end of this class.  

 

Any suggestions? I highlighted where I am having issues below:

 

 

//map to store key month. only including one date for now that corresponds with the one records

//list contact from query above
list<Contact> cons = (list<Contact>)scope;
set<Id> conids = new set<Id>();
for (Contact con : cons) conids.add(con.Id);

list<Contact> fullcontacts = [select Id, LastName,
(select Service_Date__c, MRN__c from Referral_Entries_del__r)
from Contact where Id in :conids];

map<Id, map<Date, set<Decimal>>> conid2datemapmap = new map<Id, map<Date, set<Decimal>>>();
for (Id conid : conids)
{
conid2datemapmap.put(conid, new map<Date, set<Decimal>>());
}

for (Contact con : fullcontacts)
{
//get con map to set of MRNs
//run refe loop

//- set of MRN's for individual Physician for that month
map<Date, set<Decimal>> mrns = conid2datemapmap.get(con.Id);

list<Referral_Entry__c> refs = con.Referral_Entries_del__r;

/*
[Select Id, Service_Date__c, Referring_Physician_del__c, MRN__c
FROM Referral_Entry__c
Where Referring_Physician_del__c = :cons[0].Id])
*/
for (Referral_Entry__c refe : refs)
{

totalprocessed ++;

//Find first of month
Date StartOfMonth = refe.Service_Date__c.toStartOfMonth();

//get MRNs already entered for this month
set<Decimal> theseMRNs = mrns.get(StartOfMonth);

//If there are no MRNs already entered for this month
if (theseMRNs == null)
theseMRNs = new set<Decimal>();

//Add this MRN to set of MRNs for this month
if (refe.MRN__c != null)
theseMRNs.add(refe.MRN__c);

//put set in map
mrns.put(StartOfMonth, theseMRNs);
}

//put map back into con2mrnmap
conid2datemapmap.put(con.Id, mrns);

//set up debug log
debuglog += '<br/>new contact ' + con.Id;
for (Date d : mrns.keyset())
{
debuglog += '<br/>' + d + ' ' + mrns.get(d);
}
} //end for Contact con : fullcontacts


//Delete existing Summary records, which are records without Null values in the Count of MRN field

List<Referral_Entry__c> sumrectodelete = [Select Id, Service_Date__c, Referring_Physician_del__c, MRN__c, Count_of_MRN__c
FROM Referral_Entry__c
Where Count_of_MRN__c != Null];
delete sumrectodelete;

//Insert New Summary records

 

List<Referral_Entry__c> newsumrecords = new List<Referral_Entry__c>();

for (Contact con : fullcontacts)

{

for (Date d : mrns.keyset())  
{
newsumrecords.Referring_Physician_del__c = con.Id;
}

}

 

 

 

Whenever an opportunity's closed won, we have several workflows in place that send out emails using a template. 

 

My question: can I make a trigger (or workflow) on emails sent out that creates an activity with the email's conent in the subject/comments? 

  • December 15, 2011
  • Like
  • 0

I am looking to execute some script (to add a user to a Chatter Group) when a user record is updated to any one of 10 profiles.

 

        if (u.Profile.Name.startsWith('BTLB') ){
            CollaborationGroupMember NewMember = new CollaborationGroupMember(MemberId = u.Id, CollaborationGroupId = '00ds0000001U9Ot');
            AddMembers.add(NewMember);
            }   

 This compile ok, however when i try to edit the user record I get:

Apex trigger NewUserEntries caused an unexpected exception, contact your administrator: NewUserEntries: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.NewUserEntries: line 57, column 13

Line 57 is the if statement.

 

Is what i am trying to do possible?

I know i use profileId or a SOQL but don't really want to list the 10 possible ID and keep them updated whenever a new profiles is added.

Any help much appreciate.d

  • December 15, 2011
  • Like
  • 0

Hi , 

 

I need help in fixing the assertion issue in this test class. I have 2 objects with Start_Term__c fields on both  Opportuntiy and Contact respectively . My trigger basicallly updates the Start_Term__c  field on contact.

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

@isTest 
private class opportunity_syncStartTermTest
{
	
         static testmethod void test()
         {
          Contact newcontact = new Contact(LastName = 'abc',
	 			           Start_Term__c = 'Jan 2012'
	 				   );
	    insert newcontact;
	 Opportunity newopportunity = new Opportunity( Contact__c = newcontact.Id,
	  						Name = 'abc',
		         				StageName = 'StageName',
							Start_Term__c = 'Jan 2012',
							CloseDate = Date.today()
							 );
          insert newopportunity;
		   Test.startTest();
            newopportunity.Start_Term__c = 'Sep 2011';
            update newopportunity; 
           Test.stopTest();
            Contact[] message = [SELECT Id, Start_Term__c,Program_Primary__c FROM Contact WHERE ID = :newcontact.Id limit 1]; 
            if(message.size() > 0)
            {
                System.assert(message[0].Start_Term__c == 'Sep 2011');  
             }
       
        }
      
}


}

 Thanks for your help

When we install our managed code in our client environment the system.debug statements are no longer visible. Is there a way to find out how the code is doing in the installed environment? Normally, code is not visible in the install environment but we would like to have the occasional debug line showing so we can see what data is causing our classes to fail. We heard assertions show, but is that only when evaluate to false?

 

Ideas?

  • December 15, 2011
  • Like
  • 0

Is it possible to share logic between test classes. The example I have is creating a test class for a trigger on a task. I have to first create an account and then a contact and finally a task. Is there some way to place creation of the account and contact in a separate class and call the class whenever I need to create them? I thought that this was made possible in the last release but I can't find it anywhere.

I have a piece of code that uses System.setPassword() to set a password for a user.  The method works, however upon first login as the user I am presented with the standard 'Change your password' form.  If I click 'Cancel' I am able to get in, however the form appears every at every login attempt.  Is there any way to prevent this form from appearing?

While trying to debug some of my batch apex, i'm noticing that batches can run in parallel, whereas I used to think they always ran in sequence.

 

I have a batch job, that ends up consisting of 4 batches, i.e. 4 calls of execute().  Let's call the batches A, B, C, and D.  Their times of execution are noted below.

 

A runs from 14:51:16.017 to 14:51:16.067
B runs from 14:51:17.019 to 14:51:17.148
C runs from 14:51:17.019 to 14:51:17.108
D runs from 14:51:17.022 to 14:51:17.259

 These times are taken from debug logs, and you can see that B, C, and D run in parallel.

 

I was under the impression that these batches run serially.  Infact, the following post says that as well:

 

Filed a Case to ask this question, and got this response from Tech Support:
 
1. Is it possible for the execute() method to be running more than once at the same time? (I've already confirmed that the batch job was launched only once.)

A:
All execute methods for batches within a batch job are synchronous so they will not "trip" over each other.

[posted at: http://boards.developerforce.com/t5/Apex-Code-Development/Batch-Apex-can-execute-invocations-run-concurrently/m-p/261857#M45628]

 

I'm hoping that this is true, that somehow you can have the batches run in sequence, but my experience above says otherwise.  Aftering performing timings with Database.stateful, I see that has no effect on the parallel execution of execute().

 

Anyone have any input on this topic?  Should I rewrite my batch job so that batches are not dependent of other batches?  Ideally, i'd like the batches to execute sequentially.

 

 

  • December 13, 2011
  • Like
  • 0

This is my first time creating Batch Apex.  I'm looking to count similar records in a custom object and create records within that object based of this count.  I'm looking to see if anyone can point me in the right direction to get started.  I've read a bunch on Batch Apex and seen the example of reassigning Account owners, but my scenario is a little different.

 

Below is my scenario:

 

Custom_Object__c - This is the object where there will be 200,000 records imported each month.

Number_Reference__c - This will be the field in which may have duplicate values

Contact_Reference__c - This will be the name of the Contact

Number_Count__c - This will be a sum field that will populate in a record after the Batch Apex is ran.

 

Month 1, the user imports records.  Let's say that 500 of these records have the same Contact_Reference__c and the same Number_Reference__c.  For example, there are 500 records where John Doe has the number 123 in the Number_Reference__c.  Now, when the user presses a button to run the Batch Apex, it will detect that John Doe has 500 identical records, (meaning records with the same Number_Reference__c and Contact_Reference__c fields), and will then create a record in the same object that equal the following fields:  

Contact_Reference__c = John Doe

Number_Reference__c = 123

Number_Count__c = 50

 

Thanks in advance for any guidance.

 

 

 

 

 

My goal here is to run a time-based workflow to update the Quote Status 30 days after the Quote as been approved.  It sounds like an easy requirement, when the status is changed to "Approved" via the approval process, a time-based workflow will update the status again 30 days after.  But, a workflow can not set off another workflow, meaning, once the workflow in the approval process that update the status to "Approved", that will not trigger another workflow to set it to another status of "Approved all the way" afterwards.  So,I thought I try a trigger.

 

My thought was to create a trigger to update a checkbox field called Recently_Approved__c when the Status on the Quote changes from "Draft" to "Approved".  Then, a workflow will update the Quote Status again to "Approved all the way" after the Recently_Approved__c checkbox is set to True. So, I created the trigger, and it worked, but only on Before Update, which did not trigger the workflow to update the status to "Approved all the way" when the Recently_Approved__c checkbox was checked via the trigger.

 

My main issue is my trigger is trying to update the Quote record after it has been approved.  So, when the user that needs to approve the record hits approved, a field update in the approval process will update the Status to "Approved", which should trigger the the Recently_Approved__c checkbox to True, but I get this error message:

execution of AfterUpdate caused by: System.FinalException: Record is read-only

 

So, I guess my question is how can I get around this by updating a field via a trigger on a record that is locked via an approval process?

 

Thanks in advance!