• Rejones
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 34
    Replies
I am doing the exercise portion of the Trailhead module and I copies and pasted the first Apex code into the Developer console and saved it. When I went to to the debug Execute Anonymous Window and enter the following. I got the below error message.

EmailManager em = new EmailManager();
em.sendMail('Your email address', 'Trailhead Tutorial', '123 body');

Line: 13, Column: 1
System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, ID is invalid or you do not have access to the record.: [toAddresses, Your email address]

Here is the orginal code from the exercise that I copy and pasted into the Dev Console
public class EmailManager {
 
    // Public method
    public void sendMail(String address, String subject, String body) {
        // Create an email message object
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {address};
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        // Pass this email message to the built-in sendEmail method 
        // of the Messaging class
        Messaging.SendEmailResult[] results = Messaging.sendEmail(
                                 new Messaging.SingleEmailMessage[] { mail });

        // Call a helper method to inspect the returned results
        inspectResults(results);
    }
 
    // Helper method
    private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
        Boolean sendResult = true;

        // sendEmail returns an array of result objects.
        // Iterate through the list to inspect results. 
        // In this class, the methods send only one email, 
        // so we should have only one result.
        for (Messaging.SendEmailResult res : results) {
            if (res.isSuccess()) {
                System.debug('Email sent successfully');
            }
            else {
                sendResult = false;
                System.debug('The following errors occurred: ' + res.getErrors());                 
            }
        }

        return sendResult;
    }
   
}
 
Need assistance building a test clase for the following 2 triggers

Trigger 1
trigger UpdateCloseDate on Opportunity (after update) {

List <SVS_Product__c> newProd= new List<SVS_Product__c>();
for(Opportunity opp: trigger.new)
{
if (Trigger.oldMap.get(opp.Id).CloseDate!= Trigger.newMap.get(opp.Id).CloseDate)
{
List <SVS_Product__c> Prod= new List<SVS_Product__c>([Select Id from SVS_Product__c where Opportunity__c=:opp.Id]); 
for (SVS_Product__c Pro: Prod)
{
Pro.Closed_Date__c=opp.CloseDate;
newProd.add(Pro);
}
}
}
update newProd;
}

Trigger 2

 trigger UpdateStage on Opportunity (after update) {

List <SVS_Product__c> newProd= new List<SVS_Product__c>();
for(Opportunity opp: trigger.new)
{
if (Trigger.oldMap.get(opp.Id).CloseDate!= Trigger.newMap.get(opp.Id).CloseDate)
{
List <SVS_Product__c> Prod= new List<SVS_Product__c>([Select Id from SVS_Product__c where Opportunity__c=:opp.Id]); 
for (SVS_Product__c Pro: Prod)
{
Pro.Product_Stage__c=opp.StageName;
newProd.add(Pro);
}
}
}
update newProd;
}
I want to see if anyone can provide advise on how I might be able to create seperate page layouts for each of the Opportunity Products selected? 

For instance we have a product called online Solutions and one called Promotions.  When you select online solutions I need specific fields and pickvalues to be displayed but when you select Promotions I need different fields and pickvalues to show up. 

We have 5 products and each have different Services,Fees and Options. 

I would like to see if anyone has a recommendation on how I could achieve the following request.

 

I would like for a box of recommend documents and next steps to pop up for my sales team on the Lead and Opportunity objects.

I want the documents and next steps to change based on the Stage/Status and what product they select. 

The recommended documents would be housed on the content object.  

 

FYI -I have already looked at Sales Coach and that is not completely what I am looking for.   

I need help building a trigger on my customer object called Vendor Relationship.  WHen a user changes the status to Declined and the Declined Reason code to one of the Pickvalues.  I want the trigger to auto Share the record with one of my Salesforce to Salesforce Connections. 

 

 

I built this code and migrated it to Production at the time it worked fine. Now it is throwing a error message because a new Validation Rule was built after the migration was done.  What do I need to to to fix the Test Class. 

 

Current Test Class

 

@istest
public class TestClassOpportunitySubmitForApproval{

static testMethod void TestMethodApp() {
 
 
   list<id> ids=new list<id>();
  ids.add('00570000001TNMK');
  RecordType rt=[Select r.Id, r.Name, r.SobjectType from RecordType r Where r.Name='Paycard Team' And r.SobjectType='Opportunity' And IsActive=true];
   Opportunity opp=new opportunity(name='test',closeDate=Date.newInstance(2012,7,23), StageName='prospect', Incentive_Offer__c='yes',Incentive_Justification__c='Test',RecordTypeID=rt.id,ForecastCategoryName='pipeline',type='New Business', Product_Category__c='RCS', Opportunity__c='Branded Debit Payroll',
   Adoption_Rate__c=15.0,Total_Employees__c=10,Pay_Cycle__c='Weekly',Current_Employees_Recieving_Checks__c=200,Standard_Pricing__c='Yes',Opportunity_Justification__c='Test');
   insert opp;
       /* Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setNextApproverIds(ids);
        req1.setObjectId(opp.id);
        
        // Submit the approval request for the opportunity
    
        Approval.ProcessResult result = Approval.process(req1);*/
}
        


}

Error Message

 

BUILD FAILED
C:\Users\deepika\Desktop\Comdata\Migration\Prod\build.xml:14: FAILURES:
Test failure, method: TestClassOpportunitySubmitForApproval.TestMethodApp -- Sys
tem.DmlException: Insert failed. First exception on row 0; first error: FIELD_CU
STOM_VALIDATION_EXCEPTION, Please add a value in the Months Active Per Year: [Mo
nths_Active_Per_Year__c] stack Class.TestClassOpportunitySubmitForApproval.TestM
ethodApp: line 12, column 1

Code coverage issue, class: OpportunitySubmitForApproval -- Test coverage of sel
ected Apex Trigger is 0%, at least 1% test coverage is required
Code coverage issue -- Average test coverage across all Apex Classes and Trigger
s is 0%, at least 75% test coverage is required.

I am building a workflow rule that will trigger and email alert when a lead owner is changed.

Here is the formula I built but I keep getting a syntax error that says Ischanged can not be used in this type of formula

 

AND(
ISPICKVAL(Lead Source, "Ceridian"),
ISCHANGED (OwnerID)
)

 

More Info:  I have leads that come into a Queue the Queue managers go into the queue and change the lead owner from Cross Sell Queue to on of our saleforce users,  I need an email alert to go out to the new owner when this happens. 

 

 

 

 

  • September 21, 2012
  • Like
  • 0

I need an apex trigger that will send an email alert to both the Lead owner and the Lead Owners Manager when a lead has not been read for 2 days after the created date. 

 

Can anyone help me write the trigger and the Test Class for the trigger. 

  • September 20, 2012
  • Like
  • 0

I want to create an email alert when the Picklist value for lead source equals Ceridian or Cross Sell and the Ownerid has been changed.

 

Additional info- We have a cross sell process where we load leads with dataloader each day and assign them to a cross sell queue an email alert goes out to the users in that queue letting them know that there has been a new cross sell lead created.  One of those users then goes in and changes the Lead Owner from the Cross Sell Queue to one of our users.  I need a specific email to go out when that happens. 

 

 

  • September 19, 2012
  • Like
  • 0

I built a lookup Relationship field on the opportunity page that looks up to the User Object in order to create a workflow rule and email alert that will alert both the Opportunity Owner and that individuals manager.

 

I need to have that field populated based on the role hierarchy at my company.  Can anyone help me with building the code for the trigger the field needs to be populated every time an opportunity is created.

  • September 12, 2012
  • Like
  • 0

I built a workflow the sends an email alert to the lead owner when the status is Open and the Last Modified is greater then 2 days. In the workflow I have an email alert that goes to the lead owner.  I want an email to also go to the lead owners manager.

 

How would I do this?

  • September 11, 2012
  • Like
  • 0

 

I built this trigger and it works fine in the sandbox before I can move it to production it has to meet 75% or better.  Can anyone help me write a test class for this trigger so that I can get it moved to production?  Here is the trigger.

 

 

1

2
  3
  4
  5
  6
  7
  8
  9 10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47

trigger   OpportunitySubmitForApproval on Opportunity (after insert) {
 
  List<Approval.ProcessSubmitRequest> approvalReqList=new   List<Approval.ProcessSubmitRequest>();
 
 
  for (Opportunity opp: Trigger.New)
 
  {
 
  if (opp.Incentive_Offer__c =='Yes' &&
  opp.RecordTypeID == '012V00000000ESK')
 
  {
 
  // create the new approval request to submit
 
  Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
 
  req.setComments('Submitted for approval. Please approve.');
 
  req.setObjectId(opp.Id);
 
  approvalReqList.add(req);
 
  }
 
  }
 
 
 
  // submit the approval request for processing
 
  List<Approval.ProcessResult> resultList =   Approval.process(approvalReqList);
 
  // display if the reqeust was successful
 
  for(Approval.ProcessResult result: resultList )
 
  {
 
  System.debug('Submitted for approval successfully: '+result.isSuccess());
 
  }
  
  
  }

I am trying to get an opportunity to auto submit for an approval process called Incentive offer when the field Incentive offer in the oppportunity is Yes.

 

I build the following but keep getting an error message error: expecting a right parentheses, found 'Offer' at line 5 column 30

 

 

trigger OpportunitySubmitForApproval on Opportunity (after update) { 

 

     for (Integer i = 0; i < Trigger.new.size(); i++) {        

 

  if (Trigger.Incentive Offer Yes) {             

 

// create the new approval request to submit      

Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();     

req.setComments('Submitted for approval. Please approve.');

req.setObjectId(Trigger.new[i].Id);           

// submit the approval request for processing           

Approval.ProcessResult result = Approval.process(req);           

// display if the reqeust was successful           

System.debug('Submitted for approval successfully: '+result.isSuccess());         

 

              }     

 

         }

 

}

I am trying to get an opportunity to auto submit for an approval process called Incentive offer when the field Incentive offer in the oppportunity is Yes.

 

I build the following but keep getting an error message error: expecting a right parentheses, found 'Offer' at line 5 column 30

 

 

trigger OpportunitySubmitForApproval on Opportunity (after update) { 

 

     for (Integer i = 0; i < Trigger.new.size(); i++) {        

 

  if (Trigger.Incentive Offer Yes) {             

 

// create the new approval request to submit      

Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();     

req.setComments('Submitted for approval. Please approve.');

req.setObjectId(Trigger.new[i].Id);           

// submit the approval request for processing           

Approval.ProcessResult result = Approval.process(req);           

// display if the reqeust was successful           

System.debug('Submitted for approval successfully: '+result.isSuccess());         

 

              }     

 

         }

 

}

I am trying to get an opportunity to auto submit for an approval process called Incentive offer when the field Incentive offer in the oppportunity is Yes.

 

I build the following but keep getting an error message error: expecting a right parentheses, found 'Offer' at line 5 column 30

 

 

trigger OpportunitySubmitForApproval on Opportunity (after update) {  

 

     for (Integer i = 0; i < Trigger.new.size(); i++) {         

 

  if (Trigger.Incentive Offer Yes) {              

 

 // create the new approval request to submit       

 Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();      

 req.setComments('Submitted for approval. Please approve.');

 req.setObjectId(Trigger.new[i].Id);            

 // submit the approval request for processing            

Approval.ProcessResult result = Approval.process(req);            

 // display if the reqeust was successful            

 System.debug('Submitted for approval successfully: '+result.isSuccess());          

 

              }      

 

         }

 

 }

 

I have 2 fields on my opportunity page called Incentive Offer (Picklist-Yes -No) and Justification (Text Field)  I want these fields hidden from the page unless the amount field is equal to or greater then 30,000.  The amount field is a formula field that gets calculated based on several other fields.  It is auto Populated.

 

Salesforce is telling me this can not be done.  Is there anyone who knows or has and idea for a work around?

I need help creating a formula and also if anyone is holding a training or webinar on building formulas I would love to attend as I am terriable at it.

 

I have a Picklist Field called Notifications Days and a Date field called Contract End Date.  I also have another field called Notification Date I want to build a formula that would auto populate the Notification Date based on what is entered in the other 2 fields.

 

For Instance if I have 3/20/2012 in the Contract End Date and I have Selected 20 Days from the Picklist in Notification Days I want the Notification date field to auto populate +10 days.   So in this instance the date would auto populate to 2/20/2012.

 

 

 

  1. I am trying to create a report that tells me by percentage how much a rep has grown month over month.  I am having trouble getting the formula to give me a percentage of Octobers sales verses Novembers sales.  It is giving me the percentage in $ instead of percentage even though I am telling it I want a percentage. 

Can anyone help me with the formula I need in the report to accomplish this.

Can anyone help me build a formula for a workflow field update? 

 

I have a field called Contract Expire Date and we have to send out a Renewal Notification a certian amount of days before this date.  I have a field called Renewal Notification Terms and my users will populate this as we get signed agreements based on the term days for example 90 days.

 

I need a formula that will take the Contract Expiration date and subtract the number of days indicated in the Renewal Notification field and populate the field called Communication Date.

 

For instance if the Expire date is 11/28/2011 and the Renewal Notification is 60 days i need the Communication Date to read 9/26/2011.

I know that I have some weird request but here it goes.

 

Is there away to make a field that sets on the Opportunity Page (Services) that also show up on the accounts page?

 

For instance if I create a new opportunity and I log a service in the opportunity.  I want to also be able to see that the account purchased that service from the accounts tab.

 

The reason is we have 2 teams once an opportunity is closed won the CS team takes over and mantains the account they need to be able to see at a quick glance the service the accounts are getting. 

 

They could scroll down to the opps section in the history but there will be so many opps logged against that account that they will have to sort through them all instead of having them at a glance. 

I built this code and migrated it to Production at the time it worked fine. Now it is throwing a error message because a new Validation Rule was built after the migration was done.  What do I need to to to fix the Test Class. 

 

Current Test Class

 

@istest
public class TestClassOpportunitySubmitForApproval{

static testMethod void TestMethodApp() {
 
 
   list<id> ids=new list<id>();
  ids.add('00570000001TNMK');
  RecordType rt=[Select r.Id, r.Name, r.SobjectType from RecordType r Where r.Name='Paycard Team' And r.SobjectType='Opportunity' And IsActive=true];
   Opportunity opp=new opportunity(name='test',closeDate=Date.newInstance(2012,7,23), StageName='prospect', Incentive_Offer__c='yes',Incentive_Justification__c='Test',RecordTypeID=rt.id,ForecastCategoryName='pipeline',type='New Business', Product_Category__c='RCS', Opportunity__c='Branded Debit Payroll',
   Adoption_Rate__c=15.0,Total_Employees__c=10,Pay_Cycle__c='Weekly',Current_Employees_Recieving_Checks__c=200,Standard_Pricing__c='Yes',Opportunity_Justification__c='Test');
   insert opp;
       /* Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setNextApproverIds(ids);
        req1.setObjectId(opp.id);
        
        // Submit the approval request for the opportunity
    
        Approval.ProcessResult result = Approval.process(req1);*/
}
        


}

Error Message

 

BUILD FAILED
C:\Users\deepika\Desktop\Comdata\Migration\Prod\build.xml:14: FAILURES:
Test failure, method: TestClassOpportunitySubmitForApproval.TestMethodApp -- Sys
tem.DmlException: Insert failed. First exception on row 0; first error: FIELD_CU
STOM_VALIDATION_EXCEPTION, Please add a value in the Months Active Per Year: [Mo
nths_Active_Per_Year__c] stack Class.TestClassOpportunitySubmitForApproval.TestM
ethodApp: line 12, column 1

Code coverage issue, class: OpportunitySubmitForApproval -- Test coverage of sel
ected Apex Trigger is 0%, at least 1% test coverage is required
Code coverage issue -- Average test coverage across all Apex Classes and Trigger
s is 0%, at least 75% test coverage is required.

I am building a workflow rule that will trigger and email alert when a lead owner is changed.

Here is the formula I built but I keep getting a syntax error that says Ischanged can not be used in this type of formula

 

AND(
ISPICKVAL(Lead Source, "Ceridian"),
ISCHANGED (OwnerID)
)

 

More Info:  I have leads that come into a Queue the Queue managers go into the queue and change the lead owner from Cross Sell Queue to on of our saleforce users,  I need an email alert to go out to the new owner when this happens. 

 

 

 

 

  • September 21, 2012
  • Like
  • 0

I need an apex trigger that will send an email alert to both the Lead owner and the Lead Owners Manager when a lead has not been read for 2 days after the created date. 

 

Can anyone help me write the trigger and the Test Class for the trigger. 

  • September 20, 2012
  • Like
  • 0

I am trying to get an opportunity to auto submit for an approval process called Incentive offer when the field Incentive offer in the oppportunity is Yes.

 

I build the following but keep getting an error message error: expecting a right parentheses, found 'Offer' at line 5 column 30

 

 

trigger OpportunitySubmitForApproval on Opportunity (after update) { 

 

     for (Integer i = 0; i < Trigger.new.size(); i++) {        

 

  if (Trigger.Incentive Offer Yes) {             

 

// create the new approval request to submit      

Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();     

req.setComments('Submitted for approval. Please approve.');

req.setObjectId(Trigger.new[i].Id);           

// submit the approval request for processing           

Approval.ProcessResult result = Approval.process(req);           

// display if the reqeust was successful           

System.debug('Submitted for approval successfully: '+result.isSuccess());         

 

              }     

 

         }

 

}

I am trying to get an opportunity to auto submit for an approval process called Incentive offer when the field Incentive offer in the oppportunity is Yes.

 

I build the following but keep getting an error message error: expecting a right parentheses, found 'Offer' at line 5 column 30

 

 

trigger OpportunitySubmitForApproval on Opportunity (after update) {  

 

     for (Integer i = 0; i < Trigger.new.size(); i++) {         

 

  if (Trigger.Incentive Offer Yes) {              

 

 // create the new approval request to submit       

 Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();      

 req.setComments('Submitted for approval. Please approve.');

 req.setObjectId(Trigger.new[i].Id);            

 // submit the approval request for processing            

Approval.ProcessResult result = Approval.process(req);            

 // display if the reqeust was successful            

 System.debug('Submitted for approval successfully: '+result.isSuccess());          

 

              }      

 

         }

 

 }

 

I have 2 fields on my opportunity page called Incentive Offer (Picklist-Yes -No) and Justification (Text Field)  I want these fields hidden from the page unless the amount field is equal to or greater then 30,000.  The amount field is a formula field that gets calculated based on several other fields.  It is auto Populated.

 

Salesforce is telling me this can not be done.  Is there anyone who knows or has and idea for a work around?

I need help creating a formula and also if anyone is holding a training or webinar on building formulas I would love to attend as I am terriable at it.

 

I have a Picklist Field called Notifications Days and a Date field called Contract End Date.  I also have another field called Notification Date I want to build a formula that would auto populate the Notification Date based on what is entered in the other 2 fields.

 

For Instance if I have 3/20/2012 in the Contract End Date and I have Selected 20 Days from the Picklist in Notification Days I want the Notification date field to auto populate +10 days.   So in this instance the date would auto populate to 2/20/2012.

 

 

 

  1. I am trying to create a report that tells me by percentage how much a rep has grown month over month.  I am having trouble getting the formula to give me a percentage of Octobers sales verses Novembers sales.  It is giving me the percentage in $ instead of percentage even though I am telling it I want a percentage. 

Can anyone help me with the formula I need in the report to accomplish this.