• Glen.ax1034
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 38
    Questions
  • 89
    Replies

I cannot figure out for the life of me why I am getting the CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Glen_Task_Chatter: execution AfterInsert error

 

test code:

public with sharing class test_Glen_Task_Chatter {

    /*
    *    Test the ChatterActivity trigger which inserts chatter feed posts whenever a task is inserted on the parent object
    */
    public static testMethod void testChatterActivity() {
        //create the test account
        
        User u1 = [select id from User where alias='gbrad'];
        
//Run As U1  
    
        System.RunAs(u1){
        
        Account a = new Account(name='Test Account', Type='Law Firm', Industry='Agriculture', BillingCity='Indianapolis', BillingCountry='USA');
        insert a;
        
        Contact c = new Contact(LastName='Test Account', AccountId=a.id, Title='test', Email='g@g.com', LeadSource='Adwords');
        insert c;

        //create a task on that account
        Task t = new Task(Subject='Subject', Contact_Outreach__c='Log A Phone Meeting',WhoId=c.Id,WhatId=a.id,Ownerid=u1.id);
        insert t;
        
        //Event e = new Event (Subject='Subject', Related_Services__c='Consulting', DurationInMinutes=30, ActivityDateTime=datetime.now());
        //insert e;
        
        }
    }
}

 

Actual Trigger:

trigger Glen_Task_Chatter on Task (after insert, after update) {

    if(UserInfo.getName()!='Eloqua Marketing'){
    
        List<FeedItem> feedItems = new List<FeedItem>();
    //We want to show the User name as assignedTo. The only way to get to that is by querying the user table.
        Set<ID> ownerIds = new Set<ID>();
        
        for (Task t : Trigger.new) {
            ownerIds.add(t.ownerId);
        }
        Map<ID,User> userMap = new Map<ID,User>([SELECT ID, Name FROM User WHERE ID IN :ownerIds]); //This is our user map
    
    
    
        for (Task c: Trigger.new) {
                
                    FeedItem fitem = new FeedItem();
                    fitem.type = 'LinkPost';
            		if (c.Accountid != null)
                    	fitem.ParentId = c.Accountid;
                    fitem.LinkUrl = '/' + c.id; //This is the url to take the user to the activity
                    fitem.Title = 'View';  //This is the title that displays for the LinkUrl
        
                    //Get the user by checking the userMap we created earlier
                    User assignedTo = userMap.get(c.ownerId);
        
                    fitem.Body = ((Trigger.isInsert) ? 'New' : 'Updated') + ' Task - ' + c.Subject +': ' + c.Contact_Outreach__c + '\n  ' + c.Description.substring(0,50); //+ c.Who.Name;
                    
                    if (c.AccountId !=null)
                        feedItems.add(fitem);
                
        //}
    
    
        //Save the FeedItems all at once.
        if (feedItems.size() > 0) {
            Database.insert(feedItems,false); //notice the false value. This will allow some to fail if Chatter isn't available on that object
        }
    
    
        
    
        }
        
        
        
        
        
    }

    
    
    
}

 

i wrote some apex code and am trying to remove fliptopsocialprofiles from the chatter feed manually since they go in every night and release chatter updates across all of our contacts now...

 

what is the best way to detect if it is this user and avoid running the triggers that manage my chatter feeds? apparently getuserid isn't working. note that they are outside our org since this is a managed package.

 

Hi, I want to call a nightly batch update process on all of the opportunities in the pipeline (certain criteria).

 

right now, I am logging in nightly and running a report and clicking all of the opportunities one at a time and clicking "edit" and then "save" and that's ridiculous. how do i automate this?

 

global class BatchUpdateForecast implements Database.Batchable<sObject>{

   global final String Query;
   global final String Entity;
   global final String Field;
   global final String Value;

   global BatchUpdateForecast (String q, String e, String f, String v){

      Query=q; Entity=e; Field=f;Value=v;
   }

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
     //for(sobject s : scope){
     //s.put(Field,Value); 
     //}
     update scope;
    }

   global void finish(Database.BatchableContext BC){
   }
}

 

global class batchitupson_schedule implements Schedulable {
global void execute(SchedulableContext scMain) {
BatchUpdateForecast clsBatchItUpSon = new BatchUpdateForecast('Select Id, Name FROM Opportunity','Opportunity','Source_Name__c','Gwins');
ID idBatch = Database.executeBatch(clsBatchItUpSon, 100);
}
}

 

I have apex code that populates fields, and I want to run the "before update" on all opportunities once a week to make sure that these fields that are populated are current.

I've created the scheduled batch apex in classes and have set it to schedule and run, and it's running but it isn't running the "before update" on all of my opportunities.

 

here's my scheduler:

global class batchitupson_schedule implements Schedulable {
global void execute(SchedulableContext scMain) {
BatchUpdateForecast clsBatchItUpSon = new BatchUpdateForecast('Select Id, Name FROM Opportunity','Opportunity','Source_Name__c','Gwins');
ID idBatch = Database.executeBatch(clsBatchItUpSon, 100);
}
}

 

and here is my Scheduled class that is batchable, as you can tell, all i want it to do is open all the opportunities and update them, much like if you were to click through them manually and click "Edit" then click "Save" which then runs my "before update" code for the opportunity

 

global class BatchUpdateForecast implements Database.Batchable<sObject>{

   global final String Query;
   global final String Entity;
   global final String Field;
   global final String Value;

   global BatchUpdateForecast (String q, String e, String f, String v){

      Query=q; Entity=e; Field=f;Value=v;
   }

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
     //for(sobject s : scope){
     //s.put(Field,Value); 
     //}
     update scope;
    }

   global void finish(Database.BatchableContext BC){
   }
}

 

I tried to create a workflow that changes the Opportunity Field: Stage to 'Deferred' if the opportunity is 180+ days old and the probability is >=5% and <=95%.... and it isn't updating the field Stage to 'Deferred'. This opportunity is 183 days old.

 

AND(ROUND((NOW() - CreatedDate),0)>180,Probability>5,Probability<=95)

 

http://i.imgur.com/9qChA.png

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger EscalateCase caused an unexpected exception, contact your administrator: EscalateCase: execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.EscalateCase: line 76, column 1

 

It is erroring on line:

List<Case> cCaseTypes = [SELECT Status, Id FROM Case where Status='Escalation Hold' AND ParentId =:escalatedcase.id LIMIT 10];


 

trigger EscalateCase on Case (before update, before insert) {
//MAP record type ID's to record type names.
        List<RecordType> rTypes = [select id,name from RecordType where SobjectType='Case'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
           
        MAP<Id , String> maprtID_rtName = new MAP<ID , String>();  //map record type ID's to record type names.
        for(RecordType rTypeObj :  rTypes)
        {
            maprtID_rtName.put(rTypeObj.id , rTypeObj.Name); //for all recordtypes... log id's and record type names.
        }
//MAP Record type names to record type ID's
        List<RecordType> rTypesCases = [select name,id from RecordType where SobjectType='Case'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
        
        MAP<String, ID> maprtName_rtIDCases = new MAP<String, ID>();  //map record type ID's to record type names.
        for(RecordType rTypeObj :  rTypesCases)
        {
            maprtName_rtIDCases.put(rTypeObj.Name, rTypeObj.id); //for all recordtypes... log id's and record type names.
        }
        
//MAP Case User Owner/Queue Names to reference ID's
        List<User> uTypesUsers = [select name,id from User];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
        
        MAP<String, ID> maprtName_rtIDUsers = new MAP<String, ID>();  //map record type ID's to record type names.
        for(User uTypeObj :  uTypesUsers)
        {
            maprtName_rtIDUsers.put(uTypeObj.Name, uTypeObj.id); //for all recordtypes... log id's and record type names.
        }
        
//MAP Case Group Owner/Queue Names to reference ID's
        List<Group> gTypesGroups = [select name,id from Group where Type='Queue'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
        
        MAP<String, ID> maprtName_rtIDGroups = new MAP<String, ID>();  //map record type ID's to record type names.
        for(Group gTypeObj :  gTypesGroups)
        {
            maprtName_rtIDGroups.put(gTypeObj.Name, gTypeObj.id); //for all recordtypes... log id's and record type names.
        }
    
////map for temporary return from escalation
    
    

//bulk cases for upsert
      List<Case> Cases = new List<Case>();
      List<CaseComment> ccomments = new List<CaseComment>();
      List<CaseComment> dcomments = new List<CaseComment>();
      List<CaseComment> pcomments = new List<CaseComment>();
      boolean escalated = false;
      boolean bccomments = false;
      boolean bdcomments = false;
      boolean bpcomments = false;
      MAP<ID, ID> mapescalate_add = new MAP<ID, ID>();

//lets have a look at all the trigger(s)
for (Case escalatedcase:Trigger.new){

escalated = false;    
    
//trying to close the parent case while children are still open   
      if (escalatedcase.Status=='Closed') { //trying to close the parent case while children are still open
            integer close = [Select count() from Case where ParentId = :escalatedcase.id and isClosed != true];
            if (close > 0) {
                  escalatedcase.addError('There are still Child Cases Open - Please close and try again!'); //in your face!
            }
      }
//END trying to close the parent case while children are still open


      if(maprtID_rtName.get(escalatedcase.RecordTypeId) == 'National Client Service') {
            
                  if(escalatedcase.ParentId == null) {
                      
                        if(escalatedcase.Status != 'Escalated' && escalatedcase.Status != 'Returned from Escalation' && escalatedcase.Status != 'Closed') {
                              //if any escalatedcase childcase has a status 'Escalation Hold' then pass the comments back to that case and put this case on status escalated and put that status as new
                              // then if not, proceed with the escalation group stuff
                            
                            //List<Case> cCaseTypes = [SELECT Status, Id FROM Case where ParentId =:escalatedcase.id LIMIT 10];
                            List<Case> cCaseTypes = [SELECT Status, Id FROM Case where Status='Escalation Hold' AND ParentId =:escalatedcase.id LIMIT 10];
                            for(Case eCase : cCaseTypes) {
                                If (eCase.Status == 'Escalation Hold') {
                                                
                                      Case CaseAdd = new Case(Id = eCase.id);
                                      CaseAdd.Status = 'New';
                                      CaseAdd.Escalation_Completion_Date__c = System.now();
                                      Cases.add(CaseAdd);
                                    
                                    
                                            List<CaseComment> comments = [Select c.Id, c.ParentId, c.IsPublished, c.CommentBody, c.CreatedById, c.CreatedDate, c.SystemModstamp, c.LastModifiedDate, c.LastModifiedById, c.IsDeleted from CaseComment c where c.ParentId = :escalatedcase.Id];
            
                                            for(CaseComment oldcomment :  comments) {
                                                CaseComment newcomment = new CaseComment();
                                                dcomments.add(oldcomment);
                                                bdcomments = true;
                                                newcomment.ParentId = escalatedcase.ParentId;
                                                newcomment.IsPublished = oldcomment.IsPublished;
                                                newcomment.CommentBody = oldcomment.CommentBody + escalatedcase.OwnerId + escalatedcase.Owner.Name;
                                                //Do I want to remove duplicates?
                                                //if (newcomment.CommentBody.substring(0,6) == 'Parent') { } else {
                                                    pcomments.add(newcomment);  
                                                    bpcomments = true;
                                                //}
                                            }
             
                                        
                                        
                                        escalated = true;
                                }
                            }
                            
                            

 


trigger ActivateContract on Contract (before update) {
  List<RecordType> rTypes = [select id,name from RecordType where SobjectType='Contract'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
 
  MAP<Id , String> maprtID_rtName = new MAP<ID , String>();  //map record type ID's to record type names.
  for(RecordType rTypeObj :  rTypes)
  {
  	maprtID_rtName.put(rTypeObj.id , rTypeObj.Name); //for all recordtypes... log id's and record type names.
  }

  List<Group> gTypes = [SELECT Id, name FROM Group where Type = 'Queue'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
 
  MAP<String , Id> mapgName_gID = new MAP<String , Id>();  //map record type ID's to record type names.
  for(Group gTypeObj :  gTypes)
  {
  	mapgName_gID.put(gTypeObj.Name, gTypeObj.id); //for all recordtypes... log id's and record type names.
  }
  
  List<RecordType> rTypesCases = [select name,id from RecordType where SobjectType='Case'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
  
  MAP<String, ID> maprtName_rtIDCases = new MAP<String, ID>();  //map record type ID's to record type names.
  for(RecordType rTypeObj :  rTypesCases)
  {
  	maprtName_rtIDCases.put(rTypeObj.Name, rTypeObj.id); //for all recordtypes... log id's and record type names.
  }
    
  List<User> rUserManager = [select id,ManagerId from User];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
  
  MAP<ID, ID> maprtid_rtManagerId = new MAP<ID, ID>();  //map record type ID's to record type names.
  for(ID uTypeobj :  rUserManager)
  {
  	maprtid_rtManagerId.put(uTypeobj.id, uTypeobj.ManagerId); //for all recordtypes... log id's and record type names.
  }
 
  String rType; //declare string rType.
  //Use a for loop to run through The trigger Contracts and assign for every Case.AccountId a unique Contract.Id from the map
  List<Case> Cases = new List<Case>();
  for (Contract contract:Trigger.new){
      //contract.Manager__c=maprtid_rtManagerId(contract.Salesperson__c);
      
   	if(contract.First_Activation__c == False) { //this is the first time the contract has been activated
    	if (contract.Status == 'Activated Signed') {
     		if(contract.Major_Product_Line__c == 'Background (BSG)' || contract.Major_Product_Line__c == 'Advanced Biometric/I-9 (ABG)' || contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)') {
     			
        		if(maprtID_rtName.containsKey(contract.RecordTypeId)) //these are mapping the current contracts reference to recordtype ID to record type name
        			rType = maprtID_rtName.get(contract.RecordTypeId); //rtype is now the recordtypeID of the contract
     			if(rType == 'Application' || rType == 'Supporting Documentation' || rType == 'MSA - Master Service Agreement' || rType == 'Amendment' || rType == 'Standalone Agreement' || rType == 'Addendum') {
     	 			Case CaseAdd = new Case ();
       				CaseAdd.AccountId = contract.AccountId; //preload fields for the case
       				CaseAdd.Origin = 'Internal';
       				CaseAdd.Contract_Number__c = contract.Id;
       				CaseAdd.RecordTypeId = maprtName_rtIDCases.get('Account Set Up');
       				if(contract.Major_Product_Line__c == 'Background (BSG)')
       					CaseAdd.Request_Product_Type__c = 'Background (BSG)';
       				if(contract.Major_Product_Line__c == 'Advanced Biometric/I-9 (ABG)')
       					CaseAdd.Request_Product_Type__c = 'Advanced Biometric/Fingerprint//I-9 (ABG)';
       				if(contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)')
       					CaseAdd.Request_Product_Type__c = 'Drug (Occupational Health) (OHG)';
      				
      				CaseAdd.Ownerid=mapgName_gID.get('Account Set Up');
      				Cases.add(CaseAdd); //add the case in a bulk way :-)
      				contract.First_Activation__c = True; //set the activation to true.. so that it doesnt create multiple cases.. one is all you need
     			}
   		 	}
   		}
  	}
  	
//  }
//  	upsert Cases;
//  


if(contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)') {
	if(contract.Created_Child_Case__c == false) {
		if (contract.Status == 'Activated Signed') {
		contract.Created_Child_Case__c = true;
		Case CaseAdd2 = new Case();
		CaseAdd2.RecordTypeId = maprtName_rtIDCases.get('OHG IMPLEMENTATIONS');
		CaseAdd2.Ownerid = mapgName_gID.get('OHG Implementations');
		CaseAdd2.AccountId = contract.AccountId;
		CaseAdd2.Contract_Number__c = contract.Id;
		CaseAdd2.Origin = 'Internal';
		CaseAdd2.Request_Type__c = 'Implementation New Client';
		Cases.add(CaseAdd2);
		}
	}
}

if(contract.Major_Product_Line__c == 'Background (BSG)') {
	Set<String> multiselectValues = new Set<String>();
	multiSelectValues.addAll(contract.Services_Included__c.split(';'));
	if (contract.Status == 'Activated Signed') {
 		if(multiSelectValues.contains('Drug Services')){
 				if(contract.Created_Child_Case__c == false) {
					contract.Created_Child_Case__c = true;
					Case CaseAdd3 = new Case();
					CaseAdd3.RecordTypeId = maprtName_rtIDCases.get('OHG IMPLEMENTATIONS');
					CaseAdd3.AccountId = contract.AccountId;
					CaseAdd3.Contract_Number__c = contract.Id;
					CaseAdd3.Origin = 'Internal';
					CaseAdd3.Request_Type__c = 'Implementation New Client';
					CaseAdd3.Ownerid = mapgName_gID.get('OHG Implementations');
					Cases.add(CaseAdd3);
 				}
 		}
	}
}

  if(contract.Major_Product_Line__c == 'Assessments') {
  	Set<String> multiselectValues = new Set<String>();
	multiSelectValues.addAll(contract.Services_Included__c.split(';'));
  	if (contract.Status == 'Activated Signed') {
  		if(multiSelectValues.contains('Assessments Online Testing')){
                    if(multiSelectValues.contains('Assessments Professional Services')){
                    } else {
 				if(contract.Created_Child_Case__c == false) {
					contract.Created_Child_Case__c = true;
					Case CaseAdd3 = new Case();
					CaseAdd3.RecordTypeId = maprtName_rtIDCases.get('Account Set Up');
					CaseAdd3.Ownerid = mapgName_gID.get('Account Set Up');
					CaseAdd3.AccountId = contract.AccountId;
					CaseAdd3.Contract_Number__c = contract.Id;
					CaseAdd3.Origin = 'Internal';
					CaseAdd3.Request_Type__c = 'New Account';
					Cases.add(CaseAdd3);
 				}
                    }
  		}
  	}
  }
  }
  upsert Cases;
}

 errors on line 31

 

 

I have a apex visualforce page / apex that runs code to lookup relevant products (Product2) to potentially tie back to a specific Package (Packages__c) using a many:many relationship called ProductPackage.

 

So far, I've been successfully able to create the code/logic to pull everything necessary to the visual force page. Now, I am trying to figure out the best way to pass information from a form with a custom button back into apex and get a list of the selected Product2's.

 

What is the best strategy to use checkboxes to pull a list of these product2.ID's as well as potentially some sort of specific percent discount by product back into the apex environment so I can run them through more, yet to be developed algorithms/methods?

 

 

 

 

<apex:page standardController="Packages__c" extensions="packageextensions">

Package Name: <apex:OutputText value="{!Packages__c.Name}" />
<apex:form >
    <table border="1" >

        <tr>

            <th></th>
            <apex:repeat value="{!gProducts}" var="Nam">
            <th>{!Nam.Name}</th>
            </apex:repeat> 
        </tr>
        
        <tr>
            <td>Product Id</td>
        <apex:repeat value="{!gProducts}" var="Nam">
            <td>{!Nam.Id}<apex:inputCheckbox value="{!Nam.Id}"/></td>
        </apex:repeat> 
        </tr>
        
        
        <tr>
            <td>Price Book Id</td>
                <apex:repeat value="{!gPricebookEntry}" var="Nam">
                    <apex:repeat value="{!Nam.OpportunityLineItems}" var="OLI">
                        <td>{!OLI.Id}</td>
                    </apex:repeat> 
                </apex:repeat> 
        </tr>
        
        
        <tr>
            <td>Quantity</td>
                <apex:repeat value="{!gPricebookEntry}" var="Nam">
                    <apex:repeat value="{!Nam.OpportunityLineItems}" var="OLI">
                        <td>{!OLI.Quantity}</td>
                    </apex:repeat> 
                </apex:repeat> 
        </tr>
        
        
        <tr>
            <td>Default Price</td>
                <apex:repeat value="{!gPricebookEntry}" var="Nam">
                    <apex:repeat value="{!Nam.OpportunityLineItems}" var="OLI">
                        <td>{!OLI.ListPrice}</td>
                    </apex:repeat> 
                </apex:repeat> 
        </tr>
        
        
        <tr>
            <td>Unit Price</td>
                <apex:repeat value="{!gPricebookEntry}" var="Nam">
                    <apex:repeat value="{!Nam.OpportunityLineItems}" var="OLI">
                        <td>{!OLI.UnitPrice}</td>
                    </apex:repeat> 
                </apex:repeat> 
        </tr>       

        <tr>
            <td>Total Price</td>
                <apex:repeat value="{!gPricebookEntry}" var="Nam">
                    <apex:repeat value="{!Nam.OpportunityLineItems}" var="OLI">
                        <td>{!OLI.TotalPrice}</td>
                    </apex:repeat> 
                </apex:repeat> 
        </tr>
        
        <tr>
            <td>Package</td>
                <apex:repeat value="{!gPricebookEntry}" var="Nam">
                    <apex:repeat value="{!Nam.OpportunityLineItems}" var="OLI">
                        <td>{!OLI.Package_Name__c}</td>
                    </apex:repeat> 
                </apex:repeat> 
        </tr>
        
        <tr>
            <td>Description</td>
                <apex:repeat value="{!gPricebookEntry}" var="Nam">
                    <apex:repeat value="{!Nam.OpportunityLineItems}" var="OLI">
                        <td>{!OLI.Item_Description__c}</td>
                    </apex:repeat> 
                </apex:repeat> 
        </tr>
        
        <tr>
            <td>Include</td>
            
                <apex:repeat value="{!gPricebookEntry}" var="Nam">
                    <apex:repeat value="{!Nam.OpportunityLineItems}" var="OLI">
                        <td>{!OLI.Item_Description__c}</td>
                    </apex:repeat> 
                </apex:repeat> 
               
        </tr>

            
    </table>
    
     <apex:commandButton action="{!savepackage}" value="Save Package"/>
</apex:form>
</apex:page>

 

public class packageextensions {
    private final Packages__c PackageObj;
   // public pagereference savepackage(){}
    public packageextensions (ApexPages.StandardController controller) {
        this.PackageObj= (Packages__c)controller.getSubject();
        
    }
    
    
  //     public List<Product2> setgtest() {
  //    if(account == null) ppackage = new Packages__c();
  //    return ppackage;
  // }
    public List<Product2> includeinpackage{get;set;}
   public pagereference savepackage()
{
    
    includeinpackage=includeinpackage;
return null;
}


        
    public List<Product2> getgProducts() {
        //options.add(new Product2('None'));
    
        List<Product2> returnProducts = new List<Product2>();
        
        List<Packages__c> origPackage = new List<Packages__c>();
        origPackage = [select Opportunity__c from Packages__c where id=:PackageObj.Id Limit 1];
        
        List<OpportunityLineItem> origOpportunityLineItem = new List<OpportunityLineItem >();
        origOpportunityLineItem = [Select PricebookEntryId from OpportunityLineItem where OpportunityId =:origPackage[0].Opportunity__c];
        
        
        for(OpportunityLineItem presentopp : origOpportunityLineItem) {
            List<PricebookEntry> pbe = new List<PricebookEntry>();
            //pbe = [Select Product2Id from PricebookEntry where id=:presentopp.PricebookEntryId];
            
            //List<PricebookEntry> productpbe = new List<PricebookEntry>();
            pbe = [Select Product2Id, (Select Id, OpportunityId, PricebookEntryId, Quantity, TotalPrice, UnitPrice, ListPrice, Item_Description__c, Product_Line__c, Package_Name__c From OpportunityLineItems) From PricebookEntry p where id=:presentopp.PricebookEntryId];
            
            List<Product2> productitem = new List<Product2>();
            
            productitem = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
            returnProducts.add(productitem[0]);
            system.debug(productitem[0].Name);
            system.debug(productitem[0].Id);
            
            
            
            //I CAN'T SEEM TO GET TO THE SUBCOMPONENTS FROM THE QUERY 3 Lines Above!
        
        }
        
        
        
        //List<Product2> productitem2 = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
        
        return returnProducts;
        
        }

    public List<PricebookEntry> getgPricebookEntry() {
        //options.add(new Product2('None'));
    
        List<PricebookEntry> returnpbe = new List<PricebookEntry>();
        
        List<Packages__c> origPackage = new List<Packages__c>();
        origPackage = [select Opportunity__c from Packages__c where id=:PackageObj.Id Limit 1];
        
        List<OpportunityLineItem> origOpportunityLineItem = new List<OpportunityLineItem >();
        origOpportunityLineItem = [Select PricebookEntryId from OpportunityLineItem where OpportunityId =:origPackage[0].Opportunity__c];
     
        integer i, j;
        integer olicount=[Select COUNT() from OpportunityLineItem where OpportunityId =:origPackage[0].Opportunity__c];
        i=0; j=0;
        
        while(i<olicount) {
            List<PricebookEntry> pbe = new List<PricebookEntry>();
            //pbe = [Select Product2Id from PricebookEntry where id=:presentopp.PricebookEntryId];
            
            //List<PricebookEntry> productpbe = new List<PricebookEntry>();
            pbe = [Select Product2Id, (Select Id, OpportunityId, PricebookEntryId, Quantity, TotalPrice, UnitPrice, ListPrice, Item_Description__c, Product_Line__c, Package_Name__c From OpportunityLineItems) From PricebookEntry where id=:origOpportunityLineItem[i].PricebookEntryId];
 
            integer pbecount = [Select Count() From PricebookEntry where id=:origOpportunityLineItem[i].PricebookEntryId];
            j=0;
            while(j<pbecount) {
                returnpbe.add(pbe[j]);
                j++;
                i++;
            }           
            i++;
        }
        
        
     /*  
        for(OpportunityLineItem presentopp : origOpportunityLineItem) {
            List<PricebookEntry> pbe = new List<PricebookEntry>();
            //pbe = [Select Product2Id from PricebookEntry where id=:presentopp.PricebookEntryId];
            
            //List<PricebookEntry> productpbe = new List<PricebookEntry>();
            pbe = [Select Product2Id, (Select Id, OpportunityId, PricebookEntryId, Quantity, TotalPrice, UnitPrice, ListPrice, Item_Description__c, Product_Line__c, Package_Name__c From OpportunityLineItems) From PricebookEntry where id=:presentopp.PricebookEntryId];
            for(PricebookEntry presentpbe : pbe) {
                returnpbe.add(presentpbe);
                origOpportunityLineItem++;
            }           
        
        }
        */
        
        
        //List<Product2> productitem2 = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
        
        return returnpbe;
        
        }    
    
    
}

 

 

 

I am getting an error when saving, am I declaring the method wrong? Can I use an extension class?

 

ErrorError: action="{!savepackage}": Unknown method 'Packages__cStandardController.savepackage()' 

 

relevant code:

 

global class packageextensions {
    private final Packages__c PackageObj;
    public packageextensions (ApexPages.StandardController controller) {
        this.PackageObj= (Packages__c)controller.getSubject();
    }
    
    global static Boolean getAddDisposition(List<Product2> pproducts) {
        
        return false;
    }

 

The code that is erroring:

 

<apex:page standardController="Packages__c" extensions="packageextensions">
<apex:form >

     <apex:commandButton action="{!savepackage}" value="Save Package"/>

</apex:form>

 

 

 

I can't figure out why this isn't triggering when i have it run against a case that has comments.

 

usually i'd expect it to throw an error. but the lack of error shows that it isn't even entering the for loop

 

for (Case escalatedcase:Trigger.new){
    
    
   // escalatedcase.addError(escalatedcase.CaseComments);
    
    
                                        for(CaseComment oldcomment :  escalatedcase.CaseComments) {
                                      CaseComment newcomment = oldcomment.clone(false, true);
                                      //newcomment.ParentId = CaseAdd.Id;
                                      
                                      ccomments.add(newcomment);
                                       escalatedcase.addError('Please choose a Tier 2 Escalation Level to direct escalation.'); //in your face!
                                    }
}

 

I can't seem to figure out why I can't get this code to pull the Name of the product?

 

public class packageextensions {
    private final Packages__c PackageObj;
    public packageextensions (ApexPages.StandardController controller) {
        this.PackageObj= (Packages__c)controller.getSubject();
    }
    
    public List<Product2> getgProducts() {
        //options.add(new Product2('None'));
    
        List<Product2> returnProducts = new List<Product2>();
        
        List<Packages__c> origPackage = new List<Packages__c>();
        origPackage = [select Opportunity__c from Packages__c where id=:PackageObj.Id Limit 1];
        
        List<OpportunityLineItem> origOpportunityLineItem = new List<OpportunityLineItem >();
        origOpportunityLineItem = [Select PricebookEntryId from OpportunityLineItem where OpportunityId =:origPackage[0].Opportunity__c];
        
        
        for(OpportunityLineItem presentopp : origOpportunityLineItem) {
            List<PricebookEntry> pbe = new List<PricebookEntry>();
            pbe = [Select Product2Id from PricebookEntry where id=:presentopp.PricebookEntryId];
            
            List<Product2> productitem = new List<Product2>();
            
            productitem = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
            returnProducts.add(productitem[0]);
            debug.print(productitem[0].Name);
            //I CAN'T SEEM TO GET TO THE SUBCOMPONENTS FROM THE QUERY 3 Lines Above!
        
        }
        
        //List<Product2> productitem2 = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
        
        return returnProducts;
        
        }
              
}

 

Hi, I am at a loss of words for how dumb I feel asking this simple question. I have an array of product Id's in list form:

 

[01t700000017VVBAA2, 01t700000017VVBAA2, 01t300000000OIDAA2, 01t70000002KgcDAAS]

 

That comes out when I print the list:

 

List<Product2> returnProducts = new List<Product2>();

 

using this visual force code:

 

<apex:outputText value="{!Products}" />

 

How do I convert returnProducts into a list of products.. because right now i just have their ID's

 

aka, I want to be able to pull stuff in visual force like

 

<apex:outputText value="{!Products.Name}" />


<apex:outputText value="{!Products.Id}" />

 

Stuff like that?

 

I am trying to write a packageextensions class that will return a list of Product2 so that I can allow the user to choose which products go into a package. I finally figured out how they are all linked together, but my SOQL skills and LIST skills are not up to the level required to write this. Here is how it all links together:

 

Part 2 is a list, I recognize that. I need to convert these SOQL statements so that they all go together and result in a list of products. Any ideas? Are these nested SOQL statements? Do I need mapping?

 

First:
	Select Opportunity__c from Packages__c where id='a3FT00000009YHV'
		returns:
		'006T0000008rbgtIAA' which is the opportunity associated with the package. every package only has one opportunity.

Second:
	Select Id from OpportunityLineItem where OpportunityId = '006T0000008rbgtIAA'
		returns:
		'00kT0000006XzBMIA0'
		'00kT0000006Z6csIAC'
		'00kT0000006YgMHIA0'
		'00kT0000006YWuqIAG'

Third:
	Select PricebookEntryId from OpportunityLineItem where id='00kT0000006XzBMIA0'
		returns:
		'01u70000003P4sNAAS' (which is the productcode id)

Lastly:
	Select Product2Id from PricebookEntry where id='01u70000003P4sNAAS'
		returns:
		'01t700000017VVBAA2' (which is the product2 id, hurray!)

Confirm:
	Select Name from Product2 where id='01t700000017VVBAA2'
		--- this returns the product name. score!

 

 

 

 

public class packageextensions {
    private final Packages__c PackageObj;
    public packageextensions (ApexPages.StandardController controller) {
        this.PackageObj= (Packages__c)controller.getSubject();
    }
    
    public List<Product2> getProducts() {
        
        //Opportunity op = [Select PackageObj.Opportunity from Package__c];
        
        //List<Product2> products = [select id from OpportunityLineItem where Opportunity__c =:op.id];
        
        return products;
        
        }
        

}

 

 

i am trying to detect if the contract just got switched to status: activated signed, and only run this code on the first activation... at present i had a checkbox that i thought would work by triggering true when this code is run but at present appears to be failing... in fact according to eclipse/force explorer there is no such field even though the custom field shows up on the salesforce field under contracts

 

presently running on contract (before update)

 

 

 

String rType; //declare string rType.
  //Use a for loop to run through The trigger Contracts and assign for every Case.AccountId a unique Contract.Id from the map
  List<Case> Cases = new List<Case>();
  for (Contract contract:Trigger.new){
   	if(contract.First_Activation__c == False) { //this is the first time the contract has been activated
    	if (contract.Status == 'Activated Signed') {
     		if(contract.Major_Product_Line__c == 'Background (BSG)' || contract.Major_Product_Line__c == 'Advanced Biometric/I-9 (ABG)' || contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)') {
     			
        		if(maprtID_rtName.containsKey(contract.RecordTypeId)) //these are mapping the current contracts reference to recordtype ID to record type name
        			rType = maprtID_rtName.get(contract.RecordTypeId); //rtype is now the recordtypeID of the contract
     			if(rType == 'Application' || rType == 'Supporting Documentation' || rType == 'MSA - Master Service Agreement' || rType == 'Amendment' || rType == 'Standalone Agreement' || rType == 'Addendum') {
     	 			Case CaseAdd = new Case ();

 

 

my code at present, i cant even pull the field via SOQL:

 

SELECT First_Activation__c FROM Contract where ContractNumber='2012012680'

 

it errors: 

INVALID_FIELD:
SELECT First_Activation__c FROM Contract
^
ERROR at Row:1:Column:8
No such column 'First_Activation__c' on entity 'Contract'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

 

and yet:

 

 

Contract Custom Field First Activation
 
Custom Field Definition Detail  
Field Information
Field LabelFirst ActivationObject NameContract
Field NameFirst_ActivationData TypeCheckbox
API NameFirst_Activation__c  
Descriptionused to detect if this is the first time the contract is activated for a trigger. it's to simulate a workflow rule: When a record is created, or when a record is edited and did not previously meet the rule criteria
Help Textused to detect if this is the first time the contract is activated for a trigger. it's to simulate a workflow rule: When a record is created, or when a record is edited and did not previously meet the rule criteria
Created ByGlen Bradford, 8/29/2011 10:24 AMModified ByGlen Bradford, 1/10/2012 2:33 PM
General Options
Default ValueUnchecked  
Field DependenciesField Dependencies Help 
No dependencies defined.
Validation RulesValidation Rules Help 
No validation rules defined.
Always show me fewerShow Fewer / Show Moremore records per related list

 When I click the new note.... it doesnt open up the thing in a new page? what'd i do wrong

 

 

I currently have the code on my visual force page... because I am not the isUser but I want to make sure that for the isUser that it displays correctly. My question is how do I get this to output the related list? as of right now it is outputting attached screenshot as opposed to the related list.

 

 

VF PAGE:

 

<apex:page standardController="Contract" extensions="contractextensions">
       <apex:outputText value="{!Contract.Salesperson__c}" rendered="false"/>
     {!IF(isUser,"<apex:relatedList List=\"NotesAndAttachments\"></apex:relatedlist>","<apex:relatedList List=\"NotesAndAttachments\"></apex:relatedlist>")}
</apex:page>

 

APEX Extension Controller:

public class contractextensions {
    private final Contract contractObj;
    public contractextensions(ApexPages.StandardController controller) {
        this.contractObj= (Contract)controller.getSubject();
    }

    public boolean getisUser()
    {
        if(UserInfo.getUserId()== contractObj.Salesperson__c) {
            return True;
        } else {
            return False;
        }
        
    }
}

 

 

 

 

 

I am trying to figure out how to link a Master/Detail object and a lookup related object in the apex code.

 

my goals is that i have packages and products. in products, i want to be able to put them into packages if i want to and discount the packages.

 

in the apex class, how do i start coding this? i am operating from the perspective of the package. from the package i want to populate a multi-select / array of check boxes with all the opportunity products that meet specific parameters (A SOQL SELECT STATEMENT).

 

i want to be able to add or delete objects from this package, the trick is that this package is linked to the products (That populates opportunity products) via a many:many link using another table.. any ideas?

 

 

current visualforce page:

<apex:page standardController="Packages__c" extensions="productpackageextensions">
      <!--  <apex:relatedList list="OpportunityLineItems"/> -->
       <!-- <apex:relatedList list="ProductPackage__c"/> -->
 <apex:form >

   <apex:pageBlock title="Let's add Products to Packages {!$User.FirstName}">
    <apex:pageMessages />
    <apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Cancel" action="{!cancel}"/>
      <h1>Click Save to Add</h1>
      </apex:pageBlockButtons>
      <apex:pageBlockSection >
       <apex:outputField value="{!Packages__c.name}"/> 

     <!--  <apex:inputField value="{!Packages__c.ProductPackage__c.Product2}"/> -->
      </apex:pageBlockSection>
      <!-- End Default Content REMOVE THIS -->
      </apex:pageBlock>
      </apex:form>
</apex:page>

 current apex class code:

public class productpackageextensions{
private final Packages__c packageObj;
public productpackageextensions(ApexPages.StandardController controller) {
this.packageObj = (Packages__c)controller.getSubject();
}

public Packages__c[] getPackageProducts() {


}

 

We presently have opportunity products populating from the products2 object in our salesforce app.

 

what i am trying to figure out is the best practice to make packages of these products.

 

we created a salesforce object "Screening packages"

 

the idea is to have packages that contain products from an opportunity products list, and then to mark them down to a combined discount, say 25%.

 

how would you link these in?

 

http://imgur.com/JwN0T

 

Just trying to figure this out. As of present. I have related list linked products/services and products(which is products2)

 

my questions is when i go to products, it wants me to create a new one and i just want to link products in... i dont want a new one. and i only want to have products from the linked opportunity product available to choose from.

email.toAddresses.contains('teameast@2p0b7hdjfv8olr8hubm9unhg.37creai.7.case.salesforce.com'))

 

Save Error: Method does not exist or incorrect signature: [List <String>].contains(String)

 

how do i check to see if the to.Addresses field contains that string/email?

Apex trigger ContractCompliance caused an unexpected exception, contact your administrator: ContractCompliance: execution of BeforeUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Contract.Status: Trigger.ContractCompliance: line 6, column 1

Error: Invalid Data. 
Review all error messages below to correct your data.

 

trigger ContractCompliance on Opportunity (before update) {
	
	for (Opportunity opp:Trigger.new){
		List<Contract> c = new List<Contract>([SELECT id from Contract where AccountId = :opp.accountid]);
		for(Contract cTypeObj :  c) {
			if (cTypeObj.Status == 'Activated Signed') {
				if (cTypeObj.Contract_ID_Prefix__c == 'MSA') {
					opp.ContractStructure__c = 'Yes';
					opp.MSA_or_Standalone_Effective_Date__c = cTypeObj.StartDate;
					
				}
			}
		}		
		
		List<Account> a = new List<Account>([SELECT id from Account where Id = :opp.accountid]);
		for(Account aTypeObj :  a) {
			opp.Legal_Account_Name__c = aTypeObj.Hoovers_Company_Name__c;
			opp.Customer_Contract_Street_Address_1__c = aTypeObj.Hoover_s_HQ_Address_1__c;
			opp.Customer_Contract_Street_Address_2__c = aTypeObj.Hoover_s_HQ_Address_2__c;
			opp.Customer_Notices_City__c = aTypeObj.Hoover_s_HQ_City__c;
			opp.Customer_Notices_Zip__c = aTypeObj.Hoover_s_HQ_Postal_Code__c;
		}
	}
}

 

The purpose of this trigger is to pull values of fields to the sObject Opportunity from the related Contract(s)and Account(s)

I have apex code that populates fields, and I want to run the "before update" on all opportunities once a week to make sure that these fields that are populated are current.

I've created the scheduled batch apex in classes and have set it to schedule and run, and it's running but it isn't running the "before update" on all of my opportunities.

 

here's my scheduler:

global class batchitupson_schedule implements Schedulable {
global void execute(SchedulableContext scMain) {
BatchUpdateForecast clsBatchItUpSon = new BatchUpdateForecast('Select Id, Name FROM Opportunity','Opportunity','Source_Name__c','Gwins');
ID idBatch = Database.executeBatch(clsBatchItUpSon, 100);
}
}

 

and here is my Scheduled class that is batchable, as you can tell, all i want it to do is open all the opportunities and update them, much like if you were to click through them manually and click "Edit" then click "Save" which then runs my "before update" code for the opportunity

 

global class BatchUpdateForecast implements Database.Batchable<sObject>{

   global final String Query;
   global final String Entity;
   global final String Field;
   global final String Value;

   global BatchUpdateForecast (String q, String e, String f, String v){

      Query=q; Entity=e; Field=f;Value=v;
   }

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
     //for(sobject s : scope){
     //s.put(Field,Value); 
     //}
     update scope;
    }

   global void finish(Database.BatchableContext BC){
   }
}

 

I tried to create a workflow that changes the Opportunity Field: Stage to 'Deferred' if the opportunity is 180+ days old and the probability is >=5% and <=95%.... and it isn't updating the field Stage to 'Deferred'. This opportunity is 183 days old.

 

AND(ROUND((NOW() - CreatedDate),0)>180,Probability>5,Probability<=95)

 

http://i.imgur.com/9qChA.png

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger EscalateCase caused an unexpected exception, contact your administrator: EscalateCase: execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.EscalateCase: line 76, column 1

 

It is erroring on line:

List<Case> cCaseTypes = [SELECT Status, Id FROM Case where Status='Escalation Hold' AND ParentId =:escalatedcase.id LIMIT 10];


 

trigger EscalateCase on Case (before update, before insert) {
//MAP record type ID's to record type names.
        List<RecordType> rTypes = [select id,name from RecordType where SobjectType='Case'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
           
        MAP<Id , String> maprtID_rtName = new MAP<ID , String>();  //map record type ID's to record type names.
        for(RecordType rTypeObj :  rTypes)
        {
            maprtID_rtName.put(rTypeObj.id , rTypeObj.Name); //for all recordtypes... log id's and record type names.
        }
//MAP Record type names to record type ID's
        List<RecordType> rTypesCases = [select name,id from RecordType where SobjectType='Case'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
        
        MAP<String, ID> maprtName_rtIDCases = new MAP<String, ID>();  //map record type ID's to record type names.
        for(RecordType rTypeObj :  rTypesCases)
        {
            maprtName_rtIDCases.put(rTypeObj.Name, rTypeObj.id); //for all recordtypes... log id's and record type names.
        }
        
//MAP Case User Owner/Queue Names to reference ID's
        List<User> uTypesUsers = [select name,id from User];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
        
        MAP<String, ID> maprtName_rtIDUsers = new MAP<String, ID>();  //map record type ID's to record type names.
        for(User uTypeObj :  uTypesUsers)
        {
            maprtName_rtIDUsers.put(uTypeObj.Name, uTypeObj.id); //for all recordtypes... log id's and record type names.
        }
        
//MAP Case Group Owner/Queue Names to reference ID's
        List<Group> gTypesGroups = [select name,id from Group where Type='Queue'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
        
        MAP<String, ID> maprtName_rtIDGroups = new MAP<String, ID>();  //map record type ID's to record type names.
        for(Group gTypeObj :  gTypesGroups)
        {
            maprtName_rtIDGroups.put(gTypeObj.Name, gTypeObj.id); //for all recordtypes... log id's and record type names.
        }
    
////map for temporary return from escalation
    
    

//bulk cases for upsert
      List<Case> Cases = new List<Case>();
      List<CaseComment> ccomments = new List<CaseComment>();
      List<CaseComment> dcomments = new List<CaseComment>();
      List<CaseComment> pcomments = new List<CaseComment>();
      boolean escalated = false;
      boolean bccomments = false;
      boolean bdcomments = false;
      boolean bpcomments = false;
      MAP<ID, ID> mapescalate_add = new MAP<ID, ID>();

//lets have a look at all the trigger(s)
for (Case escalatedcase:Trigger.new){

escalated = false;    
    
//trying to close the parent case while children are still open   
      if (escalatedcase.Status=='Closed') { //trying to close the parent case while children are still open
            integer close = [Select count() from Case where ParentId = :escalatedcase.id and isClosed != true];
            if (close > 0) {
                  escalatedcase.addError('There are still Child Cases Open - Please close and try again!'); //in your face!
            }
      }
//END trying to close the parent case while children are still open


      if(maprtID_rtName.get(escalatedcase.RecordTypeId) == 'National Client Service') {
            
                  if(escalatedcase.ParentId == null) {
                      
                        if(escalatedcase.Status != 'Escalated' && escalatedcase.Status != 'Returned from Escalation' && escalatedcase.Status != 'Closed') {
                              //if any escalatedcase childcase has a status 'Escalation Hold' then pass the comments back to that case and put this case on status escalated and put that status as new
                              // then if not, proceed with the escalation group stuff
                            
                            //List<Case> cCaseTypes = [SELECT Status, Id FROM Case where ParentId =:escalatedcase.id LIMIT 10];
                            List<Case> cCaseTypes = [SELECT Status, Id FROM Case where Status='Escalation Hold' AND ParentId =:escalatedcase.id LIMIT 10];
                            for(Case eCase : cCaseTypes) {
                                If (eCase.Status == 'Escalation Hold') {
                                                
                                      Case CaseAdd = new Case(Id = eCase.id);
                                      CaseAdd.Status = 'New';
                                      CaseAdd.Escalation_Completion_Date__c = System.now();
                                      Cases.add(CaseAdd);
                                    
                                    
                                            List<CaseComment> comments = [Select c.Id, c.ParentId, c.IsPublished, c.CommentBody, c.CreatedById, c.CreatedDate, c.SystemModstamp, c.LastModifiedDate, c.LastModifiedById, c.IsDeleted from CaseComment c where c.ParentId = :escalatedcase.Id];
            
                                            for(CaseComment oldcomment :  comments) {
                                                CaseComment newcomment = new CaseComment();
                                                dcomments.add(oldcomment);
                                                bdcomments = true;
                                                newcomment.ParentId = escalatedcase.ParentId;
                                                newcomment.IsPublished = oldcomment.IsPublished;
                                                newcomment.CommentBody = oldcomment.CommentBody + escalatedcase.OwnerId + escalatedcase.Owner.Name;
                                                //Do I want to remove duplicates?
                                                //if (newcomment.CommentBody.substring(0,6) == 'Parent') { } else {
                                                    pcomments.add(newcomment);  
                                                    bpcomments = true;
                                                //}
                                            }
             
                                        
                                        
                                        escalated = true;
                                }
                            }
                            
                            

 


trigger ActivateContract on Contract (before update) {
  List<RecordType> rTypes = [select id,name from RecordType where SobjectType='Contract'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
 
  MAP<Id , String> maprtID_rtName = new MAP<ID , String>();  //map record type ID's to record type names.
  for(RecordType rTypeObj :  rTypes)
  {
  	maprtID_rtName.put(rTypeObj.id , rTypeObj.Name); //for all recordtypes... log id's and record type names.
  }

  List<Group> gTypes = [SELECT Id, name FROM Group where Type = 'Queue'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
 
  MAP<String , Id> mapgName_gID = new MAP<String , Id>();  //map record type ID's to record type names.
  for(Group gTypeObj :  gTypes)
  {
  	mapgName_gID.put(gTypeObj.Name, gTypeObj.id); //for all recordtypes... log id's and record type names.
  }
  
  List<RecordType> rTypesCases = [select name,id from RecordType where SobjectType='Case'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
  
  MAP<String, ID> maprtName_rtIDCases = new MAP<String, ID>();  //map record type ID's to record type names.
  for(RecordType rTypeObj :  rTypesCases)
  {
  	maprtName_rtIDCases.put(rTypeObj.Name, rTypeObj.id); //for all recordtypes... log id's and record type names.
  }
    
  List<User> rUserManager = [select id,ManagerId from User];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
  
  MAP<ID, ID> maprtid_rtManagerId = new MAP<ID, ID>();  //map record type ID's to record type names.
  for(ID uTypeobj :  rUserManager)
  {
  	maprtid_rtManagerId.put(uTypeobj.id, uTypeobj.ManagerId); //for all recordtypes... log id's and record type names.
  }
 
  String rType; //declare string rType.
  //Use a for loop to run through The trigger Contracts and assign for every Case.AccountId a unique Contract.Id from the map
  List<Case> Cases = new List<Case>();
  for (Contract contract:Trigger.new){
      //contract.Manager__c=maprtid_rtManagerId(contract.Salesperson__c);
      
   	if(contract.First_Activation__c == False) { //this is the first time the contract has been activated
    	if (contract.Status == 'Activated Signed') {
     		if(contract.Major_Product_Line__c == 'Background (BSG)' || contract.Major_Product_Line__c == 'Advanced Biometric/I-9 (ABG)' || contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)') {
     			
        		if(maprtID_rtName.containsKey(contract.RecordTypeId)) //these are mapping the current contracts reference to recordtype ID to record type name
        			rType = maprtID_rtName.get(contract.RecordTypeId); //rtype is now the recordtypeID of the contract
     			if(rType == 'Application' || rType == 'Supporting Documentation' || rType == 'MSA - Master Service Agreement' || rType == 'Amendment' || rType == 'Standalone Agreement' || rType == 'Addendum') {
     	 			Case CaseAdd = new Case ();
       				CaseAdd.AccountId = contract.AccountId; //preload fields for the case
       				CaseAdd.Origin = 'Internal';
       				CaseAdd.Contract_Number__c = contract.Id;
       				CaseAdd.RecordTypeId = maprtName_rtIDCases.get('Account Set Up');
       				if(contract.Major_Product_Line__c == 'Background (BSG)')
       					CaseAdd.Request_Product_Type__c = 'Background (BSG)';
       				if(contract.Major_Product_Line__c == 'Advanced Biometric/I-9 (ABG)')
       					CaseAdd.Request_Product_Type__c = 'Advanced Biometric/Fingerprint//I-9 (ABG)';
       				if(contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)')
       					CaseAdd.Request_Product_Type__c = 'Drug (Occupational Health) (OHG)';
      				
      				CaseAdd.Ownerid=mapgName_gID.get('Account Set Up');
      				Cases.add(CaseAdd); //add the case in a bulk way :-)
      				contract.First_Activation__c = True; //set the activation to true.. so that it doesnt create multiple cases.. one is all you need
     			}
   		 	}
   		}
  	}
  	
//  }
//  	upsert Cases;
//  


if(contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)') {
	if(contract.Created_Child_Case__c == false) {
		if (contract.Status == 'Activated Signed') {
		contract.Created_Child_Case__c = true;
		Case CaseAdd2 = new Case();
		CaseAdd2.RecordTypeId = maprtName_rtIDCases.get('OHG IMPLEMENTATIONS');
		CaseAdd2.Ownerid = mapgName_gID.get('OHG Implementations');
		CaseAdd2.AccountId = contract.AccountId;
		CaseAdd2.Contract_Number__c = contract.Id;
		CaseAdd2.Origin = 'Internal';
		CaseAdd2.Request_Type__c = 'Implementation New Client';
		Cases.add(CaseAdd2);
		}
	}
}

if(contract.Major_Product_Line__c == 'Background (BSG)') {
	Set<String> multiselectValues = new Set<String>();
	multiSelectValues.addAll(contract.Services_Included__c.split(';'));
	if (contract.Status == 'Activated Signed') {
 		if(multiSelectValues.contains('Drug Services')){
 				if(contract.Created_Child_Case__c == false) {
					contract.Created_Child_Case__c = true;
					Case CaseAdd3 = new Case();
					CaseAdd3.RecordTypeId = maprtName_rtIDCases.get('OHG IMPLEMENTATIONS');
					CaseAdd3.AccountId = contract.AccountId;
					CaseAdd3.Contract_Number__c = contract.Id;
					CaseAdd3.Origin = 'Internal';
					CaseAdd3.Request_Type__c = 'Implementation New Client';
					CaseAdd3.Ownerid = mapgName_gID.get('OHG Implementations');
					Cases.add(CaseAdd3);
 				}
 		}
	}
}

  if(contract.Major_Product_Line__c == 'Assessments') {
  	Set<String> multiselectValues = new Set<String>();
	multiSelectValues.addAll(contract.Services_Included__c.split(';'));
  	if (contract.Status == 'Activated Signed') {
  		if(multiSelectValues.contains('Assessments Online Testing')){
                    if(multiSelectValues.contains('Assessments Professional Services')){
                    } else {
 				if(contract.Created_Child_Case__c == false) {
					contract.Created_Child_Case__c = true;
					Case CaseAdd3 = new Case();
					CaseAdd3.RecordTypeId = maprtName_rtIDCases.get('Account Set Up');
					CaseAdd3.Ownerid = mapgName_gID.get('Account Set Up');
					CaseAdd3.AccountId = contract.AccountId;
					CaseAdd3.Contract_Number__c = contract.Id;
					CaseAdd3.Origin = 'Internal';
					CaseAdd3.Request_Type__c = 'New Account';
					Cases.add(CaseAdd3);
 				}
                    }
  		}
  	}
  }
  }
  upsert Cases;
}

 errors on line 31

 

 

I am getting an error when saving, am I declaring the method wrong? Can I use an extension class?

 

ErrorError: action="{!savepackage}": Unknown method 'Packages__cStandardController.savepackage()' 

 

relevant code:

 

global class packageextensions {
    private final Packages__c PackageObj;
    public packageextensions (ApexPages.StandardController controller) {
        this.PackageObj= (Packages__c)controller.getSubject();
    }
    
    global static Boolean getAddDisposition(List<Product2> pproducts) {
        
        return false;
    }

 

The code that is erroring:

 

<apex:page standardController="Packages__c" extensions="packageextensions">
<apex:form >

     <apex:commandButton action="{!savepackage}" value="Save Package"/>

</apex:form>

 

 

 

I can't figure out why this isn't triggering when i have it run against a case that has comments.

 

usually i'd expect it to throw an error. but the lack of error shows that it isn't even entering the for loop

 

for (Case escalatedcase:Trigger.new){
    
    
   // escalatedcase.addError(escalatedcase.CaseComments);
    
    
                                        for(CaseComment oldcomment :  escalatedcase.CaseComments) {
                                      CaseComment newcomment = oldcomment.clone(false, true);
                                      //newcomment.ParentId = CaseAdd.Id;
                                      
                                      ccomments.add(newcomment);
                                       escalatedcase.addError('Please choose a Tier 2 Escalation Level to direct escalation.'); //in your face!
                                    }
}

 

Hi, I am at a loss of words for how dumb I feel asking this simple question. I have an array of product Id's in list form:

 

[01t700000017VVBAA2, 01t700000017VVBAA2, 01t300000000OIDAA2, 01t70000002KgcDAAS]

 

That comes out when I print the list:

 

List<Product2> returnProducts = new List<Product2>();

 

using this visual force code:

 

<apex:outputText value="{!Products}" />

 

How do I convert returnProducts into a list of products.. because right now i just have their ID's

 

aka, I want to be able to pull stuff in visual force like

 

<apex:outputText value="{!Products.Name}" />


<apex:outputText value="{!Products.Id}" />

 

Stuff like that?