• Irish@acc
  • NEWBIE
  • 25 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 34
    Questions
  • 26
    Replies

I have aritten a test class for my code..

trigger CloneTemplateTasks on Project__c(after Insert) {

 List<Project__c> lstPrj = new List<Project__c>();//create an empty list of Project  Set<String> setType = new Set<String>();//Set for Storing Project type  Set<Id> setPrjId = new Set<Id>(); // Set for Storing Projectids  List<Task__c> insertlst = new list<Task__c>(); // List of Task to insert

 

 for(Project__c proj : Trigger.new){

 setType.add(proj.Project_Type__c);

 }

 System.debug('setType----->'+setType);

 List<Project_Template__c> lstTemplate = [SELECT Template__c FROM Project_Template__c where Template__c !=null and Project_Type__c in:setType];

 System.debug('lstTemplate----->'+lstTemplate);

 for(Project_Template__c tempObj : lstTemplate){

 setPrjId.add(tempObj.Template__c); // code is not covering this line

 }

 System.debug('setPrjId----->'+setPrjId);

 List<Task__c> lsttask = [select id,Name,Project__c,TQL_Phase__c,Track_Root_Cause__c,Key_TQL_Milestone__c,Owner__c from Task__c where Project__c in :setPrjId ];

 System.debug('lsttask ----->'+lsttask);

   for(Project__c proj : Trigger.new)    {

    for(Task__c t : lsttask)        {      Task__c tsk = new Task__c();// my code is not covering these line      tsk = t.clone();      tsk.Project__c = proj.id;      insertlst.add(tsk);       }

  }

   System.debug('insertlst----->'+insertlst);

   insert insertlst;

 }

 

---------------------------------test class-----------------------------------

 

@IsTest

public class testClassCloneTemplateTasks{

 

    static testmethod void MyUnitTest(){

 

     //Create test profile 
Profile p = [select id from profile where name='System Administrator'];
Profile p2 = [select id from profile where name='TA Dev Lead'];

//Create Users 
    User User1 = new User(alias = 'u1', email='u1@testorg.com',
      emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
      localesidkey='en_US',profileid = p.Id, country='United States',
      timezonesidkey='America/Los_Angeles', username='u1@testorg.com');
    insert User1;
    
//create user2
User devlead = new User(alias = 'u2', email='u2@testorg.com',
      emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
      localesidkey='en_US', profileid = p2.Id, country='United States',
      timezonesidkey='America/Los_Angeles', username='dev@testorg.com');
    insert devlead;
    
//craete devlead user
User devlead2 = new User(alias = 'u2', email='u22@testorg.com',
      emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
      localesidkey='en_US', profileid = p2.Id, country='United States',
      timezonesidkey='America/Los_Angeles', username='dev2@testorg.com');
    insert devlead2;
//create FootPrint

Presence__c pr=new Presence__c();
pr.name='Test presence';
pr.MegaBU__c='CF';
pr.Region__c='LA';

//create TouchPoints
Channel__c ch=new Channel__c();

ch.name='test channel';
ch.type__c='Media';
ch.Presence_Id__c=pr.id;
ch.Start_Date__c=system.today();
ch.Audience__c='B2B';
ch.MegaBU__c='CF';
ch.GBU__c='CF';
ch.Region__c='LA';

  Project__c prj=new Project__c();

  prj.name='Test';
  prj.Project_Type__c='Social';   
  prj.Touchpoint_name__c=ch.id;
  prj.Overall_Project_Status__c='Not Started';
  prj.Project_Tql_Phase__c='3.build';    
  prj.Dev_Lead_User__c=devlead.id;
  insert prj;
//create Tak with required fields
task__c tsk=new Task__c();
tsk.Name='test Task';
tsk.Project__c=prj.id;
tsk.owner__c='DPDL';
tsk.Status__c='Not Started';
tsk.TQL_Phase__c='3. Build';
tsk.Actual_completion_date__c=system.today();
tsk.Target_Date_current_baseline__c=system.today();
tsk.Target_Date_original_baseline__c=system.today();
tsk.Track_Root_Cause__c=false;
tsk.Key_Tql_Milestone__C=true;

//tsk.Apex_Code__c=1;

insert tsk;

Project_Template__c tem=new Project_Template__c();
tem.Template__c=prj.id;
tem.Name='Test Template';
tem.Project_Type__c='Social';
insert tem;
 
task__c tsk1=new Task__c();
tsk1=tsk;
update tsk1;
}

 

 

 

}

 please help

Posts: 57
 
0
 

HI all,

 

I have written a schedualr class which will run once in a month, the requiremt is in the first month it runs it creates a record in child object and the all the field in this record will be filled manually.....

 

in the 2nd months it will run and  creates a new record but it field value must be copy from the 1st created record and in the third month when it run it again creates a new record and it will copy the filed value from 2nd created record and so on...

we can sort it based on the created date and then we can copy the field value...here is my code..

 

 

global class CreateQoDelivery implements Database.Batchable<sObject>,
Schedulable {

public String Query;
global CreateQoDelivery(){

String ProjectQuery = 'Select Id,Name,Dev_Lead_User__c,Project_Start_Date_original_baseline__c,Project_End_Date_original_baseline__c,Project_Start_Date_current_baseline__c,Project_End_Date_current_baseline__c,Project_Start_Date_actual__c,Project_End_Date_actual__c,Project_TQL_Phase__c,Project_State__c from Project__c where Overall_Project_Status__c NOT IN (\'Not Started\',\'On hold\') AND Project_TQL_Phase__c !=\'1. Kick-off\' AND Project_State__c IN(\'Active\')';

        
        
        this.Query=ProjectQuery;         
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(Database.BatchableContext BC, List<SObject> scope){
        List<Project__c> ProjectList =(Project__c[]) scope; 
                           
                        
                        
          List< Quality_of_Delivery__c> detailList = new List< Quality_of_Delivery__c>();
          
      

        for(Project__c prj : ProjectList){
           // create Master Rec for use as Detail Rec parent reference
           Quality_of_Delivery__c qodDel = new Quality_of_Delivery__c ();
		   
           List< Quality_of_Delivery__c> LstRecord = new List< Quality_of_Delivery__c>();// new line
           lstRecord=[Select CDN__c,Working_Days_to_get_ROM__c,Slow_score__c,PageSpeed_score__c,date__c,Name from Quality_of_Delivery__C where Project__c=:Prj.id AND final__c=False order by date__c limit 1];//ne line
                if(lstRecord==null){
                                    

                         
                         qodDel.Date__c = System.Today()-1;
                         qodDel.Project__c=prj.Id;                        
                        
                        qodDel.Name=prj.Name;
                        
                        
                        
                         qodDel.Dev_Lead__c=prj.Dev_Lead_User__c;
                              
                         qodDel.Number_of_Change_Requests__c =0;
                         qodDel.Approved_Status__c ='Pending input from Dev Specialist';
                         qodDel.Planned_Working_Days_Original_baseline__c= prj.Project_Start_Date_original_baseline__c.daysBetween(prj.Project_End_Date_original_baseline__c);
                         qodDel.Planned_Working_Days_current_baseline__c=prj.Project_Start_Date_current_baseline__c.daysBetween(prj.Project_End_Date_current_baseline__c); 
                         qodDel.Actual_Working_Days__c = prj.Project_Start_Date_actual__c.daysBetween(prj.Project_End_Date_actual__c);
                        }
                     
                        else{
                    for(Quality_of_Delivery__c q:lstRecord){
                    	 qodDel = q.Clone();
						 qodDel.Name=prj.Name;
                         qodDel.Project__c=prj.Id;                         
                         qodDel.Date__c = System.Today()-1;
                         qodDel.Project__c=prj.Id;                                             
                    }
           }
         detailList.add(qodDel);  
          
    insert detailList;
       
   }
}
global void finish(Database.BatchableContext BC){
}
  

                //Execute batch class with default constructor from schedular
    global void execute(SchedulableContext sc) {
        
        
       try {
    
         database.executeBatch(new CreateQoDelivery());

        }
        catch (Exception e) {
            System.debug('There are no jobs currently scheduled. ' + e.getMessage()); 
        } 
   }   
    
}

 

but m getting this error...please help me on this ...

First error: Insert failed. First exception on row 0 with id a1Pe00000002FxoEAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

HI all,

 

I have written a schedualr class which will run once in a month, the requiremt is in the first month it runs it creates a record in child object and the all the field in this record will be filled manually.....

 

in the 2nd months it will run and  creates a new record but it field value must be copy from the 1st created record and in the third month when it run it again creates a new record and it will copy the filed value from 2nd created record and so on...

we can sort it based on the created date and then we can copy the field value...here is my code..

 

global class CreateQoDelivery implements Database.Batchable<sObject>,
Schedulable {

public String Query;
global CreateQoDelivery(){

String ProjectQuery = 'Select Id,Name,Dev_Lead_User__c,Project_Start_Date_original_baseline__c,Project_End_Date_original_baseline__c,Project_Start_Date_current_baseline__c,Project_End_Date_current_baseline__c,Project_Start_Date_actual__c,Project_End_Date_actual__c,Project_TQL_Phase__c,Project_State__c from Project__c where Overall_Project_Status__c NOT IN (\'Not Started\',\'On hold\') AND Project_TQL_Phase__c !=\'1. Kick-off\' AND Project_State__c IN(\'Active\')';

        
        
        this.Query=ProjectQuery;         
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(Database.BatchableContext BC, List<SObject> scope){
        List<Project__c> ProjectList =(Project__c[]) scope; 
                           
                        
                        
          List< Quality_of_Delivery__c> detailList = new List< Quality_of_Delivery__c>();
          
      

        for(Project__c prj : ProjectList){
           // create Master Rec for use as Detail Rec parent reference
           Quality_of_Delivery__c qodDel = new Quality_of_Delivery__c ();
		   
           List< Quality_of_Delivery__c> LstRecord = new List< Quality_of_Delivery__c>();// new line
           lstRecord=[Select CDN__c,Working_Days_to_get_ROM__c,Slow_score__c,PageSpeed_score__c,date__c,Name from Quality_of_Delivery__C where Project__c=:Prj.id AND final__c=False order by date__c limit 1];//ne line
                if(lstRecord==null){
                                    

                         
                         qodDel.Date__c = System.Today()-1;
                         qodDel.Project__c=prj.Id;                        
                        
                        qodDel.Name=prj.Name;
                        
                        
                        
                         qodDel.Dev_Lead__c=prj.Dev_Lead_User__c;
                              
                         qodDel.Number_of_Change_Requests__c =0;
                         qodDel.Approved_Status__c ='Pending input from Dev Specialist';
                         qodDel.Planned_Working_Days_Original_baseline__c= prj.Project_Start_Date_original_baseline__c.daysBetween(prj.Project_End_Date_original_baseline__c);
                         qodDel.Planned_Working_Days_current_baseline__c=prj.Project_Start_Date_current_baseline__c.daysBetween(prj.Project_End_Date_current_baseline__c); 
                         qodDel.Actual_Working_Days__c = prj.Project_Start_Date_actual__c.daysBetween(prj.Project_End_Date_actual__c);
                        }
                     
                        else{
                    for(Quality_of_Delivery__c q:lstRecord){
                    	 qodDel = q.Clone();
						 qodDel.Name=prj.Name;
                         qodDel.Project__c=prj.Id;                         
                         qodDel.Date__c = System.Today()-1;
                         qodDel.Project__c=prj.Id;                                             
                    }
           }
         detailList.add(qodDel);  
          
    insert detailList;
       
   }
}
global void finish(Database.BatchableContext BC){
}
  

                //Execute batch class with default constructor from schedular
    global void execute(SchedulableContext sc) {
        
        
       try {
    
         database.executeBatch(new CreateQoDelivery());

        }
        catch (Exception e) {
            System.debug('There are no jobs currently scheduled. ' + e.getMessage()); 
        } 
   }   
    
}

 but m getting this error...please help me on this ...

First error: Insert failed. First exception on row 0 with id a1Pe00000002FxoEAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

Hi I'd like to create a pop up window which will have to value either Yes or No and when the user click on "Yes" it creates the Record and when the user click on NO nothing will happen...

 

please help me on this...this I want to achieve in javascript

Hi All,

 

I have written a trigger which will add a record in the related list, the condition for adding the record is that...

1. <Is Launch>: TRUE first, FALSE later 2. <Track Root Cause>: TRUE first, FALSE later. 3. <Actual Completion Date>: descending (later first)

 

it should check the first two value if condition doesn't met then sort the related list based on Actual completion date and copy that record in the new record..below are my code....

trigger CreateRootCause1 on Project__c (after update) {

for(Project__c prj:Trigger.new){
if(trigger.oldmap.get(prj.Id).Project_State__c!=trigger.newmap.get(prj.Id).Project_State__c)
{
  if(trigger.newmap.get(prj.id).Project_State__c=='In Cancellation'||  trigger.newmap.get(prj.id).Project_State__c=='In Closing'){
 List<Task__c> lsttask=new List<Task__c>();
 lsttask=[select id,name,Project__c,Is_Launch__c,Actual_completion_date__c,Target_Date_current_baseline__c from Task__c where (Is_Launch__c=true OR Track_Root_Cause__c=true) AND Project__c=:prj.id Order by Actual_completion_date__c desc limit 1];
 List<Root_Cause__c> lstrc=new List<Root_Cause__c>();
for(Task__c t:lsttask){
     Root_Cause__c RCDel= new Root_Cause__c();
     RCDel.TaskName__c=t.Id; 
     RCDel.Name=t.Name +' - '+'Final';
     RcDel.Project_Name__c=prj.id;         
     RCDel.Date__c=System.Today();            
     RCDel.Launch_Date_Delay__c=0;
     RCDel.Apex_Context__c=TRUE;          
                
     lstRC.add(RCDel);           
      
}
    insert lstRc;
}
}
}




}

Hi All,

 

I have written a trigger which will add a record in the related list, the condition for adding the record is that...

1. <Is Launch>: TRUE first, FALSE later
2. <Track Root Cause>: TRUE first, FALSE later. 
3. <Actual Completion Date>: descending (later first)

 

it should check the first two value if condition doesn't met then sort the related list based on Actual completion date and copy that record in the new record..below are my code....

trigger CreateRootCause1 on Project__c (after update) {

for(Project__c prj:Trigger.new){
if(trigger.oldmap.get(prj.Id).Project_State__c!=trigger.newmap.get(prj.Id).Project_State__c)
{
  if(trigger.newmap.get(prj.id).Project_State__c=='In Cancellation'||  trigger.newmap.get(prj.id).Project_State__c=='In Closing'){
 List<Task__c> lsttask=new List<Task__c>();
 lsttask=[select id,name,Project__c,Is_Launch__c,Actual_completion_date__c,Target_Date_current_baseline__c from Task__c where (Is_Launch__c=true OR Track_Root_Cause__c=true) AND Project__c=:prj.id Order by Actual_completion_date__c desc limit 1];
 List<Root_Cause__c> lstrc=new List<Root_Cause__c>();
for(Task__c t:lsttask){
     Root_Cause__c RCDel= new Root_Cause__c();
     RCDel.TaskName__c=t.Id; 
     RCDel.Name=t.Name +' - '+'Final';
     RcDel.Project_Name__c=prj.id;         
     RCDel.Date__c=System.Today();            
     RCDel.Launch_Date_Delay__c=0;
     RCDel.Apex_Context__c=TRUE;          
                
     lstRC.add(RCDel);           
      
}
    insert lstRc;
}
}
}




}

 

HI,

I have a custom button which creates child record on metting some condition now I have got another requiremnt that it also creates grand child record..please help me on this a

s how to achieve this...below is my code...

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

{!REQUIRESCRIPT("/soap/ajax/27.0/apex.js")}
var url = parent.location.href;

var prjid='{!Project__c.Id}';

var TaskId='{!Task__c.Id}';


result = sforce.connection.query("Select Status__c,id,Project__c from Task__c where Status__c not in ('Complete','Cancelled') and Project__c='"+prjid +"'");



var records = result.getArray("records");
var date = new Date('{!TODAY()}'); 
var i = records.length;
if(i>0)
   {
    
 
   window.alert("All Tasks need to be completed before the project can be closed.");
   parent.location.href = url;
}
else{

var createqod = new sforce.SObject("Quality_of_delivery__c"); 
createqod.Project__c = "{!Project__c.Id}"; 
createqod.Name = "{!Project__c.Name} " +" - "+"FINAL";
//createqod.Approved_Status__c="Pending input from Dev Specialist";
createqod.Number_of_Change_Requests__c=0;
createqod.date__c=date;
createqod.Final__c="True";
createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";

sforce.connection.create([createqod]);

//creating Grand Child Record here

var createrc = new sforce.SObject("Root_cause__c"); 
//createrc.Name="Root Cause"+" - "+"Final";
createrc.Project_Name__c="{!Project__c.Id}";
createrc.TaskName__c=    //how to give value here this is the parent id of the grand child record
createrc.Apex_context__c="true";
createrc.Final__c="True";
createrc.Launch_date_delay__c=0;
createrc.date__C=date;
//createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";
sforce.connection.create([createrc]);



parent.location.href = url;

}

 

 

Hi,

 

I'm looking for a trigger which copy the lookup filed from grand parent and paste it on the grandh child is created..

please help me on this...

global class CreateRootCause implements Database.Batchable<sObject>,
Schedulable {

public String Query;
global CreateRootCause(){

String ProjectQuery = 'Select Id,Name,Dev_Lead_User__c from Project__c where Overall_Project_Status__c NOT IN (\'Not Started\',\'On hold\') AND Project_TQL_Phase__c !=\'1. Kick-off\' AND Project_State__c IN(\'Active\')';

        
        
        this.Query=ProjectQuery;         
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(Database.BatchableContext BC, List<SObject> scope)
    {
        List<Project__c> ProjectList =(Project__c[]) scope; 
                               
    
    for(project__c prj: ProjectList)
    { 

        List<Task__c> Lsttask=new List<Task__c>();
        Lsttask=[Select id,project__c from Task__c where project__c=: prj.Id];  
        List<Root_Cause__c> lstRC=new List<Root_Cause__c>();
    for(Task__c thistask: Lsttask)
        {
            
            Root_Cause__c RCDel= new Root_Cause__c();
            RCDel.TaskName__c=thistask.Id;
            RCDel.Date__c=System.Today();  
            RCDel.Final__c=true;
            RCDel.Project_Name__c=thistask.Project__c;
            RCDel.Launch_Date_Delay__c=0; 
            RCDel.Dev_Lead__c=prj.Dev_Lead_User__c;     
            lstRC.add(RCDel);     
            //lsttask.add(thistask);
        }    
  
     insert lstRC;
    }
 
}
global void finish(Database.BatchableContext BC){
}
  

                //Execute batch class with default constructor from schedular
    global void execute(SchedulableContext sc) {
        
        
       try {
    
         database.executeBatch(new CreateRootCause());

        }
        catch (Exception e) {
            System.debug('There are no jobs currently scheduled. ' + e.getMessage()); 
        } 
   }   
    
}

How to write test class for the above code..please help me on this...

Hi All,

I have two object in the related list and if Approal Status on both the object changes to "Approved " then the Project_State__c field on the parent object changes to "Closed".

 

I have written the trigger but It's not working...please help me

 

trigger Update_Project_State on Project__c (before update) {

 

for(Project__c Prj:trigger.New){

 List<Quality_of_Delivery__c> Lstqod= new LIST<Quality_of_Delivery__c>();//object-1 MD relation

 List<Root_Cause__c> LstRC= new LIST<Root_Cause__c>();       //object-2 lookup    

 

Lstqod=[Select project__c,Final__c,Approved_Status__c from Quality_of_Delivery__c where project__c=: prj.Id];//Query qod      

 

LstRC=[Select Project_Name__c,Final__c,Approval_Status__c from Root_Cause__c where Project_Name__c=: j.Id];               

List<Project__c> prjupdate= new List<Project__c>();

            if(LstRC!=null){        for(Root_Cause__c r:LstRC){  

            if(r.Approval_Status__c=='Approved' && r.Final__C==True)  

             {                

              if(Lstqod!=null){     

                                  for(Quality_of_Delivery__c q:lstqod)  {    

                                            

                            if(q.Approved_Status__c=='Approved' && q.Final__c==True){

                                                             

                                   if(prj.Project_State__c=='Active'){                         

                                                     prj.Project_State__c='Closed';    

                                                     prjupdate.add(prj);      

                               }                                                                                                      

                           else if(prj.Project_State__c=='In Cancellation')

                                          {                                 

                                  prj.Project_State__c='Cancelled';                             

                                     prjupdate.add(prj);                              

   }                                                                                                                                                                       

   }

}                                                                     

update prjupdate;                                                                                                                                   

        }       

        }                                          

    }       

   }                                                               

}

}

trigger updateDev_Lead on Project__c(after update) { 

          for(project__c prj: trigger.new)     {

 

    if(trigger.oldmap.get(prj.Id).Dev_Lead_User__c!=trigger.newmap.get(prj.Id).Dev_Lead_User__c) { 

   List<Quality_of_Delivery__c> Lstqod=new List<Quality_of_Delivery__c>();

    Lstqod=[Select project__c,Name,Dev_lead__c from Quality_of_Delivery__c where project__c=: prj.Id];         List<Quality_of_Delivery__c> qodToupdate=new List<Quality_of_Delivery__c>();

 

    for(Quality_of_Delivery__c thisqod: Lstqod)         {

                            {      

               thisqod.Dev_lead__c=prj.Dev_Lead_User__c;   

                

                    qodToupdate.add(thisqod);    

             }

        }

    if(!qodToupdate.isempty()){

           update qodToupdate;  

      }  

     }   

        }

}

Hi,

can anybody tell me what logic should be used to create a child record when the date field changes for the 2nd time onwards...?

 

I have a date field in the parent object when this date field changes don't create the recod when it changes the 2nd time then creates the record...how to do it?

IF(

AND(

ISNULL(Major_Defect_UAT_Partner__c), ISNULL(Minor_defect_UAT_Partner__c), ISNULL(Compliance_HC__c), ISNULL(Compliance_Launch__c )

),

null,1-IF(ISNULL(Major_Defect_UAT_Partner__c),0,Major_Defect_UAT_Partner__c)-

IF(ISNULL(Minor_defect_UAT_Partner__c),0,Minor_defect_UAT_Partner__c)-

IF(ISNULL(Compliance_HC__c),0,Compliance_HC__c)-

if(ISNULL(Compliance_Launch__c),0,Compliance_Launch__c)

)

---------------------

above formula I'm using when all the fields are null show null else calculate the value..the problem is I can't saved it showing an error..Compiled formula is too big to execute (6,581 characters). Maximum size is 5,000 characters

Hi,

 

I'm using an email Template to notify the customer Portal every time the record is getting created but the link which m sending to check the record doesn't for it...please tell me how to send the URL for the Customer Portal user?

Hi,

 

I have a scheduler class which create child records and this apex class fires on 1st day of every months...

I want to concat the name of the child record to concat with previous month vs current months...

 

so basically it should appear like this: childName= test-JAN-FEB;

 

please help me on this as how i Can achieve this..

Hi,

I have two object QOD__c--> child object, Approval_Status__c is a field on this object

Project__c--> Parent Object, Project_State__c is a field on this object.

 

I'm writting a trigger whenevr Approval_Status__c changes and equal to Approved then update the Project__State__c to "Closed"

 

below is the trigger but m getting error on it...

trigger Populate on Quality_of_Delivery__c (after update) {

List<Project__c> Lstprj=new List<Project__c>(); Set<Id> PrjId =new Set<Id>();

Lstprj=[Select Id from Project__c];

for(Project__c proj : lstprj){

PrjId.add(proj.Id);

}

    Map<Id,Project__c> prj = new Map<Id, Project__c>([select Project_State__c,Id from project__c where id in :prjid]);//Getting error here..DML requires SObject or SObject list type: MAP<Id,Project__c> at line 30 column 13 

 

      for(Quality_of_Delivery__c q: Trigger.new)  

{  

 

if(trigger.oldmap.get(q.Id).Approved_Status__c!=trigger.newmap.get(q.Id).Approved_Status__c)  

 

    {  

 

    if(  trigger.newmap.get(q.Id).Approved_Status__c=='Approved'){

                     prj.get(q.Project__c).Project_State__c='Closed';      

                          }      

      }         

    update prj;  

        

                      }

  }

 

please look into this

Below is the code which creates the related child object it works fine for sys admin but doesn't work for other profile

 

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

{!REQUIRESCRIPT("/soap/ajax/27.0/apex.js")} var url = parent.location.href;

var prjid='{!Project__c.Id}';

var TaskId='{!Task__c.Id}';

result = sforce.connection.query("Select Status__c,Project__c from Task__c where Status__c not in ('Complete','Cancelled') and Project__c='"+prjid +"'");

 

var records = result.getArray("records");

var date = new Date('{!TODAY()}');

var i = records.length; if(i>0) 

  {     parent.location.href = url; 

   window.alert("All Tasks need to be completed before the project can be closed.");

}

else{

var createqod = new sforce.SObject("Quality_of_delivery__c");

createqod.Project__c = "{!Project__c.Id}";

createqod.Name = "{!Project__c.Name} ";

createqod.Approved_Status__c="Pending input from Dev Specialist";

createqod.Number_of_Change_Requests__c=0;

createqod.date__c=date; createqod.Final__c="True";

createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}"

sforce.connection.create([createqod]);

parent.location.href = url; window.alert("A final Quality of Delivery record has been created for the project. It needs to be updated and approved by Dev Lead - only then the project will be closed");

 

 

 

 

}

Below is the code which creates the related child object it works fine for sys admin but doesn't work for other profile

 

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

{!REQUIRESCRIPT("/soap/ajax/27.0/apex.js")} var url = parent.location.href;

var prjid='{!Project__c.Id}';

var TaskId='{!Task__c.Id}';

result = sforce.connection.query("Select Status__c,Project__c from Task__c where Status__c not in ('Complete','Cancelled') and Project__c='"+prjid +"'");

 

var records = result.getArray("records");

var date = new Date('{!TODAY()}');

var i = records.length; if(i>0)  

  {     parent.location.href = url;  

   window.alert("All Tasks need to be completed before the project can be closed.");

}

else{

var createqod = new sforce.SObject("Quality_of_delivery__c");

createqod.Project__c = "{!Project__c.Id}";

createqod.Name = "{!Project__c.Name} ";

createqod.Approved_Status__c="Pending input from Dev Specialist";

createqod.Number_of_Change_Requests__c=0;

createqod.date__c=date; createqod.Final__c="True";

createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}"

sforce.connection.create([createqod]);

parent.location.href = url; window.alert("A final Quality of Delivery record has been created for the project. It needs to be updated and approved by Dev Lead - only then the project will be closed");

 

 

 

 

}

Hi All,

 

This is the first time I've ever got a req that needs to be completed by FLOW and I have never worked on that..so please help me on this...

 

My requ is...I have to create a flow on custom button that button will be on parent object..

when I click on this button..It should do following thing..

1. Go to the child records say (Task__c)

2. Check the Status__c field on Task(There may be more than one records).....

If it is "completed", then go to the other child object "Delivery__c" and Create new record there. Esle

 

3. Notify the user that All task are not completed, First Finished the task...

 

Please help me on this as how to achieve this....

I have a situation like...I need to create a cusstom button on parent object and whenevr this button is clicked it should go to the child object and check some fields  and then update the field in parent object based on some condition.plz help me on this

Posts: 57
 
0
 

HI all,

 

I have written a schedualr class which will run once in a month, the requiremt is in the first month it runs it creates a record in child object and the all the field in this record will be filled manually.....

 

in the 2nd months it will run and  creates a new record but it field value must be copy from the 1st created record and in the third month when it run it again creates a new record and it will copy the filed value from 2nd created record and so on...

we can sort it based on the created date and then we can copy the field value...here is my code..

 

 

global class CreateQoDelivery implements Database.Batchable<sObject>,
Schedulable {

public String Query;
global CreateQoDelivery(){

String ProjectQuery = 'Select Id,Name,Dev_Lead_User__c,Project_Start_Date_original_baseline__c,Project_End_Date_original_baseline__c,Project_Start_Date_current_baseline__c,Project_End_Date_current_baseline__c,Project_Start_Date_actual__c,Project_End_Date_actual__c,Project_TQL_Phase__c,Project_State__c from Project__c where Overall_Project_Status__c NOT IN (\'Not Started\',\'On hold\') AND Project_TQL_Phase__c !=\'1. Kick-off\' AND Project_State__c IN(\'Active\')';

        
        
        this.Query=ProjectQuery;         
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(Database.BatchableContext BC, List<SObject> scope){
        List<Project__c> ProjectList =(Project__c[]) scope; 
                           
                        
                        
          List< Quality_of_Delivery__c> detailList = new List< Quality_of_Delivery__c>();
          
      

        for(Project__c prj : ProjectList){
           // create Master Rec for use as Detail Rec parent reference
           Quality_of_Delivery__c qodDel = new Quality_of_Delivery__c ();
		   
           List< Quality_of_Delivery__c> LstRecord = new List< Quality_of_Delivery__c>();// new line
           lstRecord=[Select CDN__c,Working_Days_to_get_ROM__c,Slow_score__c,PageSpeed_score__c,date__c,Name from Quality_of_Delivery__C where Project__c=:Prj.id AND final__c=False order by date__c limit 1];//ne line
                if(lstRecord==null){
                                    

                         
                         qodDel.Date__c = System.Today()-1;
                         qodDel.Project__c=prj.Id;                        
                        
                        qodDel.Name=prj.Name;
                        
                        
                        
                         qodDel.Dev_Lead__c=prj.Dev_Lead_User__c;
                              
                         qodDel.Number_of_Change_Requests__c =0;
                         qodDel.Approved_Status__c ='Pending input from Dev Specialist';
                         qodDel.Planned_Working_Days_Original_baseline__c= prj.Project_Start_Date_original_baseline__c.daysBetween(prj.Project_End_Date_original_baseline__c);
                         qodDel.Planned_Working_Days_current_baseline__c=prj.Project_Start_Date_current_baseline__c.daysBetween(prj.Project_End_Date_current_baseline__c); 
                         qodDel.Actual_Working_Days__c = prj.Project_Start_Date_actual__c.daysBetween(prj.Project_End_Date_actual__c);
                        }
                     
                        else{
                    for(Quality_of_Delivery__c q:lstRecord){
                    	 qodDel = q.Clone();
						 qodDel.Name=prj.Name;
                         qodDel.Project__c=prj.Id;                         
                         qodDel.Date__c = System.Today()-1;
                         qodDel.Project__c=prj.Id;                                             
                    }
           }
         detailList.add(qodDel);  
          
    insert detailList;
       
   }
}
global void finish(Database.BatchableContext BC){
}
  

                //Execute batch class with default constructor from schedular
    global void execute(SchedulableContext sc) {
        
        
       try {
    
         database.executeBatch(new CreateQoDelivery());

        }
        catch (Exception e) {
            System.debug('There are no jobs currently scheduled. ' + e.getMessage()); 
        } 
   }   
    
}

 

but m getting this error...please help me on this ...

First error: Insert failed. First exception on row 0 with id a1Pe00000002FxoEAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

Hi I'd like to create a pop up window which will have to value either Yes or No and when the user click on "Yes" it creates the Record and when the user click on NO nothing will happen...

 

please help me on this...this I want to achieve in javascript

Hi All,

 

I have written a trigger which will add a record in the related list, the condition for adding the record is that...

1. <Is Launch>: TRUE first, FALSE later 2. <Track Root Cause>: TRUE first, FALSE later. 3. <Actual Completion Date>: descending (later first)

 

it should check the first two value if condition doesn't met then sort the related list based on Actual completion date and copy that record in the new record..below are my code....

trigger CreateRootCause1 on Project__c (after update) {

for(Project__c prj:Trigger.new){
if(trigger.oldmap.get(prj.Id).Project_State__c!=trigger.newmap.get(prj.Id).Project_State__c)
{
  if(trigger.newmap.get(prj.id).Project_State__c=='In Cancellation'||  trigger.newmap.get(prj.id).Project_State__c=='In Closing'){
 List<Task__c> lsttask=new List<Task__c>();
 lsttask=[select id,name,Project__c,Is_Launch__c,Actual_completion_date__c,Target_Date_current_baseline__c from Task__c where (Is_Launch__c=true OR Track_Root_Cause__c=true) AND Project__c=:prj.id Order by Actual_completion_date__c desc limit 1];
 List<Root_Cause__c> lstrc=new List<Root_Cause__c>();
for(Task__c t:lsttask){
     Root_Cause__c RCDel= new Root_Cause__c();
     RCDel.TaskName__c=t.Id; 
     RCDel.Name=t.Name +' - '+'Final';
     RcDel.Project_Name__c=prj.id;         
     RCDel.Date__c=System.Today();            
     RCDel.Launch_Date_Delay__c=0;
     RCDel.Apex_Context__c=TRUE;          
                
     lstRC.add(RCDel);           
      
}
    insert lstRc;
}
}
}




}

HI,

I have a custom button which creates child record on metting some condition now I have got another requiremnt that it also creates grand child record..please help me on this a

s how to achieve this...below is my code...

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

{!REQUIRESCRIPT("/soap/ajax/27.0/apex.js")}
var url = parent.location.href;

var prjid='{!Project__c.Id}';

var TaskId='{!Task__c.Id}';


result = sforce.connection.query("Select Status__c,id,Project__c from Task__c where Status__c not in ('Complete','Cancelled') and Project__c='"+prjid +"'");



var records = result.getArray("records");
var date = new Date('{!TODAY()}'); 
var i = records.length;
if(i>0)
   {
    
 
   window.alert("All Tasks need to be completed before the project can be closed.");
   parent.location.href = url;
}
else{

var createqod = new sforce.SObject("Quality_of_delivery__c"); 
createqod.Project__c = "{!Project__c.Id}"; 
createqod.Name = "{!Project__c.Name} " +" - "+"FINAL";
//createqod.Approved_Status__c="Pending input from Dev Specialist";
createqod.Number_of_Change_Requests__c=0;
createqod.date__c=date;
createqod.Final__c="True";
createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";

sforce.connection.create([createqod]);

//creating Grand Child Record here

var createrc = new sforce.SObject("Root_cause__c"); 
//createrc.Name="Root Cause"+" - "+"Final";
createrc.Project_Name__c="{!Project__c.Id}";
createrc.TaskName__c=    //how to give value here this is the parent id of the grand child record
createrc.Apex_context__c="true";
createrc.Final__c="True";
createrc.Launch_date_delay__c=0;
createrc.date__C=date;
//createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";
sforce.connection.create([createrc]);



parent.location.href = url;

}

 

 

global class CreateRootCause implements Database.Batchable<sObject>,
Schedulable {

public String Query;
global CreateRootCause(){

String ProjectQuery = 'Select Id,Name,Dev_Lead_User__c from Project__c where Overall_Project_Status__c NOT IN (\'Not Started\',\'On hold\') AND Project_TQL_Phase__c !=\'1. Kick-off\' AND Project_State__c IN(\'Active\')';

        
        
        this.Query=ProjectQuery;         
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(Query);
    }
    
    global void execute(Database.BatchableContext BC, List<SObject> scope)
    {
        List<Project__c> ProjectList =(Project__c[]) scope; 
                               
    
    for(project__c prj: ProjectList)
    { 

        List<Task__c> Lsttask=new List<Task__c>();
        Lsttask=[Select id,project__c from Task__c where project__c=: prj.Id];  
        List<Root_Cause__c> lstRC=new List<Root_Cause__c>();
    for(Task__c thistask: Lsttask)
        {
            
            Root_Cause__c RCDel= new Root_Cause__c();
            RCDel.TaskName__c=thistask.Id;
            RCDel.Date__c=System.Today();  
            RCDel.Final__c=true;
            RCDel.Project_Name__c=thistask.Project__c;
            RCDel.Launch_Date_Delay__c=0; 
            RCDel.Dev_Lead__c=prj.Dev_Lead_User__c;     
            lstRC.add(RCDel);     
            //lsttask.add(thistask);
        }    
  
     insert lstRC;
    }
 
}
global void finish(Database.BatchableContext BC){
}
  

                //Execute batch class with default constructor from schedular
    global void execute(SchedulableContext sc) {
        
        
       try {
    
         database.executeBatch(new CreateRootCause());

        }
        catch (Exception e) {
            System.debug('There are no jobs currently scheduled. ' + e.getMessage()); 
        } 
   }   
    
}

How to write test class for the above code..please help me on this...

Hi All,

I have two object in the related list and if Approal Status on both the object changes to "Approved " then the Project_State__c field on the parent object changes to "Closed".

 

I have written the trigger but It's not working...please help me

 

trigger Update_Project_State on Project__c (before update) {

 

for(Project__c Prj:trigger.New){

 List<Quality_of_Delivery__c> Lstqod= new LIST<Quality_of_Delivery__c>();//object-1 MD relation

 List<Root_Cause__c> LstRC= new LIST<Root_Cause__c>();       //object-2 lookup    

 

Lstqod=[Select project__c,Final__c,Approved_Status__c from Quality_of_Delivery__c where project__c=: prj.Id];//Query qod      

 

LstRC=[Select Project_Name__c,Final__c,Approval_Status__c from Root_Cause__c where Project_Name__c=: j.Id];               

List<Project__c> prjupdate= new List<Project__c>();

            if(LstRC!=null){        for(Root_Cause__c r:LstRC){  

            if(r.Approval_Status__c=='Approved' && r.Final__C==True)  

             {                

              if(Lstqod!=null){     

                                  for(Quality_of_Delivery__c q:lstqod)  {    

                                            

                            if(q.Approved_Status__c=='Approved' && q.Final__c==True){

                                                             

                                   if(prj.Project_State__c=='Active'){                         

                                                     prj.Project_State__c='Closed';    

                                                     prjupdate.add(prj);      

                               }                                                                                                      

                           else if(prj.Project_State__c=='In Cancellation')

                                          {                                 

                                  prj.Project_State__c='Cancelled';                             

                                     prjupdate.add(prj);                              

   }                                                                                                                                                                       

   }

}                                                                     

update prjupdate;                                                                                                                                   

        }       

        }                                          

    }       

   }                                                               

}

}

trigger updateDev_Lead on Project__c(after update) { 

          for(project__c prj: trigger.new)     {

 

    if(trigger.oldmap.get(prj.Id).Dev_Lead_User__c!=trigger.newmap.get(prj.Id).Dev_Lead_User__c) { 

   List<Quality_of_Delivery__c> Lstqod=new List<Quality_of_Delivery__c>();

    Lstqod=[Select project__c,Name,Dev_lead__c from Quality_of_Delivery__c where project__c=: prj.Id];         List<Quality_of_Delivery__c> qodToupdate=new List<Quality_of_Delivery__c>();

 

    for(Quality_of_Delivery__c thisqod: Lstqod)         {

                            {      

               thisqod.Dev_lead__c=prj.Dev_Lead_User__c;   

                

                    qodToupdate.add(thisqod);    

             }

        }

    if(!qodToupdate.isempty()){

           update qodToupdate;  

      }  

     }   

        }

}

Hi,

I have two object QOD__c--> child object, Approval_Status__c is a field on this object

Project__c--> Parent Object, Project_State__c is a field on this object.

 

I'm writting a trigger whenevr Approval_Status__c changes and equal to Approved then update the Project__State__c to "Closed"

 

below is the trigger but m getting error on it...

trigger Populate on Quality_of_Delivery__c (after update) {

List<Project__c> Lstprj=new List<Project__c>(); Set<Id> PrjId =new Set<Id>();

Lstprj=[Select Id from Project__c];

for(Project__c proj : lstprj){

PrjId.add(proj.Id);

}

    Map<Id,Project__c> prj = new Map<Id, Project__c>([select Project_State__c,Id from project__c where id in :prjid]);//Getting error here..DML requires SObject or SObject list type: MAP<Id,Project__c> at line 30 column 13 

 

      for(Quality_of_Delivery__c q: Trigger.new)  

{  

 

if(trigger.oldmap.get(q.Id).Approved_Status__c!=trigger.newmap.get(q.Id).Approved_Status__c)  

 

    {  

 

    if(  trigger.newmap.get(q.Id).Approved_Status__c=='Approved'){

                     prj.get(q.Project__c).Project_State__c='Closed';      

                          }      

      }         

    update prj;  

        

                      }

  }

 

please look into this

I have a situation like...I need to create a cusstom button on parent object and whenevr this button is clicked it should go to the child object and check some fields  and then update the field in parent object based on some condition.plz help me on this

Hi, I have written a trigger to update the grandchild whenevr the field in grand parent object updated..this trigger is however not updating the field ..please help me on this

 

trigger updateDev_Lead on Project__c(after update)

{          

 

for(project__c prj: trigger.new)

    {   

 

  if(trigger.oldmap.get(prj.Id).Dev_Lead_User__c!=trigger.newmap.get(prj.Id).Dev_Lead_User__c)

 

{  

 

 List<Task__c> Lsttask=new List<Task__c>();  

 

 

   Lsttask=[Select id,project__c from Task__c where project__c=: prj.Id]; 

 

          for(Task__c thistask: Lsttask)

        {      

 

 List<Root_Cause__c> lstRc=new List<Root_cause__c>();   

 

  lstRc=[select id,Dev_Lead__c from Root_Cause__c where id =:thistask.id];

 

    List<Root_cause__c> RcToupdate=new List<Root_cause__c>();

 

                for(Root_cause__c thisRc:lstRc)     

    {      

               thisRc.Dev_lead__c=prj.Dev_Lead_User__c;  

                                      RcToupdate.add(thisRc);     

 

            }     

   

    if(!RcToupdate.isempty()){ 

          update RcToupdate;   

     }  

   }  

}     

     

}

}

public class UpdateTask{ public static Boolean stopDup = false;

public void insertRootCause(List<Task__c> lstTask)

{

set<Id> Ids=new set<Id>();

map<id,id> mapparent=new map<id,id>();

//for(Task__c tsk:trigger.new)

{ //ids.add(tsk.Project__c);}

 

for(project__c prj: trigger.new) // getting error here..please help as why this error is comimg..I'm trying to get parent's field value here which will be paste in the child of this object

{

mapParent.put(prj.id, prj.Dev_Lead_User__c);

}

if(!stopDup){

 

List<Root_cause__c> lstRC=new List<Root_Cause__c>();

               for(Task__c t:lstTask){

                     

        // Project__c project = prj.get(t.project__c);

          Root_Cause__c RCDel= new Root_Cause__c();

           System.debug('Im Inside 123----->'+t); 

           RCDel.TaskName__c=t.Id;  

           system.debug(t.TQL_Phase__c=='6.Launch'); 

                      RCDel.Date__c=System.Today();

            RCDel.Launch_Date_Delay__c=0;    

         RCDel.Task_Delay__c=0;         

    RCDel.Dev_Lead__c= mapParent.get(t.Project__c);           

               lstRC.add(RCDel);       

                  }       

if(lstRC.size()>0){

    insert lstRC;   

  stopDup = true;    

}    

  }  

   }  

         

  }

hi I have a requiremnt like this

 

whenevr a grand child is created(Created through trigger on parent obj) populate a user field (say Dev_Lead__c) from grand Parent object field( Dev_Lead_User__c)...and whenevr this field updated (Dev_Lead_User__c) of rand parent then again update this field on grand child object...

 

please help me on this trigger

H,

how do i write test class for the below trigger..I have nevr written test class..plz help

 

trigger CloneTemplateTasks on Project__c(after Insert) {

List<Project__c> lstPrj = new List<Project__c>();//create an empty list of Project Set<String> setType = new Set<String>();//Set for Storing Project type Set<Id> setPrjId = new Set<Id>(); // Set for Storing Projectids List<Task__c> insertlst = new list<Task__c>(); // List of Task to insert

 

for(Project__c proj : Trigger.new){

setType.add(proj.Project_Type__c);

}

System.debug('setType----->'+setType);

List<Project_Template__c> lstTemplate = [SELECT Template__c FROM Project_Template__c where Template__c !=null and Project_Type__c in:setType];

System.debug('lstTemplate----->'+lstTemplate);

for(Project_Template__c tempObj : lstTemplate){

setPrjId.add(tempObj.Template__c);

}

System.debug('setPrjId----->'+setPrjId);

List<Task__c> lsttask = [select id,Name,Project__c,Actual_completion_date__c,TQL_Phase__c,Key_TQL_Milestone__c,Comments__c,Owner__c,Target_date__c from Task__c where Project__c in :setPrjId ];

System.debug('lsttask ----->'+lsttask);

for(Project__c proj : Trigger.new) {

for(Task__c t : lsttask) { Task__c tsk = new Task__c(); tsk = t.clone(); tsk.Project__c = proj.id; insertlst.add(tsk); }

}

System.debug('insertlst----->'+insertlst);

insert insertlst;

 

 

 

}

I'm basically just learning as I go here - so bear with me!

 

I have a custom button on a custom object detail page that when clicked, I would like for it to create a child record and then update the lookupfield with the newly created child record.id on the parent record. 

 

Here is the code I have - the first part works fine - the record creates seamlessly.  The second part updating the lookup field does not work  - I've altered, googled, altered, studied, and altered again with absolutely nothing working.

 

{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")} {!Partnership_Employees__c.Employee_Onboarding__c}

var copyonboarding = new sforce.SObject("Employee_Onboarding__c"); 
copyonboarding.Partnership_Employee__c = "{!Partnership_Employees__c.Id}"; 
copyonboarding.Name = "{!Partnership_Employees__c.Employee__c }";
copyonboardingID = copyonboarding.get("ID");

sforce.connection.create([copyonboarding]);

//update employee record
var employee = new sforce.SObject("Partnership_Employees__c")
employee.Employee_Onboarding__c = copyonboardingID;
sforce.connection.update([employee]);

window.alert("Employee Onboarding Created"); 
window.location.reload();