• jpben
  • NEWBIE
  • 30 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 37
    Questions
  • 22
    Replies
Does anyone have an idea how to automatically update the Campaign Member "Status" field when you click on the Convert Lead or Create Opportunity button from the Campaign Member page?  When the Opportunity is created, I want to automatically update the Status of the originating Campaign Member record to "Converted".  

How do you build a trigger for this?  The whole Campaign and Campaign Member object is very tricky.  I want to be able to run a report and determine which Campaign Member record are being converted to Opportunities.  
  • August 12, 2015
  • Like
  • 0
Hi All, 

Need assistance on my trigger.  I have this trigger that creates 2 Invoice Schedule records (custom object) when a new contract is created.  The part that I need help on is linking the 2 Invoice Schedule records into the Contract.  I need to populate the Contract lookup field (Contract__c) on the Invoice Schedule record.  

Thanks in advance.  

trigger Technology_AddInvoiceSchedule on Contract (before insert) {
//When a Lynx or iKM contract are created, insert 2 Invoice Schedule records

List<Invoice_Schedule__c> invschedlist = new List<Invoice_Schedule__c>();
    for (Contract cont: Trigger.new){
        if(cont.RecordTypeId=='012J00000004xUI'||cont.RecordTypeId=='012J00000004xUJ'){
//Record Types are Technology: Lynx and Technology: iKnowMed.

Invoice_Schedule__c  invsched1 = new Invoice_Schedule__c();
            invsched1.Name='First Invoice';
            invsched1.Invoice_Number__c='TBD';
            invsched1.Invoice_Amount__c=0;
            invsched1.Opportunity__c=cont.Opportunity__c;
            invsched1.RecordTypeId='012J00000004zD9';
            
            
 Invoice_Schedule__c  invsched2 = new Invoice_Schedule__c();
            invsched2.Name='Recurring Invoice';
            invsched2.Invoice_Number__c='TBD';
            invsched2.Invoice_Amount__c=0;
            invsched2.Opportunity__c=cont.Opportunity__c;
            invsched2.RecordTypeId='012J00000004zD9';    
            
            invschedlist.add(invsched1); 
            invschedlist.add(invsched2);
        }
        if(invschedlist.size()>0)       
        insert invschedlist;
    }
    
}
  • October 29, 2014
  • Like
  • 0
Anyone has a code to share that will allow me to add Opportunity products upon creation of the Opportunity.  I need to add 20 line items upon creation of the record to alleviate some of the manual data entry for our sales reps.  

Thanks in advance. 
  • October 28, 2014
  • Like
  • 0
Is there a way to automatically sort Opportunity Products?  By default, SFDC sorts Oppty product by name (alphabetically).  If i create a number field and populate each Pricebook Entry with the sort order number, can a trigger use that field to sort the Oppty products?   

If someone can share a code, i would greatly appreciate it.  This limitation is a pain in the butt. 
  • October 23, 2014
  • Like
  • 0
Is there a way to remove the "Quote Acceptance Information" section on the pdf template on Quotes.  We need to be able to modify so that we can include multiple signers to the document.  Please advice. 
  • August 11, 2014
  • Like
  • 0
Does anyone else have issues with the publisher icon (+ icon) not appearing in Salesforce for Outlook?  I need the ability to create Cases.  I can't seem to troubleshoot this.  

I have all of the system requirements:
https://help.salesforce.com/HTViewHelpDoc?id=outlookcrm_sys_req.htm&language=en_US

I have followed these troubleshooting instructions:
https://help.salesforce.com/HTViewSolution?id=000192820&language=en_US
https://help.salesforce.com/HTViewHelpDoc?id=outlookcrm_side_panel_set_up_publisher.htm&language=en_US

I have upgraded to IE 11.
I have uninstalled and also intalled the 2.5.1 version of Salesforce for Outlook.

The icon is still not showing up !!!  Please help. 
  • August 02, 2014
  • Like
  • 0
I have 100+ Opportunities that has Opportunity Products associated to it.  What is the quickest way to delete the Opportunity Product associated to the Opportunity?  

Thanks in advance. 
  • May 22, 2014
  • Like
  • 0
Is there a way to delete selected records from the Org's trash bin?  I do not want to completely wipe out the trash bin because we would like to retain some records if needed to be undeleted.  Knowing that we only have 50k records that we can keep in the trashbin, we would like to clear some space to accommodate other records. 

Thanks in advance.
  • May 19, 2014
  • Like
  • 1
How do you control the order of columns when using Data Loader to extract data to a csv file?  We want a certain format on the csv file where the fields/columns are in certain order.  

Thanks in advance. 
  • April 05, 2014
  • Like
  • 0
We have a report that I am trying to extract automatically to a csv file.  I typically use the Command Line Interface (using DataLoader) to do this.  However, this particular report uses a Report Type of "Opportunities w/ Products".  I dont think DataLoader can do a nested SOQL query.  Any suggestions how i can automate extraction of data if the information is pulling from 2 objects.  


SELECT CloseDate, Name, Generics_Analyst__c,(SELECT Site__c,Quantity,Approved_QTY__c,Disposition__c,Product_Name__c,Status__c FROM OpportunityLineItems) FROM Opportunity
WHERE RecordTypeId = '012G00000015ChQ' AND StageName != 'FSE Created' AND CloseDate = TODAY
  • January 30, 2014
  • Like
  • 0

Hello,

 

I am looking for a solution where our users can click a button on their UI, launch a page to allow them to select a csv file, and then mass update records of a custom object.  The CSV will contain an external id (key) and fields that will be updated.  I know that there are import wizards functionality built in SFDC but I dont want to give users this access and potentially update other records.  I want the button because the process is already predefined for the users.   I appreciate any suggestions and advice. 

 

 

Thanks,

John

 

 

  • November 21, 2013
  • Like
  • 0

How do you create a SOQL query for date ranges like:

  • Current Quarter
  • Previous Quarter
  • Next Quarter
  • Previous and Current Quarter

Thanks in advance

  • November 09, 2013
  • Like
  • 0

Has anyone done encryption of attachments using crypto class?  What we want to do is encrypt attachments to all users and give only specific users to decrypt.  Can someone share their code?  I am new to this functionality and I would like to get some sample codes to get me started.  Unfortunately, I can't find a whole lot of this use case here.  And the sample codes provided here http://wiki.developerforce.com/page/Apex_Crypto_Class doesn't help me much either. 

 

Any info is appreciated.  

 

Thanks,

John

  • August 28, 2013
  • Like
  • 0

We have an approval process that has 4 steps of approval.  Can the system fire a validation rule in between approval steps. For example, Rep A approves in step 1.  In step 2, Rep B needs to fill in some fields before approving.  How can I alert Rep B in step 2 that he needs to fill out a field before he can successfully approve.

 

Thanks,

John

  • August 22, 2013
  • Like
  • 0

Does anyone have information how to encrypt attachments in SFDC?  

 

Thanks in advance,

John

  • August 20, 2013
  • Like
  • 0

Hello,

 

I need some help with incorporating exception handling (try/catch) on my code below.  I have a trigger that auto updates the stage on the Opportunity to "Feasibility", when a Feasibility (custom object) record is created. We have a validation rule on the Opportunity that all the required fields will need to be filled in before you can change the Opportunity Stage to "Feasibility".  How can I update the dml error message to "Fill in all required fields on the Opportunity" so that our user doesnt see this long text.  

 

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger OpptyStageUpdate_Feasibility caused an unexpected exception, contact your administrator: OpptyStageUpdate_Feasibility: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 006J0000007V2QeIAK; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Field is required.: [Budget__c]: Trigger.OpptyStageUpdate_Feasibility: line 31, column 1

 

 

 

trigger OpptyStageUpdate_Feasibility on Feasibility__c (after insert, after update) {

// Updates the Opportunity Stage to Feasibility when Feasibility record is created

//Lists the Opportunities from Proposals that meet criteria

List<ID> feasIds = new List<ID>();
for (Feasibility__c f: Trigger.new){
if(f.Stage__c <> null){
feasIds.add(f.Opportunity__c);
}
}

//Pulls the SOQL list and updates the Oppty Stage
List<Opportunity> opptyList = [SELECT ID, StageName, Opportunity_Type__c, RecordTypeId
FROM Opportunity
WHERE ID in:feasIds];



for (Feasibility__c f: Trigger.new){
for (Opportunity opp: opptyList){

if (f.Stage__c <> 'Closed Rejected'){
opp.StageName = 'Feasibility' ;
}
}

}

update opptyList;

}

 

 

 

  • June 11, 2013
  • Like
  • 0

Hi All,

 

I need some help with my trigger.  I have the following trigger that sends an email to the task creator when the task assignee has completed the task.  I would like to include the name of the Related To object in the email.  I have the WhatId in my code but this only pulls the Id of the record.  I tried WhatName but i dont think there is such a field.  

 

 

 

trigger TaskSendEmail on Task (before update) {
// Don't forget this- all triggers in SF are bulk triggers and so
// they can fire on multiple objects. So you need to process objects
// in a FOR loop.
Set<Id> CBIds = new Set<Id>();

for(Task tsk: Trigger.New)

if(tsk.RecordTypeId == '012G00000017Bb5' && tsk.Status == 'Completed' &&
tsk.OwnerId <> tsk.CreatedById)

CBIds.add(tsk.CreatedById);

// Build a map of all users who created the tasks.
Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :CBIds]);

for(Task tsk : Trigger.New){
if(!TriggerHelperClass.HasAlreadyFired()){

if(tsk.RecordTypeId == '012G00000017Bb5' && tsk.Status == 'Completed'
&&
tsk.OwnerId <> tsk.CreatedById)
{


User theUser = userMap.get(tsk.CreatedById);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {theUser.Email};
mail.setToAddresses(toAddresses); // Set the TO addresses
mail.setSubject('The following Task has been Completed'); // Set the subject
// Next, create a string template. Specify {0}, {1} etc. in place of actual values.
// You can replace these values with a call to String.Format.
String template = 'The following Task has been Completed: \n\n';
template+= 'Related To: {0}\n';
template+= 'Subject: {1}\n';
template+= 'Comments: {2}\n\n';
template+= 'Click the link to access the record: https://cs9.salesforce.com/{3}\n';
String duedate = '';

if (tsk.ActivityDate==null)
duedate = '';
else
duedate = tsk.ActivityDate.format();

List<String> args = new List<String>();
args.add(tsk.WhatId);
args.add(tsk.Subject);
args.add(tsk.Description);
args.add(tsk.Id);




// Here's the String.format() call.
String formattedHtml = String.format(template, args);

mail.setPlainTextBody(formattedHtml);

TriggerHelperClass.setAlreadyFired();
Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});

}
}
}
}

  • May 12, 2013
  • Like
  • 0

 

Hi All,

 

I have the following trigger that adds Revenue Schedule records on the Opportunity when the Opportunity is created.  I would like to update those records when the Opportunity Stage is changed to Closed Won.  I would like the Projected_Accrual_Date__c field on the Revenue Schedule records to be updated in case the Closed Date on the Opportunity is changed.  How can i accomplish this?  

 

Thanks in advance. 

 

 

 

 

trigger RevenueScheduleForecast on Opportunity (after insert) {


//When Onmark Oppty is created, a list of Revenue Schedule Records will be
//inserted into the Opportunity record.

List <Revenue_Schedule__c> RSToInsert = new List <Revenue_Schedule__c> ();

for (Opportunity oppty : Trigger.new) {

if(
(oppty.RecordTypeId == '012A0000000eLsf' ) ||
(oppty.RecordTypeId == '012A0000000eLsk' )
)

{


//Revenue Schedule 1//
Revenue_Schedule__c RS1 = new Revenue_Schedule__c ();
RS1.RecordTypeId = '012K0000000Cz7o';
RS1.Name = 'Month 1';
RS1.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS1.Projected_Accrual_Date__c = oppty.CloseDate;
RS1.Opportunity__c = oppty.Id;

//Revenue Schedule 2//
Revenue_Schedule__c RS2 = new Revenue_Schedule__c ();
RS2.RecordTypeId = '012K0000000Cz7o';
RS2.Name = 'Month 2';
RS2.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS2.Projected_Accrual_Date__c = oppty.CloseDate.adddays(30);
RS2.Opportunity__c = oppty.Id;

//Revenue Schedule 3//
Revenue_Schedule__c RS3 = new Revenue_Schedule__c ();
RS3.RecordTypeId = '012K0000000Cz7o';
RS3.Name = 'Month 3';
RS3.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS3.Projected_Accrual_Date__c = oppty.CloseDate.adddays(60);
RS3.Opportunity__c = oppty.Id;

//Revenue Schedule 4//
Revenue_Schedule__c RS4 = new Revenue_Schedule__c ();
RS4.RecordTypeId = '012K0000000Cz7o';
RS4.Name = 'Month 4';
RS4.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS4.Projected_Accrual_Date__c = oppty.CloseDate.adddays(90);
RS4.Opportunity__c = oppty.Id;

//Revenue Schedule 5//
Revenue_Schedule__c RS5 = new Revenue_Schedule__c ();
RS5.RecordTypeId = '012K0000000Cz7o';
RS5.Name = 'Month 5';
RS5.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS5.Projected_Accrual_Date__c = oppty.CloseDate.adddays(120);
RS5.Opportunity__c = oppty.Id;

//Revenue Schedule 6//
Revenue_Schedule__c RS6 = new Revenue_Schedule__c ();
RS6.RecordTypeId = '012K0000000Cz7o';
RS6.Name = 'Month 6';
RS6.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS6.Projected_Accrual_Date__c = oppty.CloseDate.adddays(150);
RS6.Opportunity__c = oppty.Id;

//Revenue Schedule 7//
Revenue_Schedule__c RS7 = new Revenue_Schedule__c ();
RS7.RecordTypeId = '012K0000000Cz7o';
RS7.Name = 'Month 7';
RS7.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS7.Projected_Accrual_Date__c = oppty.CloseDate.adddays(180);
RS7.Opportunity__c = oppty.Id;

//Revenue Schedule 8//
Revenue_Schedule__c RS8 = new Revenue_Schedule__c ();
RS8.RecordTypeId = '012K0000000Cz7o';
RS8.Name = 'Month 8';
RS8.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS8.Projected_Accrual_Date__c = oppty.CloseDate.adddays(210);
RS8.Opportunity__c = oppty.Id;

//Revenue Schedule 9//
Revenue_Schedule__c RS9 = new Revenue_Schedule__c ();
RS9.RecordTypeId = '012K0000000Cz7o';
RS9.Name = 'Month 9';
RS9.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS9.Projected_Accrual_Date__c = oppty.CloseDate.adddays(240);
RS9.Opportunity__c = oppty.Id;

//Revenue Schedule 10//
Revenue_Schedule__c RS10 = new Revenue_Schedule__c ();
RS10.RecordTypeId = '012K0000000Cz7o';
RS10.Name = 'Month 10';
RS10.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS10.Projected_Accrual_Date__c = oppty.CloseDate.adddays(270);
RS10.Opportunity__c = oppty.Id;

//Revenue Schedule 11//
Revenue_Schedule__c RS11 = new Revenue_Schedule__c ();
RS11.RecordTypeId = '012K0000000Cz7o';
RS11.Name = 'Month 11';
RS11.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS11.Projected_Accrual_Date__c = oppty.CloseDate.adddays(300);
RS11.Opportunity__c = oppty.Id;

//Revenue Schedule 12//
Revenue_Schedule__c RS12 = new Revenue_Schedule__c ();
RS12.RecordTypeId = '012K0000000Cz7o';
RS12.Name = 'Month 12';
RS12.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS12.Projected_Accrual_Date__c = oppty.CloseDate.adddays(330);
RS12.Opportunity__c = oppty.Id;

RSToInsert.add(RS1);
RSToInsert.add(RS2);
RSToInsert.add(RS3);
RSToInsert.add(RS4);
RSToInsert.add(RS5);
RSToInsert.add(RS6);
RSToInsert.add(RS7);
RSToInsert.add(RS8);
RSToInsert.add(RS9);
RSToInsert.add(RS10);
RSToInsert.add(RS11);
RSToInsert.add(RS12);

} //end if

}//end for

try {
insert RSToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}


}

  • May 02, 2013
  • Like
  • 0

Is there a way to automatically select a Pricebook on the Opportunity Product based on a field on the Opportunity?  For example, on Business__c field I have a picklist value called, "software".  If software is selected, i want the "Software" Pricebook to automatically be selected on the Opportunit Products section.  I would like to make it easy for our users since we have about 8 Pricebook catalogs. 

 

Thanks in advance. 

  • April 19, 2013
  • Like
  • 0

I finally got my code to work and now I need help with my Test Class.  My Test Class is only giving me 24% code coverage.  I am not sure how to test the bottom portion of my trigger.  Please advice.  

 

 

Here is my trigger:

 

trigger TaskSendEmail on Task (before update) {
// Don't forget this- all triggers in SF are bulk triggers and so
// they can fire on multiple objects. So you need to process objects
// in a FOR loop.
Set<Id> CBIds = new Set<Id>();

for(Task tsk: Trigger.New)

if(tsk.RecordTypeId == '012Z00000004WFV' && tsk.Status == 'Completed')

CBIds.add(tsk.CreatedById);

// Build a map of all users who created the tasks.
Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :CBIds]);

for(Task tsk : Trigger.New){
if(!TriggerHelperClass.HasAlreadyFired()){

if(tsk.RecordTypeId == '012Z00000004WFV' && tsk.Status == 'Completed')
{


User theUser = userMap.get(tsk.CreatedById);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {theUser.Email};
mail.setToAddresses(toAddresses); // Set the TO addresses
mail.setSubject('The following Task has been Completed'); // Set the subject
// Next, create a string template. Specify {0}, {1} etc. in place of actual values.
// You can replace these values with a call to String.Format.
String template = 'The following Task has been Completed: \n\n';
template+= 'Subject: {0}\n';
template+= 'Comments: {1}\n\n';
template+= 'Click the link to access the record: https://cs11.salesforce.com/{2}\n';
String duedate = '';

if (tsk.ActivityDate==null)
duedate = '';
else
duedate = tsk.ActivityDate.format();

List<String> args = new List<String>();
args.add(tsk.Subject);
args.add(tsk.Description);
args.add(tsk.Id);


// Here's the String.format() call.
String formattedHtml = String.format(template, args);

mail.setPlainTextBody(formattedHtml);

TriggerHelperClass.setAlreadyFired();
Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});

}
}
}
}

 

 

 

Here is my Test Class:

 

@isTest (seeAllData=true)
public class TestTaskSendEmail {

static testMethod void myUnitTest(){


Test.startTest();

Task testTask = new Task ();
testTask.OwnerId='005G0000001jWxo';
testTask.Type='Email';
testTask.Subject='Test';
testTask.ActivityDate=system.Today();
testTask.Priority='Normal';
testTask.Status='Not Started';
insert testTask;

testTask.Status ='Completed';
update testTask;

System.assertEquals (testTask.Status,'Completed');
Test.stopTest();

}
}

  • April 04, 2013
  • Like
  • 0
Is there a way to delete selected records from the Org's trash bin?  I do not want to completely wipe out the trash bin because we would like to retain some records if needed to be undeleted.  Knowing that we only have 50k records that we can keep in the trashbin, we would like to clear some space to accommodate other records. 

Thanks in advance.
  • May 19, 2014
  • Like
  • 1
Hi All, 

Need assistance on my trigger.  I have this trigger that creates 2 Invoice Schedule records (custom object) when a new contract is created.  The part that I need help on is linking the 2 Invoice Schedule records into the Contract.  I need to populate the Contract lookup field (Contract__c) on the Invoice Schedule record.  

Thanks in advance.  

trigger Technology_AddInvoiceSchedule on Contract (before insert) {
//When a Lynx or iKM contract are created, insert 2 Invoice Schedule records

List<Invoice_Schedule__c> invschedlist = new List<Invoice_Schedule__c>();
    for (Contract cont: Trigger.new){
        if(cont.RecordTypeId=='012J00000004xUI'||cont.RecordTypeId=='012J00000004xUJ'){
//Record Types are Technology: Lynx and Technology: iKnowMed.

Invoice_Schedule__c  invsched1 = new Invoice_Schedule__c();
            invsched1.Name='First Invoice';
            invsched1.Invoice_Number__c='TBD';
            invsched1.Invoice_Amount__c=0;
            invsched1.Opportunity__c=cont.Opportunity__c;
            invsched1.RecordTypeId='012J00000004zD9';
            
            
 Invoice_Schedule__c  invsched2 = new Invoice_Schedule__c();
            invsched2.Name='Recurring Invoice';
            invsched2.Invoice_Number__c='TBD';
            invsched2.Invoice_Amount__c=0;
            invsched2.Opportunity__c=cont.Opportunity__c;
            invsched2.RecordTypeId='012J00000004zD9';    
            
            invschedlist.add(invsched1); 
            invschedlist.add(invsched2);
        }
        if(invschedlist.size()>0)       
        insert invschedlist;
    }
    
}
  • October 29, 2014
  • Like
  • 0
Anyone has a code to share that will allow me to add Opportunity products upon creation of the Opportunity.  I need to add 20 line items upon creation of the record to alleviate some of the manual data entry for our sales reps.  

Thanks in advance. 
  • October 28, 2014
  • Like
  • 0
Is there a way to remove the "Quote Acceptance Information" section on the pdf template on Quotes.  We need to be able to modify so that we can include multiple signers to the document.  Please advice. 
  • August 11, 2014
  • Like
  • 0
Does anyone else have issues with the publisher icon (+ icon) not appearing in Salesforce for Outlook?  I need the ability to create Cases.  I can't seem to troubleshoot this.  

I have all of the system requirements:
https://help.salesforce.com/HTViewHelpDoc?id=outlookcrm_sys_req.htm&language=en_US

I have followed these troubleshooting instructions:
https://help.salesforce.com/HTViewSolution?id=000192820&language=en_US
https://help.salesforce.com/HTViewHelpDoc?id=outlookcrm_side_panel_set_up_publisher.htm&language=en_US

I have upgraded to IE 11.
I have uninstalled and also intalled the 2.5.1 version of Salesforce for Outlook.

The icon is still not showing up !!!  Please help. 
  • August 02, 2014
  • Like
  • 0
How do you control the order of columns when using Data Loader to extract data to a csv file?  We want a certain format on the csv file where the fields/columns are in certain order.  

Thanks in advance. 
  • April 05, 2014
  • Like
  • 0

Hello,

 

I am looking for a solution where our users can click a button on their UI, launch a page to allow them to select a csv file, and then mass update records of a custom object.  The CSV will contain an external id (key) and fields that will be updated.  I know that there are import wizards functionality built in SFDC but I dont want to give users this access and potentially update other records.  I want the button because the process is already predefined for the users.   I appreciate any suggestions and advice. 

 

 

Thanks,

John

 

 

  • November 21, 2013
  • Like
  • 0

How do you create a SOQL query for date ranges like:

  • Current Quarter
  • Previous Quarter
  • Next Quarter
  • Previous and Current Quarter

Thanks in advance

  • November 09, 2013
  • Like
  • 0

Does anyone have information how to encrypt attachments in SFDC?  

 

Thanks in advance,

John

  • August 20, 2013
  • Like
  • 0

Hello,

 

I need some help with incorporating exception handling (try/catch) on my code below.  I have a trigger that auto updates the stage on the Opportunity to "Feasibility", when a Feasibility (custom object) record is created. We have a validation rule on the Opportunity that all the required fields will need to be filled in before you can change the Opportunity Stage to "Feasibility".  How can I update the dml error message to "Fill in all required fields on the Opportunity" so that our user doesnt see this long text.  

 

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger OpptyStageUpdate_Feasibility caused an unexpected exception, contact your administrator: OpptyStageUpdate_Feasibility: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 006J0000007V2QeIAK; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Field is required.: [Budget__c]: Trigger.OpptyStageUpdate_Feasibility: line 31, column 1

 

 

 

trigger OpptyStageUpdate_Feasibility on Feasibility__c (after insert, after update) {

// Updates the Opportunity Stage to Feasibility when Feasibility record is created

//Lists the Opportunities from Proposals that meet criteria

List<ID> feasIds = new List<ID>();
for (Feasibility__c f: Trigger.new){
if(f.Stage__c <> null){
feasIds.add(f.Opportunity__c);
}
}

//Pulls the SOQL list and updates the Oppty Stage
List<Opportunity> opptyList = [SELECT ID, StageName, Opportunity_Type__c, RecordTypeId
FROM Opportunity
WHERE ID in:feasIds];



for (Feasibility__c f: Trigger.new){
for (Opportunity opp: opptyList){

if (f.Stage__c <> 'Closed Rejected'){
opp.StageName = 'Feasibility' ;
}
}

}

update opptyList;

}

 

 

 

  • June 11, 2013
  • Like
  • 0

Hi All,

 

I need some help with my trigger.  I have the following trigger that sends an email to the task creator when the task assignee has completed the task.  I would like to include the name of the Related To object in the email.  I have the WhatId in my code but this only pulls the Id of the record.  I tried WhatName but i dont think there is such a field.  

 

 

 

trigger TaskSendEmail on Task (before update) {
// Don't forget this- all triggers in SF are bulk triggers and so
// they can fire on multiple objects. So you need to process objects
// in a FOR loop.
Set<Id> CBIds = new Set<Id>();

for(Task tsk: Trigger.New)

if(tsk.RecordTypeId == '012G00000017Bb5' && tsk.Status == 'Completed' &&
tsk.OwnerId <> tsk.CreatedById)

CBIds.add(tsk.CreatedById);

// Build a map of all users who created the tasks.
Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :CBIds]);

for(Task tsk : Trigger.New){
if(!TriggerHelperClass.HasAlreadyFired()){

if(tsk.RecordTypeId == '012G00000017Bb5' && tsk.Status == 'Completed'
&&
tsk.OwnerId <> tsk.CreatedById)
{


User theUser = userMap.get(tsk.CreatedById);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {theUser.Email};
mail.setToAddresses(toAddresses); // Set the TO addresses
mail.setSubject('The following Task has been Completed'); // Set the subject
// Next, create a string template. Specify {0}, {1} etc. in place of actual values.
// You can replace these values with a call to String.Format.
String template = 'The following Task has been Completed: \n\n';
template+= 'Related To: {0}\n';
template+= 'Subject: {1}\n';
template+= 'Comments: {2}\n\n';
template+= 'Click the link to access the record: https://cs9.salesforce.com/{3}\n';
String duedate = '';

if (tsk.ActivityDate==null)
duedate = '';
else
duedate = tsk.ActivityDate.format();

List<String> args = new List<String>();
args.add(tsk.WhatId);
args.add(tsk.Subject);
args.add(tsk.Description);
args.add(tsk.Id);




// Here's the String.format() call.
String formattedHtml = String.format(template, args);

mail.setPlainTextBody(formattedHtml);

TriggerHelperClass.setAlreadyFired();
Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});

}
}
}
}

  • May 12, 2013
  • Like
  • 0

I finally got my code to work and now I need help with my Test Class.  My Test Class is only giving me 24% code coverage.  I am not sure how to test the bottom portion of my trigger.  Please advice.  

 

 

Here is my trigger:

 

trigger TaskSendEmail on Task (before update) {
// Don't forget this- all triggers in SF are bulk triggers and so
// they can fire on multiple objects. So you need to process objects
// in a FOR loop.
Set<Id> CBIds = new Set<Id>();

for(Task tsk: Trigger.New)

if(tsk.RecordTypeId == '012Z00000004WFV' && tsk.Status == 'Completed')

CBIds.add(tsk.CreatedById);

// Build a map of all users who created the tasks.
Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :CBIds]);

for(Task tsk : Trigger.New){
if(!TriggerHelperClass.HasAlreadyFired()){

if(tsk.RecordTypeId == '012Z00000004WFV' && tsk.Status == 'Completed')
{


User theUser = userMap.get(tsk.CreatedById);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {theUser.Email};
mail.setToAddresses(toAddresses); // Set the TO addresses
mail.setSubject('The following Task has been Completed'); // Set the subject
// Next, create a string template. Specify {0}, {1} etc. in place of actual values.
// You can replace these values with a call to String.Format.
String template = 'The following Task has been Completed: \n\n';
template+= 'Subject: {0}\n';
template+= 'Comments: {1}\n\n';
template+= 'Click the link to access the record: https://cs11.salesforce.com/{2}\n';
String duedate = '';

if (tsk.ActivityDate==null)
duedate = '';
else
duedate = tsk.ActivityDate.format();

List<String> args = new List<String>();
args.add(tsk.Subject);
args.add(tsk.Description);
args.add(tsk.Id);


// Here's the String.format() call.
String formattedHtml = String.format(template, args);

mail.setPlainTextBody(formattedHtml);

TriggerHelperClass.setAlreadyFired();
Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});

}
}
}
}

 

 

 

Here is my Test Class:

 

@isTest (seeAllData=true)
public class TestTaskSendEmail {

static testMethod void myUnitTest(){


Test.startTest();

Task testTask = new Task ();
testTask.OwnerId='005G0000001jWxo';
testTask.Type='Email';
testTask.Subject='Test';
testTask.ActivityDate=system.Today();
testTask.Priority='Normal';
testTask.Status='Not Started';
insert testTask;

testTask.Status ='Completed';
update testTask;

System.assertEquals (testTask.Status,'Completed');
Test.stopTest();

}
}

  • April 04, 2013
  • Like
  • 0

 

Hello,

 

I have a code below that sends an email when a task has been completed.  The issue I have is that the email is being sent twice.  This is due to a Workflow/Field Update on the Task. When the WF fires, the code below sends another email.  I've read that you can create a recursive trigger to prevent this from happening.  What is the proper way to write this recursive trigger based on my code below?  Thanks in advance. 

 

 

 

trigger TaskSendEmail on Task (after update)
{
// Don't forget this- all triggers in SF are bulk triggers and so
    // they can fire on multiple objects. So you need to process objects
    // in a FOR loop.
    Set<Id> CBIds = new Set<Id>();
   
    for(Task tsk: Trigger.New)
    {
    	if(tsk.RecordTypeId == '012Z00000004WFV' && tsk.Status == 'Completed')
        {
        	CBIds.add(tsk.CreatedById);
        }
    }
       
   
    // Build a map of all users who created the tasks.
    Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :CBIds]);// Creating map for users who satisfied the conditions
    for(Task tsk : Trigger.New)
    {
        if(tsk.RecordTypeId == '012Z00000004WFV' && tsk.Status == 'Completed')
        {
        	User theUser = userMap.get(tsk.CreatedById);  // you will not have the user records for all the tasks createdbyIds
        
	        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
	        String[] toAddresses = new String[] {theUser.Email};
	        mail.setToAddresses(toAddresses);    // Set the TO addresses
	        mail.setSubject('The following Task has been Closed');    // Set the subject
	        // Next, create a string template. Specify {0}, {1} etc. in place of actual values.
	        // You can replace these values with a call to String.Format.
	        String template = 'Hello {0}, \nYour task has been modified. Here are the details - \n\n';
	        template+= 'Subject - {1}\n';
	        template+= 'Due Date - {2}\n';
	        String duedate = '';
	        
	        if (tsk.ActivityDate==null)
	            duedate = '';
	        else
	            duedate = tsk.ActivityDate.format();
	            
	        List<String> args = new List<String>();
	        args.add(theUser.Name);
	        args.add(tsk.Subject);
	        args.add(duedate);
	        
	       
	        // Here's the String.format() call.
	        String formattedHtml = String.format(template, args);
	       
	        mail.setPlainTextBody(formattedHtml);
	        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
	    }
    }
}
  • April 01, 2013
  • Like
  • 0

I would like a VF page block in the Case page.  It will have a list of Contacts related to the Account that has been selected on the Case.  Can this be done with a standard contoller or do i need a custom controller.  Can anyone assist with a sample code or point me to a resource. Thanks. 

  • March 04, 2013
  • Like
  • 0

I have the following Button below that opens a page to add a new record for "Drugs__c".  It pre-populates the Account field on the page, but I also want to auto populate the DrugsName (Name (text)) field  with the following text, "default".  I dont want our users to worry about filling in this field since it will be overrided with a naming convention using Workflow/FieldUpdate once the record is saved.  

 

Highlighed in red is the id of the field name, "Drugs Name" in the custom object "Drugs__c".  The code is not working properly and not populating the Drug Name field.  Suggestions how to correct this.  

 

 

/a0J/e?CF00NZ0000000etH2={!Account.Name} & CF00NZ0000000etH2_lkid={!Account.Id}&retURL=%2F{!Account.Id}&01IZ00000008qBS="default"

 

 

  • December 02, 2012
  • Like
  • 0

Can anyone point me in the direction of any triggers that are used to automatically re-establish revenue schedules (for example, if the Opp Close Date changes). Is this even possible?

 

Thank you so much for the help!

I would like to be able to edit specific fields in the Assets records related to an Account. Below you will find the visualforce page I wrote to do this. When I click the save button, it doesn't actually save the values I have put in the input Fields. What am I doing wrong here?

 

<apex:page standardController="Account">
    <apex:Form >
        <apex:pageBlock title="Check in Stations for {!Account.Nickname__c}">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!account.assets}" var="item">
                <apex:column value="{!item.Name}"/>
                <apex:column headerValue="Serial Number">
                    <apex:inputField value="{!item.SerialNumber}"/>
                </apex:column>
                <apex:column headerValue="Ethernet MAC Address">
                    <apex:inputField value="{!item.Ethernet_MAC_Address__c}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:Form>
</apex:page>

 

Hello,

I am trying to play with Macros in service console. I was able to update the settings and get the macro created but having difficulty with the instructions. I am unable to select a context (no drop down options available) to proceed further with the instructions. I must be missing something really silly. Does anyone know what is it?

Thank you!