• Rahul S.ax961
  • NEWBIE
  • 125 Points
  • Member since 2011

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 66
    Replies

Hi All,

 

Hope someone can help as I'm still new to developing and trying to learn.

 

I have created a trigger to create a task when a contact record is saved and certain fields are filled in. However, this works fine but if someone goes into the record later and updates some other fields and saves because the fields are already filled in it creates another task. 

 

How can I get the code below to recognise that if a task called '30 Day Call' is already created against the contact to stop and not create another duplicate task?

 

 

trigger AssignNewMemberTask on Contact (after update) {
    List<Task> taskList = new List<Task>();
    for(integer i=0; i<trigger.new.size(); i++)
    {

        if ((trigger.new[i].Joined__c==true)&&(trigger.new[i].Joined_Date__c!=NULL)) {
         Task t = new Task(
         Subject = '30 Day Call',
         WhoId = trigger.new[i].id,
         Description = 'Call this Contact.',
         Priority = 'High',
         Status = 'Not Started',
         ActivityDate = trigger.new[i].Joined_Date__c+30,
         ReminderDateTime = System.now().addDays(2));
 
             if(trigger.new[i].Vistage_MSC__c!=null){
             t.OwnerId = trigger.new[i].Vistage_MSC__c;
             }else{
             t.OwnerId = '005E0000000YhNn';
             }
         taskList.add(t);
        }


    }
    insert taskList;
}

 

 

Many thanks

Kev

I have a trigger that fires on Task after insert, update and delete.  The trigger calls a static method that passes in the trigger.new collection.

 

The trigger code runs fine if I'm editing just one Task record at a time, but if I use dataloader to update in bulk, then it doesn't process correctly.

 

Here is my method:

 

private static void doHoursCompletedHoursRemaining(List<Task> inNew)
    {
    	Set<Id> pmtlIds = new Set<Id>();
        for (Task t : inNew) {
        	String stringWhatId = '' + t.WhatId;
        	if (t.WhatId != null) {
        		if (stringWhatId.substring(0,3) == 'a0f') {
        			pmtlIds.add(t.WhatId);
        		}
        	}
        }
        
        //Gather all Data
        List<Project_Management_Task_List__c> lstPMTLs = new List<Project_Management_Task_List__c>([Select Id, Hours_Remaining__c, Actual_Hours_Completed__c, (Select Id, Hours_Completed__c, Hours_Remaining__c  From Tasks) From Project_Management_Task_List__c Where id in :pmtlIds]);
    	
    	if (lstPMTLs.size() > 0) {
    		Map<Id, Task> mapTask = new Map<Id, Task>([Select WhatId, Hours_Remaining__c, Hours_Completed__c From Task Where WhatId in :lstPMTLs]); 
    		
    		List<Project_Management_Task_List__c> PMTLsToUpdate = new List<Project_Management_Task_List__c>();
    		for (Project_Management_Task_List__c pmtl : lstPMTLs) {
    			Decimal Remaining = 0;
    			Decimal Completed = 0;
    			if (pmtl.Tasks.size() > 0) {
    				for (Task t : mapTask.values()) {
    					for (Integer i = 0; i < lstPMTLs.size(); i++) {
    						Remaining += mapTask.get(t.Id).Hours_Remaining__c;
    						Completed += mapTask.get(t.Id).Hours_Completed__c;
    					}
    				}
    			}
    			pmtl.Hours_Remaining__c = Remaining;
    			pmtl.Actual_Hours_Completed__c = Completed;
    			PMTLsToUpdate.add(pmtl);
    		}
    		update PMTLsToUpdate;
    	}
    }

 

All the code is doing is totaling the Hours Completed and Hours Remaining of all Tasks related to a specific Project Management Task List record. 

 

If I run in bulk, it totals all the tasks records and doesn't differentiate between different Project Management Task List records.  I was trying to use the WhatId as the key in the map and then use the containsKey method, but that didn't seem to work?

 

Thanks for any help.

I got a error message with my Trigger. I just want to do, if Quote's status is ''Accepted', so Opportunity's stage change to 'Closed Won' automaticlly.

 

trigger test on Quote(after insert, after update) {
List<Opportunity> stageToUpdate = new List<Opportunity>();

for(Quote quo : trigger.new)
{if (quo.status == 'Accepted')
stageToUpdate.add(new Opportunity(Id=quo.Id, StageName = 'Closed Won'));
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}

 

Error message,

execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: 0Q09000000009qYCAQ: Trigger.test: line 6, column 38

Dear all,

 

I am very new and sforce apex coding with very little knowledge about programming - but I am very keen to learn!

 

Below is a very simple scenario which I am trying is achieve:

 

My requirements is that everytime a new record is inserted or updated to "Context" custom object, I wish to have the status of all records (new and existing) records in "Context" to change to Inactive

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
trigger ChangeContextStatus on Context__c (after insert, after update) 

{

List <Context__c> oCT = [select Status__c, from Context__c 
WHERE End_Markets__c = 'Singapore Domestic'];

    for (Context__c ct: oCT)
    {
                   ct.Status__c = True;
                
    }
    update oCT;
}

If anyone could help, thanks!

Hi,

 

Consider a scenario, Account has a Country field.

Depending on the value in Country field, values will be populated to Account Region (Custom Picklist Field).

Picklist Values - NAM, SAM, EMEA & APAC.

The values must be set dynamically, so is there any app or webservice for doing the same.

Any help is Appreciated.

 

 

Hi,

 

I have few questions related to custom buttons and would like know Which of the following are possible:

1) Showing a custom button in edit mode.

2) Hiding a custom button in detail page.

 

Any help is highly Appreciated,

Hi all,

 

I'm building a custom report for the first time, had stuck in some place.

 

Scenario is:

I have a custom object named 'Liscence' with field Name and Status (Picklist),

and there are multiple lookup fields to itself (Liscence1, Liscence2, Liscence3).

 

I'm able to show Name And Status of particular record along with lookup field names (Liscence1, Liscence2, Liscence3),

but also want to show Status fields of Lookup fields (Liscence1, Liscence2, Liscence3), 


Is there any way to do that??


Hi all,

 

Im building a summary report, its almost done but need some help in its modification.

My report is based on custom object History__c.

Showing Name of record and boolean field Status__c to check whether record is closed or not.

and there are multiple fields which are lookup to itself (History__c), so here can i show Status__c of those lookup field's.

 

desired report will look some thing like this:

 

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

Name  - Status__c - Related_History1.Name - Status__c(of 1) - Related_History2.Name - Status__c(of 2) - Related_History3.Name - Status__c(of 3)

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

 

Any help will be highly appreciated,

 

Thanks

Hi All,

I am trying to update a Lookup Field on an Account with a Trigger.  Essentially I have a Custom Object (Box_Assumptions_c) related to an Account (Account1) and I want to update an a Custom Field (X9Box_Assumptions__c) on a different Account (Account2) with a Box Assumption that is related to Account1 by using the Owner's (Portal User) Contact Account (Account1).

 

trigger updatecustomer9box on Account (before insert, before update) {
    
    //Get Account ID of the current record.
    set<id> acctid = new set<id>();
    for (account a : trigger.new)
    acctid.add(a.owner.contact.account.id);
    
    map<id, box_assumptions__c> boxmap = new map<id, box_assumptions__c>([select id 
                                                                     from box_assumptions__c
                                                                     where account__c in : acctid]);
    for (account a : trigger.new){
        box_assumptions__c thisbox = boxmap.get(a.x9box_assumptions__c);
        a.x9box_assumptions__c = thisbox.id;
    }
}

 I am getting a Null Pointer Exception so any advice would be helpful!

 

-Thanks in advance!

 

Hi All,

 

Hope someone can help as I'm still new to developing and trying to learn.

 

I have created a trigger to create a task when a contact record is saved and certain fields are filled in. However, this works fine but if someone goes into the record later and updates some other fields and saves because the fields are already filled in it creates another task. 

 

How can I get the code below to recognise that if a task called '30 Day Call' is already created against the contact to stop and not create another duplicate task?

 

 

trigger AssignNewMemberTask on Contact (after update) {
    List<Task> taskList = new List<Task>();
    for(integer i=0; i<trigger.new.size(); i++)
    {

        if ((trigger.new[i].Joined__c==true)&&(trigger.new[i].Joined_Date__c!=NULL)) {
         Task t = new Task(
         Subject = '30 Day Call',
         WhoId = trigger.new[i].id,
         Description = 'Call this Contact.',
         Priority = 'High',
         Status = 'Not Started',
         ActivityDate = trigger.new[i].Joined_Date__c+30,
         ReminderDateTime = System.now().addDays(2));
 
             if(trigger.new[i].Vistage_MSC__c!=null){
             t.OwnerId = trigger.new[i].Vistage_MSC__c;
             }else{
             t.OwnerId = '005E0000000YhNn';
             }
         taskList.add(t);
        }


    }
    insert taskList;
}

 

 

Many thanks

Kev

I'm working on a project involving a callout to a service that returns a JSON result. Using JSONObject from code share I can parse the response as long as it's very small, but I am getting a Too Many Script Statements error on a lot of the responses. Making the response smaller from the other service isn't an option.

 

Anyone have any suggestions of ways I can handle parsing a larger JSON response?

Hi Developers. 

 

Here is my requirement, As to How can I attach the record ID to the Link. I am displaying list of product code and Product name as link on a VF page and its a custom comtroller. How do i pass on the link so that once when click the product code or name it redirects to the record

Here is my VF code.

<apex:page controller="ProductPriceBook23" tabStyle="Product2">

<apex:pageBlock >
         <h1><u>Report : Products and PriceBooks for Region= NA and Product Family=PRODUCT </u>  </h1>
 </apex:pageBlock> 
    



    <apex:pageBlock >
        <apex:pageblockTable value="{!products}" var="product">
                    <apex:column headerValue="Product Code" width="150">
                    <apex:outputLink value="https://c.cs4.visual.force.com/">  {!product.prod.ProductCode} </apex:outputLink>
                    </apex:column>
                    
                     <apex:column headerValue="Product Name" width="500">
                    <apex:outputLink value="https://c.cs4.visual.force.com/">  {!product.prod.name} </apex:outputLink>
                    </apex:column>

 Thanks All

 

Hi All 

 

I have built a VF Page which displays list of products up to 1000. I need to create a Search bar where we can type product name and get the desired PRODUCT. 

 

I need help on it please. 

 

trigger LockStatus on Case (After update) {
    for(Case ca:Trigger.new){
         if(ca.New__c == True && ca.O1L__c == False && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && (ca.Status == 'New')){
            Trigger.new[0].Status.addError('Can not choose less than Open 1st Level');  // Open 1st Level
        } 
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level'))){
            Trigger.new[0].Status.addError('Can not choose less than Open 2nd Level');  // Open 2nd Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level')) ){
            Trigger.new[0].Status.addError('Can not choose less than In Progress 1st Level'); //In Progress 1st Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level'))){
            Trigger.new[0].Status.addError('Can not choose less than In Progress 2nd Level'); //In Progress 2nd Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == True  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level'))){
            Trigger.new[0].Status.addError('Can not choose less than Resolved'); //Resolved
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == True  && ca.Reso__c == True && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level') || (ca.Status == 'Resolved'))){
            Trigger.new[0].Status.addError('Can not choose less than Closed'); //Closed
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == True  && ca.Reso__c == True && ca.Close__c == True && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level')  || (ca.Status == 'Resolved') || (ca.Status == 'Closed'))){
            Trigger.new[0].Status.addError('Can not choose less than Cancle'); //Cancel
        }
}
}

 

@isTest
private class TestLockStatus  {
   static testMethod void myUnitTest() {   
      Case ca = new Case(Origin = 'Phone',Status = 'New',Subject = 'A',Type = 'Dummy',New__c = true,O1L__c = False,O2L__c = False,IP1L__c = False,
      IP2L__c = False,Reso__c = False,Close__c = False);
      test.startTest();
             try {      insert ca; update ca;    }
                 catch (Exception e) {                
                        System.debug('Can not choose less than Open 1st Level'); 
                    } 
       test.stopTest();  
     }

 Thank you so much.

 

  • June 13, 2011
  • Like
  • 0

Hi,

I need to highlight a column after clicking on it...

 

Can any one help me out..??

 

 

Thanks & Regards,

Raju.B

Hi

 

I have a requirement like there is an object 'A' and object 'B' those having same picklist suppose say p1 and p2.

 

there is a lookup of object 'B' in object 'A', when user selects some value in the lookup then those picklist values of object 'B' should get populated in Object 'A' 

 

Please help me out its very urgent

 

 

Regards,

Praveen.

Hi,

 

I have a use case where i have to check if the record has a date overlapping criteria. I have a trigger, but it kinda works only for one record and is not bulkified.

I am hitting a road block to bulkify the trigger. Any ideas?

 

trigger datesCannotOverlap on Tip__c (before Insert, before Update) {
  
  
  Tip__c newTips=New Tip__c();  
  if(trigger.isInsert || trigger.isUpdate){
  
      newTips=Trigger.New[0];
      
      
  }
  

   
   
   List<Tip__c> overlaps=[select Tip_Start_Date__c, Tip_End_Date__c, Business_Unit__c 
 from Tip__c
  where 
  (
      (Tip_Start_Date__c >= :newTips.Tip_Start_Date__c AND Tip_Start_Date__c <= :newTips.Tip_End_Date__c) OR
      (Tip_end_Date__c  >= :newTips.Tip_Start_Date__c AND Tip_End_Date__c  <= :newTips.Tip_End_Date__c) OR
      (Tip_Start_Date__c <= :newTips.Tip_Start_Date__c AND Tip_end_Date__c  >= :newTips.Tip_end_Date__c)
  )
  and Business_Unit__c=:newTips.Business_Unit__c];


System.Debug('overlaps >>>>>'+overlaps);

if(overlaps.Size() > 0){
    newTips.addError('Dates Overlapping with other Tips. please choose New dates');
}
   
   
}

 

 

Thanks,

Sales4ce

Hello,

 

I am fairly new to wirte an APEX code for this query. Hope someone will share code or comments.
if we create a booking & opportunity and add opportunity lie item, enable scheduling and define revenue schedule date with monthly installment.

Currently, user are keep changing revenue schedule date in a past or future which get impact on monthly revenues dashboard.

 

Now, we would like to restric user to changing revenue schedule date in past. how???

Thanks for help!