• MikeCloud
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 24
    Replies

I am not using the classes or triggers that came with an app. I downloaded, I wrote triggers that work in my sandbox, but my triggers I wrote and need + field customization, work flows... have caused problems with triggers already written by the app (I don't need any of them they are useless to me there are about 5 triggers and 20 Classes, How can I get rid of them all at once, they are currently deployed in the org..  I am having problems the one at a time in the IDE changing status to deleted is not working for me?

Need help with ERROR – Trigger Code and Test Code Below -Creating a "Project" Milestone1_Project__c record when an Opp custom field - Start_Project_Site_Id_Stage__c = Yes - This field is dependent upon Stage = "Closed Won" on the opportunity.

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateM1Project: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProjectMilestone: execution of AfterInsert

caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

Trigger.ProjectMilestone: line 16, column 1: []

Trigger.CreateM1Project: line 16, column 1: [] Stack Trace Class.CreateM1Project_test.myTestMethod: line 14, column 1

 

 

TRIGGER CODE

 

trigger CreateM1Project on Opportunity (after insert, after update) {

   

   

   List<Milestone1_Project__c> NewProjects = new List<Milestone1_Project__c>();

 

    for (Opportunity opp: trigger.new)  {

       

        if (opp.Start_Project_Site_Id_Stage__c == 'Yes') {

       

            Milestone1_Project__c freshProject = new Milestone1_Project__c();

            freshProject.Name = opp.Name;

            freshProject.Opportunity__c = opp.Id;

            NewProjects.add(freshProject);

        }

    }

    insert NewProjects;

       

   }

 

 

TEST CODE

 

@IsTest(SeeAllData=false)

public class CreateM1Project_test{

 

    static testMethod void myTestMethod() {

 

        Opportunity opp =

            new Opportunity(Name='Test',

            StageName='Closed Won',

            CloseDate=system.today(),

            Tower_Height__c='100',

            Start_Project_Site_Id_Stage__c='Yes');

           

        Test.startTest();

            insert opp;

        Test.stopTest();

       

    }

}

I have a custom object Project_Milestone1__c, I want to trigger a new Project when an Opportunity custom field picklist - Start_Project_Site_Id_Stage__c  = Yes, I can't get my test to pass?  Here id my TRIGGER and TEST

 

CODE

 

trigger CreateM1Project on Opportunity (after insert, after update) {
    
    
   List<Milestone1_Project__c> NewProjects = new List<Milestone1_Project__c>();

    for (Opportunity opp: trigger.new)  {
        
        if (opp.Start_Project_Site_Id_Stage__c == 'Yes') {
        
            Milestone1_Project__c freshProject = new Milestone1_Project__c();
            freshProject.Name = opp.Name;
            freshProject.Opportunity__c = opp.Id;
        }
    }
    insert NewProjects;
        
   }

 

 

TEST

 

@IsTest(SeeAllData=false)
public class CreateM1Project_test{

static testMethod void myTestMethod() {

Opportunity opp =new Opportunity(Name='Test',StageNAme='Closed Won',CloseDate=system.today(),Start_Project_Site_Id_Stage__c='Yes');

insert opp;


}
}

 

Trigger: When a custom field picklist value in Opp = Yes, I want to create a new Project, make new Project name the same as the Opp name:

 

 

 

trigger CreateM1Project on Opportunity (after insert) {
    
    
   List<Milestone1_Project__c> NewProjects = new List<Milestone1_Project__c>();

    for (Opportunity opp: trigger.new)  {
        
 

 

 if (opp.Start_Project_Site_Id_Stage__c == 'Yes') {
        
            Milestone1_Project__c freshProject = new Milestone1_Project__c();
            freshProject.Name = opp.Name;
            
        }
    }
    insert NewProjects;
        
   }

Requirements would be to capture website order fields(roughly 12 per transaction) and load into customer Salesforce instance.  Also need to create new account/contact/opportunity records as well as create new opportunity records for repeat customers.  

Whan a website lead comes in that will populate a lead source value.  When that happens I want that lead to automatically convert to a contact account opportunity.  Does anyone know how to trigger that.

Not sure what to do  - Client_Status__s is a custom filed on c case, standard contact and account names 

 

 

Error: Compile Error: Didn't understand relationship 'Contacts_r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 123 column 19

 

 

//if (Aid<>){
Account[] AL=[Select a.name,(select name, age__c,CLIENT_STATUS__C from Contacts__r where CLIENT_STATUS__c <>'inactive' and CLIENT_STATUS__c <> 'deceased' Order by Age__c desc) from Account a where id=:request.Account];
if (AL.size()>0){
ANAME=AL[0].name;
if (AL[0].Contacts__r.size()>0{
Alist=AL[0].Contacts__r;
}

}

Person who did this is gone, everthing works in this Apex Class but the referred PDF does not show Account, Account Contacts or custom field Age__c information, Case Request auto number appears and so does Shopping_List_Notes__c.

 

Need Account, Contacts, Ages to populate.

 

public class GroceryUpdate {
//VERSION 1: SORT GROCERY LIST BY CATEGORY
//  PDF: INCLUDE THE Contact/Account Name
//  Account Members Ages
//VERSION 2: CHANGE QUANTITY TO INTEGER TO REMOVE DECIMAL POINT
//VERSION 3: GET TYPE OF FOOD ORDER and SHOPPING NOTES FROM REQUEST (CASE)
  
  Case request;
  //Name crequest;
  List <Grocery_Request__c> GRList;
  List <Name> AList;
  //List <Account> atmplist;
  Account aMembers;
  Set<Id> GItemIdSet           = new Set<Id>();
  Set<Id> gIdSet             = new Set<Id>();
  Map<Id,wGrocery> gMap         = new Map<Id,wGrocery>();
  Map<Integer,Id> gSortMap       = new Map<Integer,Id>();
  Map<Integer,wGrocery> pdfGSortMap   = new Map<Integer,wGrocery>();
  Map<Id,Integer> pdfIdxMap       = new Map<Id,Integer>();
  List<wGrocery> gList         = new List<wGrocery>();
  List<Grocery_Item__c> gItemList;
  List<Grocery_Item__c> pdfGItemList;
  String Aid;
  String AName;
  // Contact c;     //LG
  
//****************
// CONSTRUCTOR
//****************
  
  public GroceryUpdate() {
    Integer idx = 0;
    
    //VERSION 1: SORT BY CATEGORY AFTER WAREHOUSE ORDER
    pdfGItemList = [Select g.Warehouse_Order__c, g.Name, g.Id, 
      g.Grocery_Category__c, g.Available__c 
      From Grocery_Item__c g
      order by Warehouse_Order__c, Grocery_Category__c, Name ASC nulls last
      limit 1000];

    for (Grocery_Item__c gi : pdfGItemList) {
      pdfGSortMap.put(idx,new wGrocery(gi));
      pdfIdxMap.put(gi.id,idx);
      idx++;
    }
    system.debug('@@@pdfGSortMap=' + pdfGSortMap);
    system.debug('@@@pdfIdxMap=' + pdfIdxMap);
    
    //VERSION 1: SORT BY CATEGORY AFTER AVAILABLE
    gItemList = [Select g.Warehouse_Order__c, g.Name, g.Id, 
      g.Grocery_Category__c, g.Available__c 
      From Grocery_Item__c g
      order by Available__c, Grocery_Category__c, Name ASC nulls last
      limit 1000];
    
    idx = 0;
    String s = null;
    String oldHighlight = '#BDBDBD';
    
    for (Grocery_Item__c gi : gItemList) {
      gMap.put(gi.id,new wGrocery(gi));
      
      if (gi.Grocery_Category__c != s ) {
        s=gi.Grocery_Category__c;
        if (oldHighlight == null) oldHighlight = '#BDBDBD';
        else oldHighlight = null;
      }
      
      gMap.get(gi.id).highlight = oldHighlight;
      
      if (gi.Available__c == true) {
        gSortMap.put(idx,gi.id);
        idx++;
      }
    }
    
    for (Grocery_Item__c gi : gItemList) {
      if (gi.Available__c == false) {
        gSortMap.put(idx,gi.id);
        idx++;
      }
    }
    
    //VERSION 3: GET Type_of_Food_Order__c and Shopping_List_Notes__c
    
    //request = [Select c.Id, c.Subject, c.Contact.Name, c.ContactId, c.CaseNumber,
    //  c.Type_of_Food_Order__c, c.Shopping_List_Notes__c,  
    //  (Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantify__c 
    //    From Grocery_Requests__r) 
    //  From Case c
    //  where id = :ApexPages.currentPage().getParameters().get('id')];
    
    //GRList = request.Grocery_Requests__r;
    //system.debug('@@@GRList=' + GRList);

    //for (Grocery_Request__c GR : GRList) {
    //  gMap.get(GR.Grocery_Item__c).quantity = GR.Quantify__c.intValue();
    //  gIdSet.add(GR.Grocery_Item__c);
      
    //  pdfGSortMap.get(pdfIdxMap.get(GR.Grocery_Item__c)).quantity = GR.Quantify__c.intValue();
    //}
    
    request = [Select c.Id,c.Account, c.Subject, c.Name, c.ContactId, c.CaseNumber,
      c.Type_of_Food_Order__c, c.Shopping_List_Notes__c,  
      (Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantify__c 
        From Grocery_Requests__r) 
      From Case c
      where id = :ApexPages.currentPage().getParameters().get('id')];
    Aid=request.Account;
    GRList = request.Grocery_Requests__r;
    
    system.debug('@@@GRList=' + GRList);

    for (Grocery_Request__c GR : GRList) {
      gMap.get(GR.Grocery_Item__c).quantity = GR.Quantify__c.intValue();
      gIdSet.add(GR.Grocery_Item__c);
      
      pdfGSortMap.get(pdfIdxMap.get(GR.Grocery_Item__c)).quantity = GR.Quantify__c.intValue();
    }
    
    //if (Aid<>''){
      Account[] AL=[Select a.name,(select name, age__c,Order by age__c desc) from Account a where id=:request.Account];
      If (AL.size()>0){
        AName=AL[0].name;
        If (AL[0].Contacts__r.size()>0){
          AList=AL[0].__r;
        }
        
      }
      
      
      //ctmplist=[Select name,(select name, age__c from Account.Contacts__r) from Account where id=:request.Account];
       //if (ctmplist[0].Contacts__r.size() > 0){
        
      
      //}
        
      //AList=ctmplist[0].Contacts__r;
    //}
    
    
    //AList=[Select name, age__c from Contact where Account like '%a0fA00000022ltLIAQ%'];
    
  
    
    
    //VERSION 1: GET Contact INFO
    // a = [Select a.Social_Security_Number__c, a.SC_Photo_ID__c, a.Name, a.Id,    LG
    //  From Contact a
    //  where id = :request.ContactId
    //  limit 1];
      
  }
  


//**************************
// GETTER AND SETTER METHODS
//**************************
  
  //VERSION 1: GET CONTACT INFO
  //public Contact getContact(){return a;}    //LG
  public Case getRequest(){return request;}
  public List<wGrocery> getpdfGRItemList() {
    List<wGrocery> pdfGRItemList = new List<wGrocery>(); 
    for (Integer i = 0; i<pdfGSortMap.size(); i++) {
      if (pdfGSortMap.get(i).quantity > 0) pdfGRItemList.add(pdfGSortMap.get(i));
      
    }
    return pdfGRItemList;
  }
  
  public List<Account> getCHList() {
    return CHList;
  }
  
  public string getHName(){
    return HName;
  }
  
  public List<wGrocery> getGList(){
    List<wGrocery> displayGList = new List<wGrocery>();
    for (Integer idx = 0; idx<gSortMap.size(); idx++) {
      displayGList.add(gMap.get(gSortMap.get(idx)));
    }
    return displayGList;
  }
  
  public void setGList(List<wGrocery> GList){
    for (wGrocery gr : GList) gMap.put(gr.GI.id,gr);
  }
  
  public pageReference save() {
    List<Grocery_Request__c> insertGList = new List<Grocery_Request__c>();
    
    for (Grocery_Request__c gr : GRList) gr.Quantify__c = GMap.get(gr.Grocery_Item__c).quantity;
    if (GRList.size()>0) update GRList;
    
    for (wGrocery wGr : GMap.values()) {
      if (wGr.quantity > 0 && gIdSet.contains(wGr.GI.Id)== false) {
        Grocery_Request__c gr = new Grocery_Request__c(Request__c=request.id, 
          Grocery_Item__c=wGr.GI.Id, Quantify__c=wGr.quantity);
        
        insertGList.add(gr);
      }
    }
    
    if (insertGList.size()>0) insert insertGList;
    
    
    PageReference pRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
    pRef.setRedirect(true);
    return pRef;
    
  }
//************
//PAGE METHODS
//************

  public pageReference cancel() {  
    
    PageReference pRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
    pRef.setRedirect(true);
    return pRef;
    
  }

  public pageReference pdfPage() {  
    
    PageReference pRef = page.GroceryUpdatePDFPage;
    pRef.getParameters().put('id',ApexPages.currentPage().getParameters().get('id'));
    pRef.setRedirect(true);
    return pRef;
    
  }
  
  //WRAPPER CLASS FOR GROCERY
  public class wGrocery{
    public Integer quantity {get; set;}
    public Grocery_Item__c GI {get; set;}
    public String highlight {get;set;}
           
    public wGrocery(Grocery_Item__c GI){
      quantity = 0;
      this.GI = GI;
      highlight=null;
    }
  }
  
  //TEST METHOD    
  static testMethod void T1() {
    //
    Grocery_Request__c qGR = [Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantify__c 
        From Grocery_Request__c
        where IsDeleted = false
        and Grocery_Item__c != null 
        limit 1];
        
    Case qRequest = [Select c.Id, 
      (Select Id, IsDeleted, Name, Request__c, Grocery_Item__c, Quantify__c 
        From Grocery_Requests__r) 
      From Case c
      where id = :qGR.Request__c
      limit 1];
      
      //INITIALIZE PAGE AND STANDARD CONTROLLER      
      PageReference pageRef = Page.GroceryUpdatePage;
      Test.setCurrentPageReference(pageRef);
      ApexPages.currentPage().getParameters().put('id', qRequest.Id);    
 
     GroceryUpdate stdCon = new GroceryUpdate();
     
    Case tgetRequest = stdCon.getRequest();
     List<wGrocery> tgetGList = stdCon.getGList();
     stdCon.setGList(tgetGList);
    List<wGrocery> tgetpdfGItemList  = stdCon.getpdfGRItemList();
     pageReference tpref = stdCon.save();
    tpref = stdCon.cancel();
    tpref = stdCon.pdfPage();
    // Account tA = stdCon.getAccount();
  }  
}

I have a custom object - Case Management, when the Contact lookup field is entered I want the Account lookup field associated with that Contact to be automatically entered.  I am new at this so here's what I have,  

Case_Management__c (before insert, before update) { for(Case_Management__c co: Trigger.new){ if (co.Contact__c != null){ co.Account__c = 'Yes'; } } }

 

This needs to be edited, but I am lost.

On a Case object or custom object you have an Acct. & a Contact lookup fiedl, when Account is populated how can you get the related contacts to that acct only to show up, and when you enter a contact how do you get the Account to populate since the contact is related to only one account.

do you use the original field name: example Account or renamed Household when writing Apex code.

I want to capture from my email info sent to me from an email service  -the contact info and description info.... similar to the way web to lead works, I have EE

I have a custom object with contact lookup field and account lookup field, when I enter Contact I want Account lookup field to populate based on the contact (associated to only one account) to cut down on all the lookups my users need to do in this object page layout.

Need help with ERROR – Trigger Code and Test Code Below -Creating a "Project" Milestone1_Project__c record when an Opp custom field - Start_Project_Site_Id_Stage__c = Yes - This field is dependent upon Stage = "Closed Won" on the opportunity.

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateM1Project: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProjectMilestone: execution of AfterInsert

caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

Trigger.ProjectMilestone: line 16, column 1: []

Trigger.CreateM1Project: line 16, column 1: [] Stack Trace Class.CreateM1Project_test.myTestMethod: line 14, column 1

 

 

TRIGGER CODE

 

trigger CreateM1Project on Opportunity (after insert, after update) {

   

   

   List<Milestone1_Project__c> NewProjects = new List<Milestone1_Project__c>();

 

    for (Opportunity opp: trigger.new)  {

       

        if (opp.Start_Project_Site_Id_Stage__c == 'Yes') {

       

            Milestone1_Project__c freshProject = new Milestone1_Project__c();

            freshProject.Name = opp.Name;

            freshProject.Opportunity__c = opp.Id;

            NewProjects.add(freshProject);

        }

    }

    insert NewProjects;

       

   }

 

 

TEST CODE

 

@IsTest(SeeAllData=false)

public class CreateM1Project_test{

 

    static testMethod void myTestMethod() {

 

        Opportunity opp =

            new Opportunity(Name='Test',

            StageName='Closed Won',

            CloseDate=system.today(),

            Tower_Height__c='100',

            Start_Project_Site_Id_Stage__c='Yes');

           

        Test.startTest();

            insert opp;

        Test.stopTest();

       

    }

}

I have a custom object Project_Milestone1__c, I want to trigger a new Project when an Opportunity custom field picklist - Start_Project_Site_Id_Stage__c  = Yes, I can't get my test to pass?  Here id my TRIGGER and TEST

 

CODE

 

trigger CreateM1Project on Opportunity (after insert, after update) {
    
    
   List<Milestone1_Project__c> NewProjects = new List<Milestone1_Project__c>();

    for (Opportunity opp: trigger.new)  {
        
        if (opp.Start_Project_Site_Id_Stage__c == 'Yes') {
        
            Milestone1_Project__c freshProject = new Milestone1_Project__c();
            freshProject.Name = opp.Name;
            freshProject.Opportunity__c = opp.Id;
        }
    }
    insert NewProjects;
        
   }

 

 

TEST

 

@IsTest(SeeAllData=false)
public class CreateM1Project_test{

static testMethod void myTestMethod() {

Opportunity opp =new Opportunity(Name='Test',StageNAme='Closed Won',CloseDate=system.today(),Start_Project_Site_Id_Stage__c='Yes');

insert opp;


}
}

 

Trigger: When a custom field picklist value in Opp = Yes, I want to create a new Project, make new Project name the same as the Opp name:

 

 

 

trigger CreateM1Project on Opportunity (after insert) {
    
    
   List<Milestone1_Project__c> NewProjects = new List<Milestone1_Project__c>();

    for (Opportunity opp: trigger.new)  {
        
 

 

 if (opp.Start_Project_Site_Id_Stage__c == 'Yes') {
        
            Milestone1_Project__c freshProject = new Milestone1_Project__c();
            freshProject.Name = opp.Name;
            
        }
    }
    insert NewProjects;
        
   }

Not sure what to do  - Client_Status__s is a custom filed on c case, standard contact and account names 

 

 

Error: Compile Error: Didn't understand relationship 'Contacts_r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 123 column 19

 

 

//if (Aid<>){
Account[] AL=[Select a.name,(select name, age__c,CLIENT_STATUS__C from Contacts__r where CLIENT_STATUS__c <>'inactive' and CLIENT_STATUS__c <> 'deceased' Order by Age__c desc) from Account a where id=:request.Account];
if (AL.size()>0){
ANAME=AL[0].name;
if (AL[0].Contacts__r.size()>0{
Alist=AL[0].Contacts__r;
}

}

I have a custom object - Case Management, when the Contact lookup field is entered I want the Account lookup field associated with that Contact to be automatically entered.  I am new at this so here's what I have,  

Case_Management__c (before insert, before update) { for(Case_Management__c co: Trigger.new){ if (co.Contact__c != null){ co.Account__c = 'Yes'; } } }

 

This needs to be edited, but I am lost.