• snaps
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies

I have a list with multiple elements associated with one name. I want to check only if the email address in the first element is empty - the others I don't care if they are blank. Here is my list:

 

public List<Opportunity> opportunity {
        get {
            return [SELECT Name, Ashoka_Website_Profile_Link__c,
            (SELECT Engagement_Role__c.Name,
                Engagement_Role__c.Contact__r.Email, 
                Engagement_Role__c.Contact__r.Name,
                Engagement_Role__c.Contact__r.Account.Name,
                Engagement_Role__c.Contact__r.Id
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = :oppId];
            }
    }

 

Originally, I did not use a list but instead just created a new Opportunity object. My code all ran fine. I used this if-statement and for-loop after (pardon the terrible naming, it was not my doing):

 

        if (opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email != null) {
            addresses = opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email;
            
            for (Integer i = 1; i < opportunity.R00NR0000000UWbWMAW__r.size(); i++) {
                if (opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email != null) {          
                    addresses += ':' + opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email;
                }
            }
        }

 

But since replacing my code with the list, my code doesn't work anymore. How then would the syntax look? I suppose first I would need to check if the list is empty in the first place, but after that, how would I check if the email field specifically is empty?

  • July 03, 2013
  • Like
  • 0

I have been stuck on this task for awhile now, so any feedback would be appreciated. Here is my sendEmail() class:

 

public class sendEmail {

    public String subject { get; set; }
    public String body { get; set; }
    public Id recordId;
    private final Opportunity opportunity;

    public sendEmail() {
        recordId = ApexPages.currentPage().getParameters().get('id');
        opportunity = [SELECT Name, Ashoka_Website_Profile_Link__c,
            (SELECT Engagement_Role__c.Name,
                Engagement_Role__c.Contact__r.Email, 
                Engagement_Role__c.Contact__r.Name,
                Engagement_Role__c.Contact__r.Account.Name,
             	Engagement_Role__c.Contact__r.Id
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = :recordId];
    }

    public Opportunity getOpportunity() {
        return opportunity;
    }

    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 

        String addresses;
        
        // Checks to see if there even exists a contact and email address before looping 
        // through the whole list of contacts and emails 
        if (opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email != null) {
            addresses = opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email;
            
            for (Integer i = 1; i < opportunity.R00NR0000000UWbWMAW__r.size(); i++) {
                if (opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email != null) {          
                    addresses += ':' + opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email;
                }
            }
        }

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

        // Sets the parameters of the email
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( body );
        email.setBccSender (true);
        
        
        Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });

        PageReference sentTrue = new PageReference('/apex/emailSentTrue?Id=' + opportunity.id); 
        sentTrue.setRedirect(true); 
        return sentTrue;
        
    }
}

 

And here is my test class:

 

 

@isTest(SeeAllData=true)

private class testSendEmail {
    private static testMethod void testSend() {
    	
        sendEmail se = new sendEmail();
        
        Opportunity testOpp = new Opportunity(name='Test Name', Ashoka_Website_Profile_Link__c = 'Some Link');
		insert testOpp;
        
     	RecordType r = [SELECT ID from RecordType WHERE SObjectType ='Account' AND Name = 'Individual']; 
        Account acc = new Account(Name='Test Account', RecordType = r);
        insert acc;       
        Account a = [SELECT ID From Account WHERE Name = 'Test Account'];
        Contact con = new Contact(FirstName='Test',LastName='Contact', Email='test@ashoka.org', Account=a);
        insert con;
        Engagement_Role__c er = new Engagement_Role__c(Contact__c = con.Id, Opportunity__c= testOpp.Id, Role__c='Nominator');
        insert er;
             
        Opportunity updatedOpp = [SELECT Name, Ashoka_Website_Profile_Link__c,
            (SELECT Engagement_Role__c.Name,
                Engagement_Role__c.Contact__r.Email, 
                Engagement_Role__c.Contact__r.Name,
                Engagement_Role__c.Contact__r.Account.Name,
                Engagement_Role__c.Contact__r.Id
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = :testOpp.Id];
       
        System.assertEquals('Test Name', updatedOpp.Name);
        System.assertEquals('Some Link', updatedOpp.Name);
        System.assertEquals('test@ashoka.org', updatedOpp.R00NR0000000UWbWMAW[0].Contact__r.Email);
      	System.assertEquals('Test Contact', updatedOpp.R00NR0000000UWbWMAW[0].Contact__r.Name);
      	System.assertEquals(con.Id, updatedOpp.R00NR0000000UWbWMAW[0].Contact__r.Id);
        
        String nextPage = se.send().getUrl();
        PageReference page = se.send();
        System.assertEquals(':testOpp.Id', nextPage); 
        
        }
}

 

My coverage is 26%, and only covers the first line of my query. What the heck am I doing wrong?

  • June 21, 2013
  • Like
  • 0

I have a flow where the user enters his contact information, and the flow checks if his email is in the system or not. If he is in the system, he is sent to the page with all of his contact details and the screen confirming his information. If he isn't, the system automatically creates a new record of the user and then sends him to the page with all of his contact details, as well as the screen confirming the creation of his new contact record.

 

Right now, the page is set up so that the edit, clone, delete and share buttons are hidden - I do not want the users who already have their information set up to be able to edit their information. I do, however, want the new users to be able to edit their contact details. Is this even possible to do with the workflow, and how should I approach this? 

  • June 11, 2013
  • Like
  • 0

I have a class designed to send an email from an opportunity.  Opportunities have a lookup to an object called the Panel Tool and there is a junction object called "panelists" that links the panel tool to contacts. I am pulling the contacts' emails via the soql query, and then adding them to the list of emails so that users do not have to manually type in email addresses.

 

Now, I'm working on my first ever Apex test class, and am running into some difficulties. Here is the code I need to test on:

 

public class sendEmail {

    public String subject { get; set; }
    public String body { get; set; }
    private final Opportunity opportunity;

    /*
     * Creates a constructor that populates the Opportunity object with the nominator's name and email address.
     * The nominator's email should never be blank - otherwise, his contact information would not show up.
     */
    public sendEmail() {
        opportunity = [SELECT Name, 
            (SELECT Engagement_Role__c.Name, Engagement_Role__c.Contact__r.Email, Engagement_Role__c.Contact__r.FirstName 
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Opportunity getOpportunity() {
        return opportunity;
    }

    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 

        String addresses;
        
        // Checks to see if there even exists a contact and email address before looping 
        // through the whole list of contacts and emails 
        if (opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email != null) {
            addresses = opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email;
            
            for (Integer i = 1; i < opportunity.R00NR0000000UWbWMAW__r.size(); i++) {
                if (opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email != null) {          
                    addresses += ':' + opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email;
                }
            }
        }

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

        // Sets the parameters of the email
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( body );
        
        // Sends the email
        Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });

        // Redirects page to confirm that email was successfully sent
        PageReference sentTrue = new PageReference('/apex/emailSentTrue?Id=' + opportunity.id); 
        sentTrue.setRedirect(true); 
        return sentTrue;
    }
}

 

 And here is the partial test code that I have written:

 

@isTest

private class testSendEmail {
    private static testMethod void testSend() {
        
        sendEmail controller = new sendEmail();
        Opportunity[] opp = [SELECT Name, 
            (SELECT Engagement_Role__c.Name, Engagement_Role__c.Contact__r.Email, Engagement_Role__c.Contact__r.FirstName 
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = '0064000000BKcY9'];
        Opportunity newOpp = opp[0];
        insert newOpp;
        String nextPage = controller.send().getUrl();
        
        test.startTest();
        PageReference page = controller.send();
        test.stopTest();
        
        System.assertEquals('Alberto', newOpp.name);
        System.assertEquals('/apex/sendEmailPage?Id=0064000000BKcY9', nextPage);
        
        }
}

 

I realize my testing is incomplete and that I haven't tested all conditions yet. My problem however is that my code never reaches beyond the here:

 

    public sendEmail() {
        opportunity = [SELECT Name, 

 

What exactly am I doing wrong here?

  • June 06, 2013
  • Like
  • 0

Hey guys,

 

We are trying to run a SOQL query to pull a list of email addresses, and then want to be able to draft and send an email to them.

 

We are basically copying the info from the visualforce developer guide and trying to adjust it to our data model, but are running into some issues in compiling the list of emails.(http://www.salesforce.com/us/developer/docs/pages/Content/pages_email_intro.htm)

 

 

Data Model:

We are trying to send this email from an opportunity.  Opportunities have a lookup to an object called the Panel Tool.  There is a junction object called "panelists" that links the panel tool to contacts, and so we are pulling the contact's emails via the soql query, and then trying to send to the list of emails.

 

This SOQL Query seems to work, but there could well be a better way.  We pulled the contact's email to the junction object via a formula field to try to simplify things, but the query works either way.

 

SELECT Name,(SELECT Name,Panelists_Email__c FROM Panelists__r) FROM Panel__c WHERE Id IN (Select Assigned_to_Panel__c FROM Opportunity WHERE Id= :ApexPages.currentPage().getParameters().get('id'))];

 

Here is the link to our code:

http://pastebin.com/fWEji9ry

 

Currently we are getting a compilation error: Invalid foreign key relationship: Panel__c.Assigned_to_Panel__r at line 22 column 25

 

Right now we don't really know how else to proceed, and would like some tips and/or feedback with our query/code.

  • May 30, 2013
  • Like
  • 0

I have a list with multiple elements associated with one name. I want to check only if the email address in the first element is empty - the others I don't care if they are blank. Here is my list:

 

public List<Opportunity> opportunity {
        get {
            return [SELECT Name, Ashoka_Website_Profile_Link__c,
            (SELECT Engagement_Role__c.Name,
                Engagement_Role__c.Contact__r.Email, 
                Engagement_Role__c.Contact__r.Name,
                Engagement_Role__c.Contact__r.Account.Name,
                Engagement_Role__c.Contact__r.Id
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = :oppId];
            }
    }

 

Originally, I did not use a list but instead just created a new Opportunity object. My code all ran fine. I used this if-statement and for-loop after (pardon the terrible naming, it was not my doing):

 

        if (opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email != null) {
            addresses = opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email;
            
            for (Integer i = 1; i < opportunity.R00NR0000000UWbWMAW__r.size(); i++) {
                if (opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email != null) {          
                    addresses += ':' + opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email;
                }
            }
        }

 

But since replacing my code with the list, my code doesn't work anymore. How then would the syntax look? I suppose first I would need to check if the list is empty in the first place, but after that, how would I check if the email field specifically is empty?

  • July 03, 2013
  • Like
  • 0

I have been stuck on this task for awhile now, so any feedback would be appreciated. Here is my sendEmail() class:

 

public class sendEmail {

    public String subject { get; set; }
    public String body { get; set; }
    public Id recordId;
    private final Opportunity opportunity;

    public sendEmail() {
        recordId = ApexPages.currentPage().getParameters().get('id');
        opportunity = [SELECT Name, Ashoka_Website_Profile_Link__c,
            (SELECT Engagement_Role__c.Name,
                Engagement_Role__c.Contact__r.Email, 
                Engagement_Role__c.Contact__r.Name,
                Engagement_Role__c.Contact__r.Account.Name,
             	Engagement_Role__c.Contact__r.Id
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = :recordId];
    }

    public Opportunity getOpportunity() {
        return opportunity;
    }

    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 

        String addresses;
        
        // Checks to see if there even exists a contact and email address before looping 
        // through the whole list of contacts and emails 
        if (opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email != null) {
            addresses = opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email;
            
            for (Integer i = 1; i < opportunity.R00NR0000000UWbWMAW__r.size(); i++) {
                if (opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email != null) {          
                    addresses += ':' + opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email;
                }
            }
        }

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

        // Sets the parameters of the email
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( body );
        email.setBccSender (true);
        
        
        Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });

        PageReference sentTrue = new PageReference('/apex/emailSentTrue?Id=' + opportunity.id); 
        sentTrue.setRedirect(true); 
        return sentTrue;
        
    }
}

 

And here is my test class:

 

 

@isTest(SeeAllData=true)

private class testSendEmail {
    private static testMethod void testSend() {
    	
        sendEmail se = new sendEmail();
        
        Opportunity testOpp = new Opportunity(name='Test Name', Ashoka_Website_Profile_Link__c = 'Some Link');
		insert testOpp;
        
     	RecordType r = [SELECT ID from RecordType WHERE SObjectType ='Account' AND Name = 'Individual']; 
        Account acc = new Account(Name='Test Account', RecordType = r);
        insert acc;       
        Account a = [SELECT ID From Account WHERE Name = 'Test Account'];
        Contact con = new Contact(FirstName='Test',LastName='Contact', Email='test@ashoka.org', Account=a);
        insert con;
        Engagement_Role__c er = new Engagement_Role__c(Contact__c = con.Id, Opportunity__c= testOpp.Id, Role__c='Nominator');
        insert er;
             
        Opportunity updatedOpp = [SELECT Name, Ashoka_Website_Profile_Link__c,
            (SELECT Engagement_Role__c.Name,
                Engagement_Role__c.Contact__r.Email, 
                Engagement_Role__c.Contact__r.Name,
                Engagement_Role__c.Contact__r.Account.Name,
                Engagement_Role__c.Contact__r.Id
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = :testOpp.Id];
       
        System.assertEquals('Test Name', updatedOpp.Name);
        System.assertEquals('Some Link', updatedOpp.Name);
        System.assertEquals('test@ashoka.org', updatedOpp.R00NR0000000UWbWMAW[0].Contact__r.Email);
      	System.assertEquals('Test Contact', updatedOpp.R00NR0000000UWbWMAW[0].Contact__r.Name);
      	System.assertEquals(con.Id, updatedOpp.R00NR0000000UWbWMAW[0].Contact__r.Id);
        
        String nextPage = se.send().getUrl();
        PageReference page = se.send();
        System.assertEquals(':testOpp.Id', nextPage); 
        
        }
}

 

My coverage is 26%, and only covers the first line of my query. What the heck am I doing wrong?

  • June 21, 2013
  • Like
  • 0

I have a flow where the user enters his contact information, and the flow checks if his email is in the system or not. If he is in the system, he is sent to the page with all of his contact details and the screen confirming his information. If he isn't, the system automatically creates a new record of the user and then sends him to the page with all of his contact details, as well as the screen confirming the creation of his new contact record.

 

Right now, the page is set up so that the edit, clone, delete and share buttons are hidden - I do not want the users who already have their information set up to be able to edit their information. I do, however, want the new users to be able to edit their contact details. Is this even possible to do with the workflow, and how should I approach this? 

  • June 11, 2013
  • Like
  • 0

I have a class designed to send an email from an opportunity.  Opportunities have a lookup to an object called the Panel Tool and there is a junction object called "panelists" that links the panel tool to contacts. I am pulling the contacts' emails via the soql query, and then adding them to the list of emails so that users do not have to manually type in email addresses.

 

Now, I'm working on my first ever Apex test class, and am running into some difficulties. Here is the code I need to test on:

 

public class sendEmail {

    public String subject { get; set; }
    public String body { get; set; }
    private final Opportunity opportunity;

    /*
     * Creates a constructor that populates the Opportunity object with the nominator's name and email address.
     * The nominator's email should never be blank - otherwise, his contact information would not show up.
     */
    public sendEmail() {
        opportunity = [SELECT Name, 
            (SELECT Engagement_Role__c.Name, Engagement_Role__c.Contact__r.Email, Engagement_Role__c.Contact__r.FirstName 
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Opportunity getOpportunity() {
        return opportunity;
    }

    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 

        String addresses;
        
        // Checks to see if there even exists a contact and email address before looping 
        // through the whole list of contacts and emails 
        if (opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email != null) {
            addresses = opportunity.R00NR0000000UWbWMAW[0].Contact__r.Email;
            
            for (Integer i = 1; i < opportunity.R00NR0000000UWbWMAW__r.size(); i++) {
                if (opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email != null) {          
                    addresses += ':' + opportunity.R00NR0000000UWbWMAW[i].Contact__r.Email;
                }
            }
        }

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

        // Sets the parameters of the email
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( body );
        
        // Sends the email
        Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });

        // Redirects page to confirm that email was successfully sent
        PageReference sentTrue = new PageReference('/apex/emailSentTrue?Id=' + opportunity.id); 
        sentTrue.setRedirect(true); 
        return sentTrue;
    }
}

 

 And here is the partial test code that I have written:

 

@isTest

private class testSendEmail {
    private static testMethod void testSend() {
        
        sendEmail controller = new sendEmail();
        Opportunity[] opp = [SELECT Name, 
            (SELECT Engagement_Role__c.Name, Engagement_Role__c.Contact__r.Email, Engagement_Role__c.Contact__r.FirstName 
            FROM Opportunity.R00NR0000000UWbWMAW WHERE Role__c='Nominator' AND Engagement_Role__c.Contact__r.Email != NULL ) 
            FROM Opportunity WHERE Id = '0064000000BKcY9'];
        Opportunity newOpp = opp[0];
        insert newOpp;
        String nextPage = controller.send().getUrl();
        
        test.startTest();
        PageReference page = controller.send();
        test.stopTest();
        
        System.assertEquals('Alberto', newOpp.name);
        System.assertEquals('/apex/sendEmailPage?Id=0064000000BKcY9', nextPage);
        
        }
}

 

I realize my testing is incomplete and that I haven't tested all conditions yet. My problem however is that my code never reaches beyond the here:

 

    public sendEmail() {
        opportunity = [SELECT Name, 

 

What exactly am I doing wrong here?

  • June 06, 2013
  • Like
  • 0

Hey guys,

 

We are trying to run a SOQL query to pull a list of email addresses, and then want to be able to draft and send an email to them.

 

We are basically copying the info from the visualforce developer guide and trying to adjust it to our data model, but are running into some issues in compiling the list of emails.(http://www.salesforce.com/us/developer/docs/pages/Content/pages_email_intro.htm)

 

 

Data Model:

We are trying to send this email from an opportunity.  Opportunities have a lookup to an object called the Panel Tool.  There is a junction object called "panelists" that links the panel tool to contacts, and so we are pulling the contact's emails via the soql query, and then trying to send to the list of emails.

 

This SOQL Query seems to work, but there could well be a better way.  We pulled the contact's email to the junction object via a formula field to try to simplify things, but the query works either way.

 

SELECT Name,(SELECT Name,Panelists_Email__c FROM Panelists__r) FROM Panel__c WHERE Id IN (Select Assigned_to_Panel__c FROM Opportunity WHERE Id= :ApexPages.currentPage().getParameters().get('id'))];

 

Here is the link to our code:

http://pastebin.com/fWEji9ry

 

Currently we are getting a compilation error: Invalid foreign key relationship: Panel__c.Assigned_to_Panel__r at line 22 column 25

 

Right now we don't really know how else to proceed, and would like some tips and/or feedback with our query/code.

  • May 30, 2013
  • Like
  • 0