• Kr ram
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 12
    Replies
before insert on task object -to get account/con/lead ids into task custom fieldhello gurus:
Goal : To populate the Account ID ,Contact ID,Lead ID into a custom field in the task object (i.e)

If task is linked to an account get the Account id and write it to a custom field in task object
If task is linked to an contact get the Contact id and write it to a custom field in task object
If task is linked to an lead get the lead id and write it to a custom field in task object.

this is the code ,but i get the "attempt to deference a null pointer exception" any suggestions appreciated!



trigger updateAccountFromTask on Task (before insert)
{
    String account_prefix = Schema.SObjectType.Account.getKeyPrefix();
    String contact_prefix = Schema.SObjectType.Contact.getKeyPrefix();

    Map<Id,Account> accountMap = new Map<Id,Account>();
    Map<Id,Contact> contactMap = new Map<Id,Contact>();
    Set<id> Ids = new Set<id>();
        for (Task tk: Trigger.new) 
        {
        Ids.add(tk.WhatId);
       Ids.add(tk.WhoId);
        }
    Map<id,Account> accountMap2 = new Map<id,Account>([Select Id,Full_Account_ID__c from Account Where Id in :Ids]);
    Map<id,Contact> accountMap3 = new Map<id,Contact>([Select Id,Name from Contact Where Id in :Ids]);
        for (Task t: Trigger.new)
        if(t.Subject != null)//) || t.WhoId == null )//|| t.WhoId !=null*/) 
        
        //&& t.Status == 'Completed - Move to Demo'&& ((String)t.WhatId).startsWith(account_prefix))
        {
        Account a = accountMap2.get(t.WhatId);
        Contact b = accountMap3.get(t.WhoId);
         t.Account_id__c= a.Full_Account_ID__c ;
        // t.Contact_Id__c= b.Name;
        //a.Task_Source__c = t.Task_Source__c;
       // a.Demo_Status__c = t.status;// this is the line its throwing exception
        accountMap.put(a.id,a);
       // contactMap.put(b.id,b);
        }
            try
            {
                update accountMap.values();
              //  update ContactMap.values();
            }
                catch (system.Dmlexception e) 
                {
                system.debug (e);
                }
                }
  • February 03, 2016
  • Like
  • 0
hello gurus:
Goal : To populate the Account ID ,Contact ID,Lead ID into a custom field in the task object (i.e)

If task is linked to an account get the Account id and write it to a custom field in task object
If task is linked to an contact get the Contact id and write it to a custom field in task object
If task is linked to an lead get the lead id and write it to a custom field in task object.

this is the code ,but i get the "attempt to deference a null pointer exception" any suggestions appreciated!



trigger updateAccountFromTask on Task (before insert)
{
    String account_prefix = Schema.SObjectType.Account.getKeyPrefix();
    String contact_prefix = Schema.SObjectType.Contact.getKeyPrefix();

    Map<Id,Account> accountMap = new Map<Id,Account>();
    Map<Id,Contact> contactMap = new Map<Id,Contact>();
    Set<id> Ids = new Set<id>();
        for (Task tk: Trigger.new) 
        {
        Ids.add(tk.WhatId);
       Ids.add(tk.WhoId);
        }
    Map<id,Account> accountMap2 = new Map<id,Account>([Select Id,Full_Account_ID__c from Account Where Id in :Ids]);
    Map<id,Contact> accountMap3 = new Map<id,Contact>([Select Id,Name from Contact Where Id in :Ids]);
        for (Task t: Trigger.new)
        if(t.Subject != null)//) || t.WhoId == null )//|| t.WhoId !=null*/) 
        
        //&& t.Status == 'Completed - Move to Demo'&& ((String)t.WhatId).startsWith(account_prefix))
        {
        Account a = accountMap2.get(t.WhatId);
        Contact b = accountMap3.get(t.WhoId);
         t.Account_id__c= a.Full_Account_ID__c ;
        // t.Contact_Id__c= b.Name;
        //a.Task_Source__c = t.Task_Source__c;
       // a.Demo_Status__c = t.status;// this is the line its throwing exception
        accountMap.put(a.id,a);
       // contactMap.put(b.id,b);
        }
            try
            {
                update accountMap.values();
              //  update ContactMap.values();
            }
                catch (system.Dmlexception e) 
                {
                system.debug (e);
                }
                }
  • February 02, 2016
  • Like
  • 0
Hello gurus,

the below apex trigger i guess can hit the governor limits and may be be optimized for bulk updates,
Any changes you would recommend? thank you !
---------------------------------------------------------------------------------------------
trigger abc on abc__c (after insert, after update) {
 
    for(abc__c project : Trigger.New)
    {
               List< Project_Task__c> tasklist = new List< Project_Task__c>    (
               [SELECT id, name, IsComplete__c  FROM Project_Task__c
               WHERE (name LIKE '%big deal Call%'     
                                             AND IsComplete__c = FALSE
                                             AND abc__c = :project.id]
               );
 
               for (Project_Task__c task : tasklist)
               {
                              task. IsComplete__c = true;
               }
               update tasklist;
      
   }
}
----------------------------------------------------------------------------------------------------
  • September 02, 2015
  • Like
  • 0
Hello gurus,

I am trying to perform a mass update using the data loader,and the below code is throwing duplicate IDs error,
i know i am using SET ,but any pointers on using MAP so that i can fix the error.
All i am doing is copying 2 fields from child(appl__c) to parent(contact)  where the parent is a lookup field in the child table.
Any pointers? thank you!

trigger abre on Appl__c (after insert, after update) {

    Set<Contact> parents = new Set<Contact>();
  
    for (Appl__c child : trigger.new) {
        if(child.Id != null){
            parents.add(new Contact(Id = child.Contact__c, Admit_Type__c = child.Admit_Type__c,Admit_Term__c=child.Admit_Term__c));
        }
    }

    if(!parents.isEmpty()){
       
        List<Contact> toUpdate = new List<Contact>();
        toUpdate.addAll(parents);
        update toUpdate;
    }
    }
  • August 03, 2015
  • Like
  • 0

Hello Gurus,

 

I have a standard object

Scenario:i need to update a contract date__c  custom field on the same object only if the date value is made NULL by external integration  with the previous date value from the same field  if populated,and if previous DATE value is NULL do nothing

 

i know a trigger.old and getmap (id) could be used but i need the exact "after update" trigger syntax,

 

i used this but i get an after update stack  error,

please note i need an after update trigger

 

trigger abc_123 on Asset (after update) {

for (Asset asse : Trigger.new) {

Asset oldAsset = Trigger.oldMap.get(asse.ID);

if ( asse.contract_Date__c==null) {

asse..contract__c = oldAsset..contract_Date__c;

}
}

 

i know this is simple but my brain cells are out on a friday evening,any input appreciated. thank you!

  • September 14, 2013
  • Like
  • 0

Hello,

I have a master object- Parentobj1

Detail child obj-childobj1 in a master detail relationship

 

When i create a NEW Record using the the NEW button in the  Parentobj1,i want to add the childobj1 fields in the EDIT page of the 

Parentobj1 ,itself

 

Currently the process  is to create the parentobj1 record using the NEW button  and Save It and then NAVIGATE to the child Related list click new enter and save it,

 

I know a a VF page can accomplish it but i want a simple solution.

any thoughts?

 

  • February 22, 2013
  • Like
  • 0

Contract id is a text field but i wanted to accept only numbers only 11 digits allowed,i do NOT want to change the field type but the below validation rule solution works ,but how do i restrict so that it accepts only 11 digits,any other thoughts appreciated as well.. thanks

 

NOT(ISNUMBER( Contract_ID ))

  • February 20, 2013
  • Like
  • 0

Hello Experts!

I am not very familiar  to outbound message using workflows 

 

I need to pass some parameters from a custom object say serial number ,product type and product family from Salesforce  to an end point URL (the end point URL is within our firewall) to get the License activation code,

i know i can accomplish this using outbound message using workflows ,please clarify if i am wrong 

If i can accomplish this using an outbound message, how can i retreive the details from the outbound message response to a custom field? 

In this example i get a license activation code back from the outbound message i want to populate it back to the custom object record from where the outbound message was sent,how do i accomplish this?

 

IF this is not possible using Workflow outbound message ,should i write a custom webservice Apex class?,if you can point to any examples that would be appreciated!

 

Please reply incase you have trouble understanding the question

thanks!

Hello gurus,

 

I have this scenario to tackle 

Have two custom objects 

Custom__A

Custom__B

 

both  the custom objects are related using a lookup.

When the user is the custom__B record detail the following needs to be done

 

1)Provide a custom button in Custom__B detail page

2)when the button is clicked from Custom__B page, open a new page with a link to create a new record for custom__A

3)and when the user saves the Custom__A record -associate the Custom__A record with  Custom__B record

 

I know the possible answers are create a custombutton and and a trigger to associate records,

 

Any sample apex examples greatly appreciated.

thanks!

  • February 05, 2011
  • Like
  • 0
hello gurus:
Goal : To populate the Account ID ,Contact ID,Lead ID into a custom field in the task object (i.e)

If task is linked to an account get the Account id and write it to a custom field in task object
If task is linked to an contact get the Contact id and write it to a custom field in task object
If task is linked to an lead get the lead id and write it to a custom field in task object.

this is the code ,but i get the "attempt to deference a null pointer exception" any suggestions appreciated!



trigger updateAccountFromTask on Task (before insert)
{
    String account_prefix = Schema.SObjectType.Account.getKeyPrefix();
    String contact_prefix = Schema.SObjectType.Contact.getKeyPrefix();

    Map<Id,Account> accountMap = new Map<Id,Account>();
    Map<Id,Contact> contactMap = new Map<Id,Contact>();
    Set<id> Ids = new Set<id>();
        for (Task tk: Trigger.new) 
        {
        Ids.add(tk.WhatId);
       Ids.add(tk.WhoId);
        }
    Map<id,Account> accountMap2 = new Map<id,Account>([Select Id,Full_Account_ID__c from Account Where Id in :Ids]);
    Map<id,Contact> accountMap3 = new Map<id,Contact>([Select Id,Name from Contact Where Id in :Ids]);
        for (Task t: Trigger.new)
        if(t.Subject != null)//) || t.WhoId == null )//|| t.WhoId !=null*/) 
        
        //&& t.Status == 'Completed - Move to Demo'&& ((String)t.WhatId).startsWith(account_prefix))
        {
        Account a = accountMap2.get(t.WhatId);
        Contact b = accountMap3.get(t.WhoId);
         t.Account_id__c= a.Full_Account_ID__c ;
        // t.Contact_Id__c= b.Name;
        //a.Task_Source__c = t.Task_Source__c;
       // a.Demo_Status__c = t.status;// this is the line its throwing exception
        accountMap.put(a.id,a);
       // contactMap.put(b.id,b);
        }
            try
            {
                update accountMap.values();
              //  update ContactMap.values();
            }
                catch (system.Dmlexception e) 
                {
                system.debug (e);
                }
                }
  • February 02, 2016
  • Like
  • 0
Hello gurus,

I am trying to perform a mass update using the data loader,and the below code is throwing duplicate IDs error,
i know i am using SET ,but any pointers on using MAP so that i can fix the error.
All i am doing is copying 2 fields from child(appl__c) to parent(contact)  where the parent is a lookup field in the child table.
Any pointers? thank you!

trigger abre on Appl__c (after insert, after update) {

    Set<Contact> parents = new Set<Contact>();
  
    for (Appl__c child : trigger.new) {
        if(child.Id != null){
            parents.add(new Contact(Id = child.Contact__c, Admit_Type__c = child.Admit_Type__c,Admit_Term__c=child.Admit_Term__c));
        }
    }

    if(!parents.isEmpty()){
       
        List<Contact> toUpdate = new List<Contact>();
        toUpdate.addAll(parents);
        update toUpdate;
    }
    }
  • August 03, 2015
  • Like
  • 0

Hello,

I have a master object- Parentobj1

Detail child obj-childobj1 in a master detail relationship

 

When i create a NEW Record using the the NEW button in the  Parentobj1,i want to add the childobj1 fields in the EDIT page of the 

Parentobj1 ,itself

 

Currently the process  is to create the parentobj1 record using the NEW button  and Save It and then NAVIGATE to the child Related list click new enter and save it,

 

I know a a VF page can accomplish it but i want a simple solution.

any thoughts?

 

  • February 22, 2013
  • Like
  • 0

Contract id is a text field but i wanted to accept only numbers only 11 digits allowed,i do NOT want to change the field type but the below validation rule solution works ,but how do i restrict so that it accepts only 11 digits,any other thoughts appreciated as well.. thanks

 

NOT(ISNUMBER( Contract_ID ))

  • February 20, 2013
  • Like
  • 0

Hello Experts!

I am not very familiar  to outbound message using workflows 

 

I need to pass some parameters from a custom object say serial number ,product type and product family from Salesforce  to an end point URL (the end point URL is within our firewall) to get the License activation code,

i know i can accomplish this using outbound message using workflows ,please clarify if i am wrong 

If i can accomplish this using an outbound message, how can i retreive the details from the outbound message response to a custom field? 

In this example i get a license activation code back from the outbound message i want to populate it back to the custom object record from where the outbound message was sent,how do i accomplish this?

 

IF this is not possible using Workflow outbound message ,should i write a custom webservice Apex class?,if you can point to any examples that would be appreciated!

 

Please reply incase you have trouble understanding the question

thanks!