• case comments
  • NEWBIE
  • 45 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 9
    Replies
We have implemented the Public Knowledge Base from appexchange.  VF page isn't one of our strong suits. We were able to change the header logo and footer logo to our company logo, but is there a way to change the Contact Us link to something else or remove it all together?
I have a simple visualforce form that's asking a couple of questions.  I would like for this form to be launched from the Case object and have the Case number passed to visualforce page.

The custom fields of this visualforce page is using fields on another custom object.  I thought maybe I could have just created a custom button to launch the visualforce page, but the since the page was used using a custom object, it's not showing up when creating the custom button on the case object.

Any help would be greatly appreciated.  Thanks.
I'm trying to set up some test code to insert 200 products.  When I run the test code, I get an error stating: List has no rows for assignment.  This is occuring on the code for:
Pricebook2 pbook = [Select id from Pricebook2 where isStandard = true];

The weird thing is, I copied and pasted the exact same code to execute anonymous and it ran fine, but running it through test coverage errors out.  Am I missing something here?
@isTest

public class AfterOppTriggerTest {
    static testMethod void OppTest(){
        //create a list of products       
        List<Product2> productstoinsert = new List <Product2>();
        for(Integer x = 0; x < 200 ;x++){
            Product2 newprod = new Product2(Name = 'newprod' + x, isactive = true);
            productstoinsert.add(newprod);
          
        }
        insert productstoinsert;
        //Select the pricebook
        Pricebook2 pbook = [Select id from Pricebook2 where isStandard = true];
        system.debug(pbook);
        
        //create pricebook entries
        List<PriceBookEntry> pbinsert = new List<PriceBookEntry>();
        for(Integer x=0; x < 200; x++){
            PriceBookEntry pbentry = new PricebookEntry(Pricebook2ID = pbook.Id, Product2ID = productstoinsert[x].id, unitprice = 100, isactive = true, usestandardprice = false);
            pbinsert.add(pbentry);
            system.debug(pbentry);
        }
        insert pbinsert;
        
        
    }
}


I have a trigger in place to insert a list into a custom object.  I first want to make sure there aren't any duplicates first before inserting.  So far I have an sObject list of what's going to be inserted and another sObject list of what's already there.  How can i find what the difference is between the two lists to insert?

For example, let's use the Account object.  If i have the following in a List
List1
Acme, San Francisco
Acme, Los Angeles
IBM, New York

List2
Acme, San Francisco
Acme, Los Angeles
Acme, New York
IBM, New York

Out of those two lists, how can I pull out only Acme, New York?
I'm trying to create a button to put on the customer portal layout to allow them to re-open a closed case.  I've created a custom button that calls on a VF page.  Everything seems to work fine, but the customer can click that button at anytime, even for a non closed case.  What kind of  logic can I put in to only allow the button to be executed for a closed case?
The simple answer would be to change the record type of the closed case to something else and put the button on the new record types page layout, but I can't chnage any record types for our own business process reasons. 
Any help would be greatly appreciated.  Thanks.

public class ReOpenExtension {
    public ReOpenExtension(ApexPages.StandardController controller){
    Case c = (Case)controller.getRecord();
    c.Status = 'In Progress';
}
public static void testMethodtest() {
    Case c = new Case();
    ApexPages.StandardController controller = new ApexPages.StandardController(c);
    ReOpenExtension extension = new ReOpenExtension(controller);
    System.assertEquals(c.Status,'In Progress');
    }
}


<apex:page standardController="Case" extensions="ReOpenExtension">
<apex:form >
<h1> Re-Open Case Form</h1>
<apex:pageblock title="{!case.CaseNumber}">
<apex:pageblocksection columns="1" >
<apex:inputtextarea value="{!case.Re_Open_Case_Reason__c}" cols="100" rows="5"/>
</apex:pageblocksection>
<apex:pageblockButtons >
               
                <apex:commandbutton action="{!save}" value="Save"/>
               
                <apex:commandbutton action="{!cancel}" value="Cancel"/>
            </apex:pageblockButtons>
</apex:pageblock>
</apex:form>

</apex:page>
I have a form in visualforce that's gathering customer information, but I would like to be able to also allow them to upload attachments to the form.  From what I've read, because I'm using the <apex:form> tag, I can't just use <apex:detail relatedlist="true"/>.  I would need to create a custom controller to handle the attachments.
I was thinking maybe having the customer input all the fields and upon hitting the submit button, that then goes to anohter VF page that asks them to enter attachments. Something like this:
http://bobbuzzard.blogspot.com/2011/01/uploading-multiple-attachments-via.html
That is where I'm finding difficult.  How would I go about doing that? Any help would be greatly appreciated.  Thanks.

<apex:page standardController="Drupal_UI_Assets__c" showHeader="true">
  <h1>Drupal UI Assets(JCORE)</h1>

  <apex:form >

  <apex:pageBlock >

  Please provide assets used to build demonstration sites and which will later be used for site development<p/>
  <b>Please state the jcode or journal name (if new journal)</b><p/>
  <apex:inputField value="{!Drupal_UI_Assets__c.JCode_or_Journal_Name__c}"/><p/>
 
  <b>Copy Drupal UI Asset Delivery Spreadsheet from the following journal </b><p/>
  Enter entries only for differences between two journals. Please use jcode for Highwire Journals and Journal Name for new launches<br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.Copy_from_following_journal__c}"/><p/>
  </apex:pageBlock>
  <apex:pageBlock title="Images">
  Please upload images using upload button at the bottom of the page<p/>
  </apex:pageBlock>
  <apex:pageblock title="Fonts">
  <b>Title Fonts</b><p/>
  Default: Georgia, Palantino, Times New Roman, Century Gothic<br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.Title_Fonts__c}"/><p/>
  <b>Menu/Body Text Font</b><p/>
  Default: Arial, Verdana, Gil Sans, Lucida Sans (Used for article body)<br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.Menu_Body_Text_Font__c}"/><p/>
  <b>Font Size</b><p/>
  Leave blank to use Highwire defaults<br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.Font_Size__c}"/><p/>
  <b>Labels Font Size</b><p/>
  Leave blank to use Highwire defaults<br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Labels_Font_Size__c}"/><p/>
  <b>Article Title Font Size</b><p/>
  Leave blank to use Highwire defaults<br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Article_Title_Font_Size__c}"/><p/>
  <b>Body Text Font Size</b><p/>
  Leave blank to use Highwire defaults<br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Body_Text_Font_Size__c}"/><p/>
  </apex:pageblock>
  <apex:pageblock title="Colors">
  <b>Please choose one of the following options:</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Colors__c}"/><p/>
  <b>Primary Site Color</b><p/>
  Needed only if option 2 is selected<br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Primary_Site_Color__c}"/><p/>
   <b>Secondary Site Color</b><p/>
   Needed only if option 2 is selected<br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Secondary_Site_Color__c}"/><p/>
  <b>Navigation Bar Color(1)</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Navigation_Bar_Color_1__c}"/><p/>
  <b>Page Background Color(2)</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Page_Background_Color_2__c}"/><p/>
  <b>Content Background Color(3)</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Content_Background_Color_3__c}"/><p/>
  <b>Button Color(4)</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Button_Color_4__c}"/><p/>
  <b>Tab Background</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Tab_Background__c}"/><p/>
  <b>Tab Text</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Tab_Text__c}"/><p/>
  <b>Tab Active</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Tab_Active__c}"/><p/>
  <b>Carousel Background</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Carousel_Background__c}"/><p/>
  <b>Carousel Text</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Carousel_Text__c}"/><p/>
  <b>Body Text</b><br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Body_Text__c}"/><p/>
  <b>Article Text</b><br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Article_Text__c}"/><p/>
  <b>Citation on Hover</b><br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Citation_on_Hover__c}"/><p/>
  <b>Abstract Popup</b><br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Abstract_Popup__c}"/><p/>
   <b>Article Correction Box</b><br/>
    <apex:inputField value="{!Drupal_UI_Assets__c.Article_Correction_Box__c}"/><p/>
  <b>Header Text</b><br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Header_Text__c}"/><p/>
  <b>Link Text</b><br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Link_Text__c}"/><p/>
  <b>Announcement Box</b><br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Announcement_Box__c}"/><p/>
  </apex:pageblock>
  <apex:pageblock title="Buttons and Icons">
  Default icons are at <apex:outputLink value="http://fortawesome.github.com/Font-Awesome/#icons-new"> http://fortawesome.github.com/Font-Awesome/#icons-new </apex:outputLink><p/>
  <b>Please provide location of custom icons if required</b><br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Location_of_custom_icons_if_required__c}"/><p/>
  </apex:pageblock>
  <apex:pageBlock title="Site Menus">
Please provide menu labels. Note if these are "buttons" or if they have a drop-down. If using drop-drowns, then please list these labels and the page they link to. Submenus are called out with "-" after ">"in the HighWire recommends section. <p/>
Home Content > -Current    -Ahead of Print    -Archive    -Most Read<br/>
Info for >    -Authors    -Reviewers    -Subscribers    -Institutions    -Advertisers    -Patients<br/>
About Us > -About Us -Contact Us -Editorial Board<br/>
More > -Alerts -Advertising -Feedback -Folders -Help<p/>
<b>Menu Labels</b><p/>
Copy template from above and modify if any changes are needed<br/>
  <apex:inputField value="{!Drupal_UI_Assets__c.Menu_Labels__c}"/><p/>
  <b>Display "Other Publication" menu dropdown in Top Level Menu </b><p/>
  Only applicable to sites under umbrellas<br/>
   <apex:inputField value="{!Drupal_UI_Assets__c.Display_Other_Publication_menu__c}"/><p/>
    </apex:pageBlock>
   <apex:pageblock title="Homepage Content Section">
   <b>Select what to display on the Homepage main content section</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Homepage_main_content_section__c}"/>
   Other:<apex:inputField value="{!Drupal_UI_Assets__c.Homepage_maint_content_section_Other__c}"/><p/>
   <b>Select to display on Homepage:</b><p/>
   These items span all columns of the homepage<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Homepage__c}"/>
    Other:<apex:inputField value="{!Drupal_UI_Assets__c.Homepage_Other__c}"/><p/>
   <b>Select which panels you would like to display in the Right column:</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Right_column__c}"/>
   Other:<apex:inputField value="{!Drupal_UI_Assets__c.Right_column_Other__c}"/><p/>
   </apex:pageblock>
   <apex:pageBlock title="Footer Section">
   <b>Display footer section on site?</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Footer_Section_on_site__c}"/><p/>
   <b>How many postscript columns should the footer section contain?</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Postscript_columns__c}"/><p/>
   </apex:pageBlock>
   <apex:pageBlock title="Advertising">
   <b>What pages should have advertisements?</b><p/>
   Please select the option that best fits. If "All Site Pages" is selected, there is no need to make additional selections<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Advertisements__c}"/><p/>
   <b>Who is the advertising provider?</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Advertising_provider__c}"/><p/>
   <b>Select where advertisements should appear:</b><p/>
   Position locations can be seen at <apex:outputLink value="http://jnl-reference.drupal-stage-jnl-web01.highwire.org"> http://jnl-reference.drupal-stage-jnl-web01.highwire.org </apex:outputLink><br/>
    <apex:inputfield value="{!Drupal_UI_Assets__c.Advertisements_should_appear__c}"/><p/>
    <b>Will every site page have the same advertisements and locations?</b><br/>
    <apex:inputfield value="{!Drupal_UI_Assets__c.Advertisements_and_locations__c}"/><p/>
   </apex:pageBlock>
   <apex:pageblock title="Citation">
   HighWire Default Style - <apex:outputLink value="https://na7.salesforce.com/501A0000000gOrG?srPos=0&srKp=501"> https://na7.salesforce.com/501A0000000gOrG </apex:outputLink><p/>
   <b>Select desired citation style:</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Citation_Style__c}"/><p/>
   <b>Please provide custom citation format if needed</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Custom_citation__c}"/><p/>
   </apex:pageblock>
   <apex:pageBlock title="Configurations (JCORE)">
   These items don't need to be delivered with the initial asset document but will be necessary for site building<br/>
   </apex:pageBlock>
   <apex:pageblock title="Social Media">
   Please provide links to Twitter, Facebook, linkedin. etc if you would like them displayed.<p/>
   <b>Where should the Social Media links be displayed?</b><p/>
   Default location is Top Level Menu<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Social_Media_links_displayed__c}"/> Other:<apex:inputfield value="{!Drupal_UI_Assets__c.Social_Media_displayed_Other__c}"/><p/>
   <b>Facebook Link</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Facebook_Link__c}"/><p/>
   <b>Twitter Link</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Twitter_Link__c}"/><p/>
   <b>LinkedIn Link</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.LinkedIn_Link__c}"/><p/>
   <b>Additional Social Media Links</b><p/>
   Please add the Social Media name, image logo locatio and link location on each new line<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Additional_Social_Media_Links__c}"/><p/>
   </apex:pageblock>
   <apex:pageBlock title="Home Page Text Elements">
   <b>Please provide About the Journal Homepage Text</b><p/>
   Recommended length is 500 to 750 characters. (leave blank if not needed)<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.About_the_Journal_Homepage_Text__c}"/><p/>
   <b>Please provide Announcement Homepage Text</b><p/>
   Recommended size is one line of text or 50 to 75 characters. (leave blank if not needed)<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Announcement_Homepage_Text__c}"/><p/>  
   </apex:pageBlock>
   <apex:pageblock title="Article Page Elements">
   <b>Provide preferred DOI format</b><br/>
    <apex:inputfield value="{!Drupal_UI_Assets__c.Preferred_DOI_format__c}"/><p/> 
    <b>Choose which functions to include from the list below</b><br/>
    <apex:inputfield value="{!Drupal_UI_Assets__c.Article_Page_Elements__c}"/><p/>
   <b>Display Social Sharing Widget?</b><p/>
   Displays link to tweet, facebook like, g+1, reddit ect...<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Social_Sharing_Widget__c}"/><p/>
   <b>Display Jump To Article Navigation Links?</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Jump_to_Article_Navigation_Links__c}"/><p/>
   <b>Display Issue Cover in Sidebar?</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Issue_Cover_in_Sidebar__c}"/><p/>
   <b>Article Navigtation Display style</b><p/>
   Floating will display the Jump to link when scrolling down the page<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Article_Navigation_Display_Style__c}"/><p/>
   <b>Display More in this TOC section accordion?</b><p/>
   Accordion expands to display more articles from the same Table of Contents section<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.More_in_this_TOC_section_accordian__c}"/><p/>
   <b>Display More in this Related Articles accordion?</b><p/>
   Accordion expands to display more related articles and links to related articles in Pubmed and Google Scholar<br/>
    <apex:inputfield value="{!Drupal_UI_Assets__c.More_in_this_Related_Articles_accordion__c}"/><p/>
   <b>Display Subject Collections Widget?</b><p/>
   Displays subject collections associated with the article being viewed<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Subject_Collections_Widget__c}"/><p/>
   <b>Display Keywords in Article Body?</b><br/>
    <apex:inputfield value="{!Drupal_UI_Assets__c.Keywords_in_Article_Body__c}"/><p/>
   <b>Display Keywords in Column 2 Widget?</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Keywords_in_Column_2_Widget__c}"/><p/>
   </apex:pageblock>
   <apex:pageBlock title="Table of Contents Page Elements">
   <b>Display popup abstracts on Article listing pages?</b><p/>
   Article listing pages include issue Table of Contents, Published Ahead of Print Page<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Popup_abstracts_on_Article_listing_pages__c}"/><p/>
   <b>Display Jump to Table of Content Sections Navigation Links?</b><p/>
   Displayed by default<br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.Jump_to_TOC_Sections_Navigation_Links__c}"/><p/>
  <b>Display CME links for each article</b><p/>
  CME must be installed<br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.CME_links_for_each_article__c}"/><p/>
  </apex:pageBlock>
  <apex:pageBlock title="Collection Elements">
  <b>Does the site contain Subject Collections?</b><br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.Subject_Collections__c}"/><p/>
  <b>Expand Subject Collections listing by default?</b><p/>
  Default behavior shows listing expanded<br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.Expand_Subject_Collections__c}"/><p/>
  </apex:pageBlock>
  <apex:pageBlock title="Advanced Search Page Elements">
  <b>Please provide content for the Advanced Search snippet</b><p/>
  This text will appear at the top of the Advanced Search page<br/>
  <apex:inputfield value="{!Drupal_UI_Assets__c.Advanced_Search_snippet__c}"/><p/>
  <b>Display Advanced Page link next to Quick Search Box?</b><p/>
  The link will appear below the Quick Search Box<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Advanced_Page_link__c}"/><p/>
  <b>Display help pages for search?</b><br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Help_Pages_for_Search__c}"/><p/>
    </apex:pageBlock>
   <apex:pageblock title="Archive Page Elements">
   <b>Provide preferred format or choose HighWire default.</b><p/>
   i.e. 7th: Vol 94, Issue 21<br/>
   <apex:inputfield value="{!Drupal_UI_Assets__c.Archive_Page_format__c}"/><p/>
   <b>Display cover hide/display option?</b><p/>
   Displays and hides issue covers on Archive listing<br/>
    <apex:inputfield value="{!Drupal_UI_Assets__c.Cover_Hide_Display_option__c}"/><p/>
    <b>Option to Refine Archives Search?</b><br/>
    <apex:inputfield value="{!Drupal_UI_Assets__c.Refine_Archives_Search__c}"/><p/>
   </apex:pageblock>

  
   <apex:commandButton action="{!save}" value="Submit"/>
  </apex:form>


</apex:page>

I have a trigger that creates related cases whenever a case is inserted that meets a certain criteria.   On my contact record, I have a lookup field to a User record.  Every internal User has a Contact record.  When the the related cases are created, the Contact record of the User who triggered the code is inserted automatically into the contact field of the related cases. 

trigger AfterCaseTrigger on Case (after insert, after update) {
    Map<String,Case>newObjLinkMap = new Map<String,Case>();
    Set<ID> scID = new Set<ID>();    
    List<Days_in_Status__c>DaysStatus = new List<Days_in_Status__c>();
    Days_in_Status__c dis = new Days_in_Status__c();
    Set<ID> CIds = new Set <ID>();
    List<Case> relatedCases = new List<Case>();
    sObject s = [SELECT ID FROM CONTACT WHERE user__c =: Userinfo.getUserId()];
    ID myid = s.id;

 I seem to be getting errored out on this line of code when a customer portal user creates a case or when a case is created from a web form. 

sObject s = [SELECT ID FROM CONTACT WHERE user__c =: Userinfo.getUserId()];
    ID myid = s.id;

 The rest of my code fires correctly if it is an internal user creating the case.

for(Case caseObj : Trigger.new){
if(Trigger.isInsert){
 if((caseObj.Type == 'Drupal Site Launch' || caseObj.Type == 'Classic Site Launch') && caseObj.ParentId == NULL){
                Case JDLaunchCase = new Case();
                JDLaunchCase.Subject = caseObj.Subject + ' JD Launch Work';
                JDLaunchCase.RecordTypeId = '012A000000177IL';
                JDLaunchCase.ParentId = caseObj.ID;
                JDLaunchCase.Type = caseObj.Type;
                JDLaunchCase.Request_Type__c = 'Request New Development';
                JDLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                JDLaunchCase.ContactId = myid;
                JDLaunchCase.OwnerId = Userinfo.getUserId();
                relatedCases.add(JDLaunchCase);
                Case ACLaunchCase = new Case();
                ACLaunchCase.Subject = caseObj.Subject + ' AC Launch Work';
                ACLaunchCase.RecordTypeId = '012A000000177IL';
                ACLaunchCase.ParentId = caseObj.Id;
                ACLaunchCase.Type = caseObj.Type;
                ACLaunchCase.Request_Type__c = 'Request New Development';
                ACLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                ACLaunchCase.ContactId = myid;
                ACLaunchCase.OwnerId = Userinfo.getUserId();
                relatedcases.add( ACLaunchCase);
                Case Content = new Case();
                Content.Subject = caseObj.Subject + ' Content processing for launch';
                Content.RecordTypeId = '012A000000177IL';
                Content.ParentId = caseObj.Id;
                Content.Type = caseObj.Type;
                Content.Request_Type__c = 'Request New Development';
                Content.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                Content.ContactId = myid;
                Content.OwnerId = Userinfo.getUserId();
                relatedCases.add(Content);
                Case LaunchQA = new Case();
                LaunchQA.Subject = caseObj.Subject + ' Launch QA';
                LaunchQA.RecordTypeId = '012A000000177IL';
                LaunchQA.ParentId = caseObj.Id;
                LaunchQA.Type = caseObj.Type;
                LaunchQA.Request_Type__c = 'Request New Development';
                LaunchQA.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                LaunchQA.ContactId = myid;
                LaunchQA.OwnerId = Userinfo.getUserId();
                relatedCases.add(LaunchQA);
                Case MobileSupport = new Case();
                MobileSupport.Subject = caseObj.Subject + ' Mobile Support for Launch';
                MobileSupport.RecordTypeId = '012A000000177IL';
                MobileSupport.ParentId = caseObj.Id;
                MobileSupport.Type = caseObj.Type;
                MobileSupport.Request_Type__c = 'Request New Development';
                MobileSupport.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                MobileSupport.ContactId = myid;
                MobileSupport.OwnerId = Userinfo.getUserId();
                relatedCases.add(MobileSupport);                
                
            }
            
            
        }

 Can some one point me in the right direction as to how to structure this logic better?  Thanks

I have code that redirects emails and sets the from address to the original email address. It will take the from address on the email and stick it into the reply to, so when the recipient gets it, it'll be as if it came from the original sender and they can reply back to them.  The code has been working for years but something happened and now it's not working.  Nothing has changed, and I can only suspect that it was due to a Salesforce release.  Does anybody know what I would need to change to get this to work again?  Thanks.

public with sharing class ForwardEmailController {
	public EmailMessage email {get;set;}
	public String forwardTo{get;set;}
	
	public ForwardEmailController(){
		String id = Apexpages.currentPage().getParameters().get('e');
		if (id != null){
			email =[Select id,ParentId,subject,FromName,FromAddress,TextBody,HtmlBody from EmailMessage where id =: id];
		}
	}
	
	public pageReference forward(){
		List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
		String delimiter = ';';
		if (forwardTo!= null && forwardTo!=''){
			if (forwardTo.indexOf(',')!= -1){
				delimiter = ',';
			}
			for (String s : forwardTo.split(delimiter)){
				Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
	            mail.setToAddresses(new String[] {s});
	            mail.setSenderDisplayName(email.FromName);
	            mail.setSubject(email.subject);
	            mail.setReplyTo(email.FromAddress);
	            mail.setPlainTextBody(email.TextBody);
	            mail.setHtmlBody(email.HtmlBody);
	            emailList.add(mail);
			}
			Case c = [Select id,redirected__c from Case where id =: email.ParentId][0];
			c.Redirected__c = true;
			update c;
			Messaging.sendEmail(emailList);
		}
		return new PageReference('/' +email.ParentId);
	}
	
	
}

 

In my Contact object, I have a lookup field to the User table.  Every user has a corresponding contact record.

I have a trigger, that pulls in the Contact ID of the current User and passes that information to the Case Contact field.

 

The trigger works, as I'm able to create cases with this information being populated correctly.  I'm having problems figuring out how to write the test code as the system user wouldn't have a contact or user to match up against.

    sObject s = [SELECT ID FROM CONTACT WHERE user__c =: Userinfo.getUserId()];
    ID myid = s.id;

 

            if((caseObj.Type == 'Drupal Site Launch' || caseObj.Type == 'Classic Site Launch') && caseObj.ParentId == NULL){
                Case JDLaunchCase = new Case();
                JDLaunchCase.Subject = caseObj.Subject + ' JD Launch Work';
                JDLaunchCase.RecordTypeId = '012A000000177IL';
                JDLaunchCase.ParentId = caseObj.ID;
                JDLaunchCase.Type = caseObj.Type;
                JDLaunchCase.Request_Type__c = 'Request New Development';
                JDLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                JDLaunchCase.ContactId = myid;
                relatedCases.add(JDLaunchCase);

 

I have an after insert trigger that creates related cases when a certain type of case is created. 

 

The snippet of code that I'm using to create these related cases are below.  It worked originally, but the more I added to it, eventually I ran into the future calls error.  Is there a better way for me to write out this code?  Any help is appreciated.  Thanks.

//Create related cases for launch cases
            if(caseObj.Type == 'Drupal Site Launch' || caseObj.Type == 'Classic Site Launch'){
                Case JDLaunchCase = new Case();
                JDLaunchCase.Subject = 'JD Launch Work';
                JDLaunchCase.RecordTypeId = '012A000000177IL';
                JDLaunchCase.ParentId = caseObj.ID;
                JDLaunchCase.Type = caseObj.Type;
                JDLaunchCase.Request_Type__c = 'Request New Development';
                JDLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
               relatedCases.add(JDLaunchCase);
                Case ACLaunchCase = new Case();
                ACLaunchCase.Subject = 'AC Launch Work';
                ACLaunchCase.RecordTypeId = '012A000000177IL';
                ACLaunchCase.ParentId = caseObj.Id;
                ACLaunchCase.Type = caseObj.Type;
                ACLaunchCase.Request_Type__c = 'Request New Development';
                ACLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                relatedcases.add( ACLaunchCase);
                Case Content = new Case();
                Content.Subject = 'Content processing for launch';
                Content.RecordTypeId = '012A000000177IL';
                Content.ParentId = caseObj.Id;
                Content.Type = caseObj.Type;
                Content.Request_Type__c = 'Request New Development';
                Content.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                relatedCases.add(Content);
                Case LaunchQA = new Case();
                LaunchQA.Subject = 'Launch QA';
                LaunchQA.RecordTypeId = '012A000000177IL';
                LaunchQA.ParentId = caseObj.Id;
                LaunchQA.Type = caseObj.Type;
                LaunchQA.Request_Type__c = 'Request New Development';
                LaunchQA.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                relatedCases.add(LaunchQA);
                Case MobileSupport = new Case();
                MobileSupport.Subject = 'Mobile Support for Launch';
                MobileSupport.RecordTypeId = '012A000000177IL';
                MobileSupport.ParentId = caseObj.Id;
                MobileSupport.Type = caseObj.Type;
                MobileSupport.Request_Type__c = 'Request New Development';
                MobileSupport.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                relatedCases.add(MobileSupport);                
                }
    if(relatedCases != null && !relatedCases.isEmpty())
        insert relatedCases;

 

 

My code tracks how long a case has been in a certain picklist value.  There is a custom object called "Days In Status" that captures when a picklist is changed and logs in how long it was in that picklist.  I then have a rollup field back to the case to track the total days.  When I run the scenarios in the sandbox org, everything works fine.  When I move the change a picklist, the trigger fires and I get a new record in my custom object.  

 

When I write my test code, It seems as if the trigger is not firing.  Where did I go wrong?

 

Trigger:

trigger AfterCaseTrigger on Case (after insert, after update) {

    List<Days_in_Status__c>DaysStatus = new List<Days_in_Status__c>();
    Days_in_Status__c dis = new Days_in_Status__c();
    for(Case caseObj : Trigger.new){
        
            //Days in Stage code
            if(checkRecursive.runOnce()){
                if(oldCase.Major_Project_Status_Indicator__c == 'Orange' && caseObj.Major_Project_Status_Indicator__c != 'Orange' ){
                    
                    //get the number of days between today and the date the start date orange was
                    dis.Status__c = 'Orange';
                    if(caseObj.Date_to_Orange__c != null){
                        dis.Days_in_Status__c = caseObj.Date_to_Orange__c.daysBetween(system.today());}
                    dis.Case__c = caseObj.ID;
                    
                    //insert those days
                    DaysStatus.add(dis);
                }
                if(oldCase.Major_Project_Status_Indicator__c == 'Red' && caseObj.Major_Project_Status_Indicator__c != 'Red' ){
                    
                    //get the number of days between today and the date the start date red was
                    dis.Status__c = 'Red';
                    if(caseObj.Date_to_Red__c != null){
                        dis.Days_in_Status__c = caseObj.Date_to_Red__c.daysBetween(system.today());}
                    dis.Case__c = caseObj.ID;
                    
                    //insert those days
                    DaysStatus.add(dis);
                }
                if(oldCase.Internal_Dev_Status__c == 'PxM Review' && caseObj.Internal_Dev_Status__c != 'PxM Review' ){
                    
                    //get the number of days between today and the date the start date PxM Review was
                    dis.Status__c = 'PxM Review';
                    if(caseObj.Date_to_PxM_Review__c != null){
                        dis.Days_in_Status__c = caseObj.Date_to_PxM_Review__c.daysBetween(system.today());}
                    dis.Case__c = caseObj.ID;
                    
                    //insert those days
                    DaysStatus.add(dis);
                }
            }
 
    
    if(DaysStatus.isEmpty()==false){
        insert DaysStatus;}
    
    
    
    
}

 Recursive class:

public Class checkRecursive{
    private static boolean run = true;
    public static boolean runOnce(){
    if(run){
	 run=false;
	 return true;
    }else{
        return run;
    }
    }
}

 Test Class:

@isTest
private class CaseTriggerTestClass {
    static testMethod void runTest()
    {
        test.starttest();

        Case case1 = new Case();
        case1.Major_Project_Status_Indicator__c = 'Orange'; 
        case1.Internal_Dev_Status__c = 'Open';
        insert case1;
        System.debug('Date to Orange1:' + case1.Date_to_Orange__c);
        case1.Date_to_Orange__c = date.newInstance(2013,1,1);
        case1.Major_Project_Status_Indicator__c = 'Red';
        case1.Internal_Dev_Status__c = 'PxM Review';
        update case1;
        System.debug('Date to Orange2: ' + case1.Date_to_Orange__c);
        System.debug('Days in orange: ' + case1.Days_in_Orange__c);
		System.debug('Major Project Status Indicator: ' + case1.Major_Project_Status_Indicator__c);
      
        
        List<Days_in_Status__c> ds = new List<Days_in_Status__c>();
        
        test.stoptest();
        
        ds = [SELECT Name, Case__c, Days_in_Status__c, Status__c FROM Days_in_Status__c];
		system.debug('Size of List: ' + ds.size());
        
        }
       
    
}

 

From my debug logs, I can see that the Major Project Status Indicator did move to Red on the update.  That should have fired the trigger.  But size of my list comes back at 0.

Any help is greatly appreciated.  Thanks.

I have a project application that has milestones and tasks.  Milestones can have multiple tasks.  On Milestones, there can be a lookup to another milestone, which also has it's own tasks.

My trigger updates all the dates of the tasks and the related milestone when the original milestone's date changes.  The problem I'm running into is that when the trigger updates the related milestone, that then runs the trigger again, since it's and update to milestone.

The code works if i'm updating a milestone with only 2 levels of related milestones, but once I get to something higher, I run into soql limits.  Is there a more efficient way for me to write this trigger?

 

trigger MilestoneTrigger on MPM4_BASE__Milestone1_Milestone__c (after update) {
    Integer DaysToAdd;
    
    //get ID of Milestones
    Set<ID> msid = new Set<ID>();
    for(MPM4_BASE__Milestone1_Milestone__c ms: trigger.new){
        msid.add(ms.id);
        //if kickoff date is changed then do code
        //calculate the day difference of old and new date    
        MPM4_BASE__Milestone1_Milestone__c oldms = Trigger.oldMap.get(ms.Id);
        DaysToAdd = oldms.MPM4_BASE__Kickoff__c.daysBetween(ms.MPM4_BASE__Kickoff__c);
    }
    
    //get list of all tasks in milestone
    List<MPM4_BASE__Milestone1_Task__c> tasks = [SELECT Id, MPM4_BASE__Due_Date__c,MPM4_BASE__Start_Date__c FROM MPM4_BASE__Milestone1_Task__c WHERE MPM4_BASE__Project_Milestone__c IN: msid];
    //get list of all child milestones
    List<MPM4_BASE__Milestone1_Milestone__c> cmilestone = [SELECT Id, MPM4_BASE__Deadline__c, MPM4_BASE__Kickoff__c FROM MPM4_BASE__Milestone1_Milestone__c WHERE MPM4_BASE__Predecessor_Milestone__c IN: msid ];  
    
    
    
    List<MPM4_BASE__Milestone1_Task__c> updateTask = new List<MPM4_BASE__Milestone1_Task__c>();
    List<MPM4_BASE__Milestone1_Milestone__c> updateCMilestone = new List<MPM4_BASE__Milestone1_Milestone__c>();
    
    
    //add those dates to all tasks
    for(MPM4_BASE__Milestone1_Task__c t : tasks){
        t.MPM4_BASE__Due_Date__c += DaysToAdd;
        t.MPM4_BASE__Start_Date__c += DaysToAdd;
        updateTask.add(t);
    }
    if(updateTask.isEmpty()==false){
        update updateTask;}
    
    // add those dates to child milestones dates
    for(MPM4_BASE__Milestone1_Milestone__c m : cmilestone){
        m.MPM4_BASE__Deadline__c += DaysToAdd;
        m.MPM4_BASE__Kickoff__c += DaysToAdd;
        updateCMileStone.add(m);
    }  
    if(updateCMilestone.isEmpty()==false){
        update updateCMilestone;}
    
}

 

I have a custom button that pops up a VF in another window.  I want to be able to click save, close the pop up, and refresh the parent page.  The code looks correct, but it doesn't close the pop up window, but instead just refreshes in the pop up window.  I have turned off development on my profile and that doesn't seem to fix the problem.

 

<apex:page standardController="Opportunity" sidebar="false" showheader="false">
    <script language="JavaScript" type="text/javascript">
    function CloseAndRefresh(){
        window.opener.location.href="/{!$CurrentPage.parameters.id}";
        window.top.close();
        
    }
    </script>
    
    <apex:form >
        <apex:pageblock >
            <apex:pageBlockSection >
                
                <apex:inputfield value="{!opportunity.Titles__c}"/>
                <apex:inputfield value="{!opportunity.stagename}"/>
                <apex:commandbutton action="{!save}" value="Save" oncomplete="javascript&colon;CloseAndRefresh()"/>
                
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
    
</apex:page>
               

 

 

Hello,

 

I'm fairly new to writing apex. I've written the following code to update the status of the case to match that of another dropdown(JIRA_Status2__c) on the case.  This trigger should only fire when JIRA_Status2__c changes and if the recordtype matches.

 

The code works, but I would like to know if I've written too much to achieve such a basic update.  Thanks for the input in advance. It wil help me to learn how to code better in the future.

trigger UpdateJiraOnlyRT on Case (after update) {

    //create list of case IDs
    List<ID>cid = new List<ID>();
   
    
    
    //add cases to list for only cases that has JIRA Status2 dropdown changed AND recordtype=012A00000017NFl

    for (Case c: Trigger.new){
        Case oldCase = Trigger.oldMap.get(c.Id);
        if((oldCase.JIRA_Status2__c != c.JIRA_Status2__c) && (c.RecordTypeID=='012A00000017NFl')){
            cid.add(c.ID);}
    }
  
   //update the list  
    List<Case>updatecase =[SELECT Id, Status, JIRA_Status2__c from Case WHERE Id IN:cid];
    for(Case c2:updatecase){
        c2.Status = c2.JIRA_Status2__c;
    }
    
    update updatecase;
        
}

 

 

On opportunity, I have a lookup to case.  Whenever a case is moved to status 'Cancelled/declined', I want the opportunity stage to go to "Closed-Lost".  I have written a trigger below, but it doesn't seem to be working.  Any help would be greatly appreciated.

 

trigger ClosedLostOpp2 on Case (after update) {
    //create list of case IDs
    List<ID> cid = New List<ID>();
    //find cases to add to list
    for(Case c: Trigger.new){
        if(c.Status == 'Cancelled/declined'){
            cid.add(c.Id);
        }
       
             
             
             
     List<Opportunity> OppUpdateList = [SELECT Id, StageName from Opportunity WHERE ID in:cid];
        List<Opportunity> opp = new List<Opportunity>();
        for (Opportunity oppsupd : oppUpdateList)
        {
            oppsupd.StageName = 'Closed-Lost';
            opp.add(oppsupd);
        }
        update opp;
        
            

}
}

 

We have implemented the Public Knowledge Base from appexchange.  VF page isn't one of our strong suits. We were able to change the header logo and footer logo to our company logo, but is there a way to change the Contact Us link to something else or remove it all together?
I have a simple visualforce form that's asking a couple of questions.  I would like for this form to be launched from the Case object and have the Case number passed to visualforce page.

The custom fields of this visualforce page is using fields on another custom object.  I thought maybe I could have just created a custom button to launch the visualforce page, but the since the page was used using a custom object, it's not showing up when creating the custom button on the case object.

Any help would be greatly appreciated.  Thanks.
I'm trying to set up some test code to insert 200 products.  When I run the test code, I get an error stating: List has no rows for assignment.  This is occuring on the code for:
Pricebook2 pbook = [Select id from Pricebook2 where isStandard = true];

The weird thing is, I copied and pasted the exact same code to execute anonymous and it ran fine, but running it through test coverage errors out.  Am I missing something here?
@isTest

public class AfterOppTriggerTest {
    static testMethod void OppTest(){
        //create a list of products       
        List<Product2> productstoinsert = new List <Product2>();
        for(Integer x = 0; x < 200 ;x++){
            Product2 newprod = new Product2(Name = 'newprod' + x, isactive = true);
            productstoinsert.add(newprod);
          
        }
        insert productstoinsert;
        //Select the pricebook
        Pricebook2 pbook = [Select id from Pricebook2 where isStandard = true];
        system.debug(pbook);
        
        //create pricebook entries
        List<PriceBookEntry> pbinsert = new List<PriceBookEntry>();
        for(Integer x=0; x < 200; x++){
            PriceBookEntry pbentry = new PricebookEntry(Pricebook2ID = pbook.Id, Product2ID = productstoinsert[x].id, unitprice = 100, isactive = true, usestandardprice = false);
            pbinsert.add(pbentry);
            system.debug(pbentry);
        }
        insert pbinsert;
        
        
    }
}


I have code that redirects emails and sets the from address to the original email address. It will take the from address on the email and stick it into the reply to, so when the recipient gets it, it'll be as if it came from the original sender and they can reply back to them.  The code has been working for years but something happened and now it's not working.  Nothing has changed, and I can only suspect that it was due to a Salesforce release.  Does anybody know what I would need to change to get this to work again?  Thanks.

public with sharing class ForwardEmailController {
	public EmailMessage email {get;set;}
	public String forwardTo{get;set;}
	
	public ForwardEmailController(){
		String id = Apexpages.currentPage().getParameters().get('e');
		if (id != null){
			email =[Select id,ParentId,subject,FromName,FromAddress,TextBody,HtmlBody from EmailMessage where id =: id];
		}
	}
	
	public pageReference forward(){
		List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
		String delimiter = ';';
		if (forwardTo!= null && forwardTo!=''){
			if (forwardTo.indexOf(',')!= -1){
				delimiter = ',';
			}
			for (String s : forwardTo.split(delimiter)){
				Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
	            mail.setToAddresses(new String[] {s});
	            mail.setSenderDisplayName(email.FromName);
	            mail.setSubject(email.subject);
	            mail.setReplyTo(email.FromAddress);
	            mail.setPlainTextBody(email.TextBody);
	            mail.setHtmlBody(email.HtmlBody);
	            emailList.add(mail);
			}
			Case c = [Select id,redirected__c from Case where id =: email.ParentId][0];
			c.Redirected__c = true;
			update c;
			Messaging.sendEmail(emailList);
		}
		return new PageReference('/' +email.ParentId);
	}
	
	
}

 

I have an after insert trigger that creates related cases when a certain type of case is created. 

 

The snippet of code that I'm using to create these related cases are below.  It worked originally, but the more I added to it, eventually I ran into the future calls error.  Is there a better way for me to write out this code?  Any help is appreciated.  Thanks.

//Create related cases for launch cases
            if(caseObj.Type == 'Drupal Site Launch' || caseObj.Type == 'Classic Site Launch'){
                Case JDLaunchCase = new Case();
                JDLaunchCase.Subject = 'JD Launch Work';
                JDLaunchCase.RecordTypeId = '012A000000177IL';
                JDLaunchCase.ParentId = caseObj.ID;
                JDLaunchCase.Type = caseObj.Type;
                JDLaunchCase.Request_Type__c = 'Request New Development';
                JDLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
               relatedCases.add(JDLaunchCase);
                Case ACLaunchCase = new Case();
                ACLaunchCase.Subject = 'AC Launch Work';
                ACLaunchCase.RecordTypeId = '012A000000177IL';
                ACLaunchCase.ParentId = caseObj.Id;
                ACLaunchCase.Type = caseObj.Type;
                ACLaunchCase.Request_Type__c = 'Request New Development';
                ACLaunchCase.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                relatedcases.add( ACLaunchCase);
                Case Content = new Case();
                Content.Subject = 'Content processing for launch';
                Content.RecordTypeId = '012A000000177IL';
                Content.ParentId = caseObj.Id;
                Content.Type = caseObj.Type;
                Content.Request_Type__c = 'Request New Development';
                Content.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                relatedCases.add(Content);
                Case LaunchQA = new Case();
                LaunchQA.Subject = 'Launch QA';
                LaunchQA.RecordTypeId = '012A000000177IL';
                LaunchQA.ParentId = caseObj.Id;
                LaunchQA.Type = caseObj.Type;
                LaunchQA.Request_Type__c = 'Request New Development';
                LaunchQA.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                relatedCases.add(LaunchQA);
                Case MobileSupport = new Case();
                MobileSupport.Subject = 'Mobile Support for Launch';
                MobileSupport.RecordTypeId = '012A000000177IL';
                MobileSupport.ParentId = caseObj.Id;
                MobileSupport.Type = caseObj.Type;
                MobileSupport.Request_Type__c = 'Request New Development';
                MobileSupport.Requested_Deliver_Date__c = caseObj.Estimated_Launch_Date__c;
                relatedCases.add(MobileSupport);                
                }
    if(relatedCases != null && !relatedCases.isEmpty())
        insert relatedCases;

 

 

I have a trigger that does multiple processes on the case object.  I seem to be hitting my soql limits on this trigger.  Could someone point me in the right direction of where I might be looping too many statements?  Much appreciated.

trigger BeforeCaseInsert on Case (before insert,before update)
{
    List<String> RecordTypeNameList = new List<String>();
    RecordTypeNameList.add('CR');
    RecordTypeNameList.add('Prod Specialist');
    RecordTypeNameList.add('BenchPress');
    RecordTypeNameList.add('Support');
    
    
    List<RecordType> RecordTypeResult = [SELECT id,Name FROM RecordType WHERE name in: RecordTypeNameList];
    
    Map<String,Id> RecordTypeNameIDMap = new Map<String,Id>();
    
    for(RecordType rt : RecordTypeResult)
    {
        RecordTypeNameIDMap.put(rt.Name,rt.id);
    }
    
 
    private List <Sites__c> sitesF;
    List<Spec_History__c> SpecList = new List<Spec_History__c>();
    
   
    sitesF = new List<Sites__c>([SELECT id, Name, Feedback__c, Account__c, Account__r.Publication_Manager2__c
                                 FROM Sites__c LIMIT 50000]);
    
    
    
    //Create lists for the case team member code
    List<CaseTeamMember> ctm = new List<CaseTeamMember>();
    List<CaseTeamMember> ctmdelete = new List<CaseTeamMember>();
    List<CaseTeamRole>ctrole = [SELECT Name, Id FROM CaseTeamRole];
    Map<String,String>caseteamr = new Map<String,String>{};
        for(CaseTeamRole ct:ctrole){
            caseteamr.put(ct.Name, ct.Id);}
    
    //Create Set of Case Ids where status is Closed
    Set<ID>cid= new Set<ID>();
    
    
    for (Case c : trigger.new) {
        
        if (c.Description != null
            && c.Description != ''
            && c.recordTypeID == RecordTypeNameIDMap.get('Support'))
        {
            for(Sites__c s : sitesF) {
                if(c.Description.contains(s.Feedback__c) && s.Feedback__c != null){
                    c.sites__c = s.id;
                    c.accountId = s.account__c;

                    break;}
            }
        }
        
        if (c.recordTypeId == RecordTypeNameIDMap.get('Prod Specialist')
            && c.JCode__c != null
            && c.JCode__c != ''
           ) {
               for(Sites__c s : sitesF) {
                   if (c.JCode__c == s.Name){
                       c.accountId = s.account__c;
                       c.Sites__c = s.id;
                       break;
                   }
               }
               
           }
        
        // Spec History Code
        if (Trigger.isUpdate) {
            if (c.recordTypeId == RecordTypeNameIDMap.get('CR'))      
            {
                Case oldCase = Trigger.oldMap.get(c.ID);
                if (c.Spec_Image__c != oldCase.Spec_Image__c || c.Spec_pages__c != oldCase.Spec_Pages__c || c.Jcode__c != oldCase.JCode__c || c.Spec_description__c != oldCase.Spec_description__c || c.Configuration_Details__c != oldCase.Configuration_Details__c ) {
                    Spec_History__c newspec = new Spec_History__c ();
                    if (c.Spec_Image__c != oldCase.Spec_Image__c) {
                        newspec.Spec_Image_History__c = oldCase.Spec_Image__c;
                    }
                    if (c.Spec_pages__c != oldCase.Spec_Pages__c){
                        newspec.Spec_pages__c = oldCase.Spec_Pages__c;
                    }
                    if (c.Jcode__c != oldCase.JCode__c){
                        newspec.Spec_Jcode__c = oldCase.JCode__c;
                    }
                    if (c.Spec_description__c != oldCase.Spec_description__c){
                        newspec.Spec_description__c = oldCase.Spec_description__c;
                    }
                    if (c.Configuration_Details__c != oldCase.Configuration_Details__c){
                        newspec.Spec_Config_Details__c = oldCase.Configuration_Details__c;
                    }
                    newspec.Case__c = c.ID;
                    SpecList.add(newspec);
                }
                
            }
        }
        
        if (c.recordTypeId == RecordTypeNameIDMap.get('BenchPress'))
        {
            for(Sites__c s : sitesF) {
                
                if (c.Journal_Code__c == s.id){
                    c.Sites__c = s.id;
                    c.accountId = s.account__c;
                    
                    //         accMap.put(s.account__c,s.Account__r);
                    break;
                }
            }
        }
        
        /**
Following code used to insert case team members using the case manager field
**/
        // Get the id of the old case
        if (Trigger.isUpdate) {
            Case oldCase = Trigger.oldMap.get(c.Id);
            //Delete old case manager from case team
            if(oldCase.Case_Manager__c != null || oldCase.Case_Manager__c == null){
                for(CaseTeamMember ctmrem : [SELECT Id FROM CaseTeamMember WHERE MemberID =: c.Case_Manager__c OR MemberID =: oldCase.Case_Manager__c]){
                    
                    ctmdelete.add(ctmrem);}
            }
            // If the old case manager doesn't equal the new case manager
            if(oldCase.Case_Manager__c != c.Case_Manager__c &&	 c.Case_Manager__c != null){
                
                // Create a list of the members in the case team
                
                // For each of the case managers in ctmlist
                
                
                CaseTeamMember ctmadd = new CaseTeamMember();
                ctmadd.ParentId = c.id;
                ctmadd.MemberId = c.Case_Manager__c;
                ctmadd.TeamRoleId = caseteamr.get('Case Manager');
                
                
                // Add the case manager to the list ctm
                ctm.add(ctmadd);
                
            }  
        }

//add to list of only cases that have been cancelled/declined
        if(c.Status=='Cancelled/declined'){
            cid.add(c.id);}
    }
    if(SpecList.isEmpty()==false){
        insert SpecList;    }
    if(ctmdelete.isEmpty()==false){
        delete ctmdelete;}        
    if(ctm.isEmpty() == false){
        insert ctm;}
    
    List < Opportunity > OppUpdateList = [SELECT Id, StageName from Opportunity WHERE Case__c in : cid AND StageName <> 'Closed - Lost'];
    
    //Set those Opportunities to Closed - Lost
    for (Opportunity oppsupd: oppUpdateList) {
        oppsupd.StageName = 'Closed - Lost';
    }
    update oppUpdateList;
    
}

 

Hello,

 

I'm fairly new to writing apex. I've written the following code to update the status of the case to match that of another dropdown(JIRA_Status2__c) on the case.  This trigger should only fire when JIRA_Status2__c changes and if the recordtype matches.

 

The code works, but I would like to know if I've written too much to achieve such a basic update.  Thanks for the input in advance. It wil help me to learn how to code better in the future.

trigger UpdateJiraOnlyRT on Case (after update) {

    //create list of case IDs
    List<ID>cid = new List<ID>();
   
    
    
    //add cases to list for only cases that has JIRA Status2 dropdown changed AND recordtype=012A00000017NFl

    for (Case c: Trigger.new){
        Case oldCase = Trigger.oldMap.get(c.Id);
        if((oldCase.JIRA_Status2__c != c.JIRA_Status2__c) && (c.RecordTypeID=='012A00000017NFl')){
            cid.add(c.ID);}
    }
  
   //update the list  
    List<Case>updatecase =[SELECT Id, Status, JIRA_Status2__c from Case WHERE Id IN:cid];
    for(Case c2:updatecase){
        c2.Status = c2.JIRA_Status2__c;
    }
    
    update updatecase;
        
}

 

 

On opportunity, I have a lookup to case.  Whenever a case is moved to status 'Cancelled/declined', I want the opportunity stage to go to "Closed-Lost".  I have written a trigger below, but it doesn't seem to be working.  Any help would be greatly appreciated.

 

trigger ClosedLostOpp2 on Case (after update) {
    //create list of case IDs
    List<ID> cid = New List<ID>();
    //find cases to add to list
    for(Case c: Trigger.new){
        if(c.Status == 'Cancelled/declined'){
            cid.add(c.Id);
        }
       
             
             
             
     List<Opportunity> OppUpdateList = [SELECT Id, StageName from Opportunity WHERE ID in:cid];
        List<Opportunity> opp = new List<Opportunity>();
        for (Opportunity oppsupd : oppUpdateList)
        {
            oppsupd.StageName = 'Closed-Lost';
            opp.add(oppsupd);
        }
        update opp;
        
            

}
}