function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BegginerBegginer 

Guidance on writing a trigger




Hi all, 

I'm learning triggers in salesforce and want some advice on understanding how to write a trigger for below scenario. what is the approach?
There are two objects Object1_c(Parent) and Object__c(child) having look-up relationship.

Summary:
Object__c has record types namely  "A" and "B".
Object__c has a field (currency) --> Myamount__c
Object__c has 2 picklislts --> Picklist_a__c and Pciklist_b__c
object1__c has a field(curreny_ --> amount__c

Scenario:

when amount__c(on Object1__c) is blank or null, and if record type is either A||B and Picklst_a__c and picklist__b is selected then Myamount__c should be required show be the error.

Thanks in advance.
 
Best Answer chosen by Begginer
rajat Maheshwari 6rajat Maheshwari 6
trigger ObjectTrigger on ObjectPar__c(before update)
  {
     Set<Id> st_ParentId = new set<id>();

for(ObjectPar__c obj : Trigger.new)
   {
   
           st_ParentId.add(obj.lookupField);
   }

List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,lookupField from ObjectCh__c where lookupField IN:st_ParentId]);



if(lst_objCh!=null && lst_objCh.size()>0)
  {
    

for(ObjectPar__c obj : Trigger.new)
  {
    
        if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && obj.Picklist_b__c=='Checked' && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB))

            {
                     obj.addError('My Name is Error');
            }
        }
  }



}


As per your scenario, when picklist b have value "Checked" and having child records related to that then trigger will fire to display error message , otherwise, No error will come.

Thanks

All Answers

LBKLBK
You don't need a trigger here.

What you need is a validation rule on Object__c to achieve this.

Here is  your validation rule.
 
AND(
ISNULL(Object1__r.amount__c),
NOT(ISPICKVAL(Picklst_a__c,"")),
NOT(ISPICKVAL(Picklst_b__c,"")),
ISNULL(Myamount__c))
As you can see, I didn't include the Record Type here because you have only two record types and both are eligible for this validation.

Hope this helps.
 
Waqar Hussain SFWaqar Hussain SF
You have to write trigger on Object1__c object. This may look like 
 
Trigger ObjectTrigger on Object__c(Before insert, before update){

	Map<Id, object1__c> object1Map = new Map<Id, object1__c>([Select Id, Name from object1__c]);
	
	for(Object__c obj : trigger.new){
		Object1_c ParentObj = object1Map.get(obj.Object1_c);
		if(ParentObj != null){
			if(obj.Picklst_a__c != null && obj.Picklst_b__c != null && obj.Myamount__c == null){
				obj.addError('My amount is requird...');
			}
		}
	
	}
}

 
BegginerBegginer
I have tried that it's not working, I don't think you can get parent field (amount__c) on the child object.

it throws out an error that the unknown function Object1__r.Amount__c check spelling. 
Waqar Hussain SFWaqar Hussain SF
Trigger ObjectTrigger on Object__c(Before insert, before update){

	Map<Id, object1__c> object1Map = new Map<Id, object1__c>([Select Id, Name, Amount__c from object1__c]);
	
	for(Object__c obj : trigger.new){
		Object1_c ParentObj = object1Map.get(obj.Object1_c);
		if(ParentObj != null){

// you can use amount field here ParentObj.Amount__c
system.debug('Amount:: '+ParentObj.Amount__c);
			if(obj.Picklst_a__c != null && obj.Picklst_b__c != null && obj.Myamount__c == null){
				obj.addError('My amount is requird...');
			}
		}
	
	}
}
rajat Maheshwari 6rajat Maheshwari 6

Hi,

Please use below code snippet : - 

 

trigger ObjectTrigger on Object__c (before insert,before update)
  {
     Set<Id> st_ParentId = new set<id>();

for(Object__c obj : Trigger.new)
   {
      st_ParentId.add(obj.lookupField);
   }

Map<Id,Object1__c> Object_1_Map = new Map<id,Object1__c>([Select Id,Name,Amount from Object1__c where Id IN : st_ParentId]);

for(Object__c obj : Trigger.new)
  {
     if(Object_1_Map!=null && Object_1_Map.containsKey(obj.lookupfield))
        {
            if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && Object_1_Map.get(obj.lookupField).Amount==null)

            {
                     obj.addError('Myamount__c should be required');
            }
        }
  }


Here in this code, 

1. lookupField refer to lookupRelationship field between two objects.

2. IdCorrespondingtoA refer to RecordType Id for A.

3. IdCorrespondingtoB refer to RecordTypeId for B.

Please Mark as best answer,if it works :)

BegginerBegginer
line 4 Throws an error invalid field Object1_c for Sobject Object__c
rajat Maheshwari 6rajat Maheshwari 6

Hi,

please check and do amendment accordingly -

Object__c  :  - Replace with API Name of child object.

Object1__c : - Replace with API Name of parent Object.

lookupfield : - Replace with relationshipField API

Could you please paste your code over here, ?

Thanks

 

rajat Maheshwari 6rajat Maheshwari 6

User-added image

Please let me know in case of confusion

Thanks

BegginerBegginer
My bad I got confused between the parent and child and got it wrong, here is the revised one 
There are two objects ObjectPar__c(Parent) and ObjectCh__c(child) having look-up relationship.

Summary:
ObjectPar__c has record types namely  "A" and "B".
ObjectPar__c has a field (currency) --> Myamount__c
ObjectPar__c has 2 picklislts --> Picklist_a__c and Pciklist_b__c
ObjectCh__c has a field(curreny_ --> amount__c)

Scenario:

when amount__c(on ObjectCh__c(childobject)) is blank or null, and if record type is either A||B and Picklst_a__c and picklist__b (on parent) is selected then Myamount__c should be required it cannot be blank
 
rajat Maheshwari 6rajat Maheshwari 6

Hi, Below is code snippet : - 

trigger ObjectTrigger on ObjectCh__c (before insert,before update)
  {
     Set<Id> st_ParentId = new set<id>();

for(ObjectCh__c obj : Trigger.new)
   {
      st_ParentId.add(obj.lookupField);
   }

Map<Id,ObjectPar__c> Object_Par_Map = new Map<id,ObjectPar__c>([Select Id,Name,RecordTypeId,Picklist_a__c,Picklist_b__c,Myamount__c from ObjectPar__c where Id IN : st_ParentId]);

for(ObjectCh__c obj : Trigger.new)
  {
     if(Object_Par_Map !=null && Object_Par_Map.containsKey(obj.lookupfield))
        {
            if(Object_Par_Map.get(obj.lookupfield).Picklist_a__c!=null && Object_Par_Map.get(obj.lookupfield).Picklist_b__c!=null && (Object_Par_Map.get(obj.lookupfield).RecordTypeId==IdCorrespondingtoA || Object_Par_Map.get(obj.lookupfield).RecordTypeId==IdCorrespondingtoB) && obj.amount__c==null)

            {
                     obj.addError('Myamount__c should be required');
            }
        }
  }

}
rajat Maheshwari 6rajat Maheshwari 6
please let me know,if you face still issue, Otherwise Mark as best Answer If it works :)
BegginerBegginer
the error should be on the parent object, first parent record is created by choosing the above record types, the picklists(picklist "just received") leaving Myamount blank and then the user has the option to create a child record from the related list. now in the child object, there is some picklists and amount field. if the user checks picklist and didn't enter the amount field and saved and when user come back on parent object and changes the picklist to "received"then the trigger should fire. 
BegginerBegginer
Hi all, 

I'm learning triggers in salesforce and want some advice on understanding how to write a trigger for below scenario. what is the approach?

There are two objects ObjectPar__c(Parent) and ObjectCh__c(child) having look-up relationship.

Summary:
ObjectPar__c has record types namely  "A" and "B".
ObjectPar__c has a field (currency) --> Myamount__c
ObjectPar__c has 2 picklislts --> Picklist_a__c and Pciklist_b__c( two values "checked" , "Received")
ObjectCh__c has a field(curreny_ --> amount__c)

Scenario:

if record type is either A||B and Picklst_a__c and picklist__b ("checked") (on parent) is selected then Myamount__c is not enter and record is saved, then user from the related list selects the child object and on the child object if amount__c(on ObjectCh__c(child object)) is blank or null, and saves the record and when user come to parent object and changes the Pciklist_b__c("Received ") then the trigger should fire.
rajat Maheshwari 6rajat Maheshwari 6
Hi,

Use this code which will fire on change of picklistb field


trigger ObjectTrigger on ObjectPar__c(before update)
  {
     Set<Id> st_ParentId = new set<id>();

for(ObjectPar__c obj : Trigger.new)
   {
     if(Trigger.oldMap.get(obj.id).Picklist_b__c != obj.Picklist_b__c)
           st_ParentId.add(obj.lookupField);
   }

List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,Amount__c,lookupField from ObjectCh__c where Amount__c = null && lookupField IN:st_ParentId]);



if(lst_objCh!=null && lst_objCh.size()>0)
  {
    

for(ObjectPar__c obj : Trigger.new)
  {
    
        if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) )

            {
                     obj.addError('Myamount__c should be required');
            }
        }
  }

}

Let me know if it works :)

Thanks
rajat Maheshwari 6rajat Maheshwari 6

Use and instead of && in soql query : - 

List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,Amount__c,lookupField fromObjectCh__c where Amount__c = null And lookupField IN:st_ParentId]);

Ajay mishraAjay mishra
Hi,

What i have understood from you requirement till now is.

You want to show error on parent record. when it is created and child records Amount field is null.

Let me correct you, if parent is not created yet how can a child exist.

So as per my understanding you should show the error on child when it is created.

And mention Error on child record using merge field which you want to be filled before child is created.

OR if you say that it should be shown after both the records are created. And should show error when parent is updated.

Please use  @rajat Maheshwari 6 code

please let me know if you want more help.

Thanks
Ajay Mishra
Email: mishraajay.m1@gmail.com
BegginerBegginer
Hi Rajat,

Thank you for quick turn around, code is not working properly, after checking all condition I found that even if I enter Myamount__c  value trigger is firing, actually requirement is not.It should fire only if amount__c on child is null and Myamount__c has a value it should not fire the error
rajat Maheshwari 6rajat Maheshwari 6
trigger ObjectTrigger on ObjectPar__c(before update)
  {
     Set<Id> st_ParentId = new set<id>();

for(ObjectPar__c obj : Trigger.new)
   {
     if(Trigger.oldMap.get(obj.id).Picklist_b__c != obj.Picklist_b__c)
           st_ParentId.add(obj.lookupField);
   }

List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,Amount__c,lookupField from ObjectCh__c where Amount__c = null && lookupField IN:st_ParentId]);



if(lst_objCh!=null && lst_objCh.size()>0)
  {
    

for(ObjectPar__c obj : Trigger.new)
  {
    
        if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && obj.Myamount__c ==null)

            {
                     obj.addError('Myamount__c should be required');
            }
        }
  }

}


Please let me know, your testing once again.

Thanks

BegginerBegginer
What if I want to implement on the records that are created after today to be effected with the trigger? where should I add that in the code?? 
rajat Maheshwari 6rajat Maheshwari 6

Begginer, please include this attribute in if condition :- 

obj.createdDate > 2017-02-15T00:00:00Z

Here 2017-02-15T00:00:00Z refer to YYYY-MM-DDThh:mm:ssZ

 

Please mark as best answer, It it works, otherwise let me know the issue

Thanks
Rajat Maheshwari

BegginerBegginer
comparison arguments must be compatible types: Datetime
rajat Maheshwari 6rajat Maheshwari 6

could you please post your code over here, so that quickly I can make amended 

 

BegginerBegginer
trigger ObjectTrigger on ObjectPar__c(before update)
 {
     Set<Id> st_ParentId = new set<id>(); 
for(ObjectPar__c obj : Trigger.new)
   {
     if(Trigger.oldMap.get(obj.id).Myamount__c != obj.Myamount__c )
           st_ParentId.add(obj.ObjectRe__c);
   }
 
List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,Amount__c,ObjectRe__c from ObjectCh__c where Amount__c = null && ObjectRe__c IN: st_ParentId]);
 if(lst_objCh!=null && lst_objCh.size()>0)
  { 
for(ObjectPar__c ob : Trigger.new)
  {     
       if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && obj.Myamount__c==null && obj.createdDate > '2017-02-15T00:00:00Z')            
                 ob.addError('Myamount__c should be required');
            }        }
  } 
}
rajat Maheshwari 6rajat Maheshwari 6

Please remove quote, as this was the reason for reason.

Use this and let me know : - 

trigger ObjectTrigger on ObjectPar__c(before update)
 {
     Set<Id> st_ParentId = new set<id>(); 
for(ObjectPar__c obj : Trigger.new)
   {
     if(Trigger.oldMap.get(obj.id).Myamount__c != obj.Myamount__c )
           st_ParentId.add(obj.ObjectRe__c);
   }
 
List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,Amount__c,ObjectRe__c from ObjectCh__c where Amount__c = null && ObjectRe__c IN: st_ParentId]);
 if(lst_objCh!=null && lst_objCh.size()>0)
  { 
for(ObjectPar__c ob : Trigger.new)
  {     
       if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && obj.Myamount__c==null && obj.createdDate > 2017-02-15T00:00:00Z)            
                 ob.addError('Myamount__c should be required');
            }        }
  } 
}

 

Waqar Hussain SFWaqar Hussain SF
trigger ObjectTrigger on ObjectPar__c(before update)
 {
     Set<Id> st_ParentId = new set<id>(); 
for(ObjectPar__c obj : Trigger.new)
   {
     if(Trigger.oldMap.get(obj.id).Myamount__c != obj.Myamount__c )
           st_ParentId.add(obj.ObjectRe__c);
   }
 
List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,Amount__c,ObjectRe__c from ObjectCh__c where Amount__c = null && ObjectRe__c IN: st_ParentId]);
 if(lst_objCh!=null && lst_objCh.size()>0)
  { 
for(ObjectPar__c ob : Trigger.new)
  {     
       if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && obj.Myamount__c==null && obj.createdDate > TODAY)            
                 ob.addError('Myamount__c should be required');
            }        }
  } 
}

See above example and let me know. It will definitely help you.
BegginerBegginer
Variable does not exists TODAY
rajat Maheshwari 6rajat Maheshwari 6

Begginer, Your issue get solved or not ?   If Not, then what the error you are facing ?

 

Note : FYI,   I am taking Today Date which is 15 feb 2017 

 

Thanks

 

 

BegginerBegginer
Same error even if date changed back or forth
comparison arguments must be compatible types: DateTime
rajat Maheshwari 6rajat Maheshwari 6

Begginer, Here I am seing one mistake : - 

for(ObjectPar__c ob : Trigger.new)
  {     
       if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && obj.Myamount__c==null && obj.createdDate > 2017-02-15T00:00:00Z)            
                 ob.addError('Myamount__c should be required');
            }        }
  } 

Here for loop instance is "ob" and we are using "obj" in body of for loop.

Please use this as below : - 

for(ObjectPar__c obj : Trigger.new)
  {     
       if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && obj.Myamount__c==null && obj.createdDate > 2017-02-15T00:00:00Z)            
                 obj.addError('Myamount__c should be required');
            }        }
  } 

BegginerBegginer
if both are obj in trigger.new then duplicate variable error throws out which is why I changed it
rajat Maheshwari 6rajat Maheshwari 6

okie, Begginer,

If you want to use ob as earlier, then replace obj from body of forLoop by ob like below : - 

for(ObjectPar__c ob : Trigger.new)
  {     
       if(ob.Picklist_a__c!=null && ob.Picklist_b__c!=null && (ob.RecordTypeId==IdCorrespondingtoA || ob.RecordTypeId==IdCorrespondingtoB) && ob.Myamount__c==null && ob.createdDate > 2017-02-15T00:00:00Z)            
                 ob.addError('Myamount__c should be required');
            }        }
  } 

BegginerBegginer
Same error 
BegginerBegginer
can you help me with you email id @rajat
rajat Maheshwari 6rajat Maheshwari 6

Yeah sure @Begginer

Email Id : rajatzmaheshwari@gmail.com

BegginerBegginer
I'm working on another scenario could use your help @rajat Maheshwari

There are two objects ObjectPar__c(Parent) and ObjectCh__c(child) having look-up relationship.

Summary:
ObjectPar__c has record types namely  "A" and "B".
ObjectPar__c has 2 picklislts --> Picklist_a__c and Pciklist_b__c
ObjectCh__c 

Scenario:

if record type is either A||B and Picklst_a__c and picklist__b ("checked") (on the parent) is selected and there are records on the child object then trigger should fire on the parent object.
if there are no records on child object then trigger should not fire.
rajat Maheshwari 6rajat Maheshwari 6
trigger ObjectTrigger on ObjectPar__c(before update)
  {
     Set<Id> st_ParentId = new set<id>();

for(ObjectPar__c obj : Trigger.new)
   {
   
           st_ParentId.add(obj.lookupField);
   }

List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,lookupField from ObjectCh__c where lookupField IN:st_ParentId]);



if(lst_objCh!=null && lst_objCh.size()>0)
  {
    

for(ObjectPar__c obj : Trigger.new)
  {
    
        if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && obj.Picklist_b__c=='Checked' && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB))

            {
                     obj.addError('My Name is Error');
            }
        }
  }



}


As per your scenario, when picklist b have value "Checked" and having child records related to that then trigger will fire to display error message , otherwise, No error will come.

Thanks

This was selected as the best answer
BegginerBegginer
trigger ObjectTrigger on ObjectPar__c(before update)
02  {
03     Set<Id> st_ParentId = new set<id>();
04 
05for(ObjectPar__c obj : Trigger.new)
06   {
07    
08           st_ParentId.add(obj.lookupField);
09   }
10 
11List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,lookupField from ObjectCh__c wherelookupField IN:st_ParentId]);
12 
13 
14 
15if(lst_objCh!=null && lst_objCh.size()>0)
16  {
17     
18 
19for(ObjectPar__c obj : Trigger.new)
20  {
21     
22        if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && obj.Picklist_b__c=='Checked' && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && (obj.Myamount__c == null || obj.Myamount__c == 0)
23 
24            {
25                     obj.addError('Myamount is required ');
26            }
27        }
28  }
29 
30 
31 
32}



but when I enter Myamount the trigger is firing. can you help me on this?
rajat Maheshwari 6rajat Maheshwari 6
please use this : - 

 if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && obj.Picklist_b__c=='Checked' && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && (obj.Myamount__c == null || obj.Myamount__c == 0))
rajat Maheshwari 6rajat Maheshwari 6
RightParenthesis was missing
 
rajat Maheshwari 6rajat Maheshwari 6
Right, When you enter value other than 0 , you must not get error.

Thanks
BegginerBegginer
how to trigger when create day is greater than 2017-02-14

 if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && obj.Picklist_b__c=='Checked' && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && (obj.Myamount__c == null || obj.Myamount__c == 0) && CreatedDate > '2017-02-14')
rajat Maheshwari 6rajat Maheshwari 6

Begginer,

CreatedDate returns DateTime, so you need to compare createdDate with dateTime value,..Please follow below one : -

 if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && obj.Picklist_b__c=='Checked' && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && (obj.Myamount__c == null || obj.Myamount__c == 0) && CreatedDate > 2017-02-15T00:00:00Z)

 

Let me know if any issue comes
 

BegginerBegginer
tried that same error 
rajat Maheshwari 6rajat Maheshwari 6

Begginer,

Use this :P It will help you :) 

 datetime startDate = datetime.newInstance(2017,02,15);

 if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && obj.Picklist_b__c=='Checked' && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && (obj.Myamount__c == null || obj.Myamount__c == 0) && CreatedDate > startDate )

 

Enjoy :D

Please let me know the issue again comes

Ajay mishraAjay mishra
Hi Begginer,

Please try this. It may work for you.
 
trigger ObjectParTrigger on ObjectPar__c(before update)
{
    Set<Id> st_ParentId = new set<id>();
	
	DateTime dateCreated = DateTime.newInstance(2017, 02, 14, 00, 00, 00);

	for(ObjectPar__c obj : Trigger.new)
	{
		if((obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && obj.Picklist_a__c != null && obj.Picklist_b__c == 'checked' && Myamount__c == null && CreatedDate > dateCreated)
		{
           st_ParentId.add(obj.lookupField);
		}
	}

	List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,lookupField from ObjectCh__c where lookupField IN:st_ParentId]);

	if(lst_objCh!=null && lst_objCh.size()>0)
	{    

		for(ObjectPar__c obj : [Select Id from ObjectPar__c where Id IN st_ParentId])
		{
			obj.addError('My Name is Error');
		}

	}
}


Thanks
Ajay Mishra
Email: mishraajay.m1@gmail.com
rajat Maheshwari 6rajat Maheshwari 6

Hi Begginer,

Does your issue get solved?

BegginerBegginer
List<ObjectCh__c> lst_objCh = new List<ObjectCh__c>([Select id,lookupField from ObjectCh__c where lookupField.CreatedDate >  2017-02-15T00:00:00Z lookupField IN:st_ParentId]);

I used that query and its working fine
rajat Maheshwari 6rajat Maheshwari 6

Begginer,

Below is points, please look over it : - 

1. In query, YYYY-MM-DDThh:mm:ssZ works fine as , in your case It works :)

2. In If Conditional logic, What I have suggested, will work fine

Ex-   

datetime startDate = datetime.newInstance(2017,02,15);
 if(obj.Picklist_a__c!=null && obj.Picklist_b__c!=null && obj.Picklist_b__c=='Checked' && (obj.RecordTypeId==IdCorrespondingtoA || obj.RecordTypeId==IdCorrespondingtoB) && (obj.Myamount__c == null || obj.Myamount__c == 0) && CreatedDate > startDate )

 

Note : - Query return child Object fields , Please let me know, Whose createdDate you want to check either parent object created Date or child Object created Date ?

Please Mark as best answer, If it make sense.

Thanks

 

rajat Maheshwari 6rajat Maheshwari 6

Begginer,

Please feel free to contact me on any issue on email Id : rajatzmaheshwari@gmail.com

BegginerBegginer
For Sure, I appreciate your help.
Brooke HarperBrooke Harper
Hey! Thanks to the both of you for working around this one, special mention to Begginer for doing the trial and error part. This works great.
Maria Machado 2Maria Machado 2
Hi! I have 2 object. Adventure__c and Adventure_Note__c. I am trying to populate the field "Adventure_Email_in_Note__c" 
in the object Adventure_Note__c, with the email in the field "Email_From_Requestor__c" which is in the Adventure__c . I am trying to use the code below, but I think I have an error since it does nothing.

trigger OnAdventureFields on Adventure__c (after insert, after update) {

    map<string, Adventure__c> ObjMap = new map<string, Adventure__c>();
    
        for(Adventure__c obj: Trigger.new){
            
            if (obj.Email_From_Requestor__c != Null) {
            
                ObjMap.put(obj.Email_From_Requestor__c, obj);
                
             }
         }
         
         List<Adventure_Note__c> AdventureNotes = [SELECT Id, Adventure_Email_in_Note__c, Adventure_ID__c
                                         FROM Adventure_Note__c WHERE Adventure_Email_in_Note__c IN :ObjMap.KeySet()];
         
         List<Adventure_Note__c> NoteUpdateList = new List<Adventure_Note__c>();
         
         for (Adventure_Note__c c: AdventureNotes){
         
             Adventure__c obj = ObjMap.get(c.Adventure_Email_in_Note__c);
             
             c.Adventure_Email_in_Note__c = obj.Email_From_Requestor__c;

             NoteUpdateList.add(c);
             
             if(NoteUpdateList.size() > 0){
                 update NoteUpdateList;
              }
          }
}
Robert WhiskerRobert Whisker
Before creating triggers, consider the following:
  • upsert triggers fire both before and after insert or before and after update triggers as appropriate.
  • merge triggers fire both before and after delete for the losing records, and both before and after update triggers for the winning record. See Triggers and Merge Statements.
  • Triggers that execute after a record has been undeleted only work with specific objects. See Triggers and Recovered Records.
  • Field history e.g what you have searched like any file Need for speed no limits mod apk (https://apkslord.com/need-for-speed-no-limits-mod-apk/) is not recorded until the end of a trigger. If you query field history in a trigger, you don’t see any history for the current transaction.
  • Field history tracking honors the permissions of the current user. If the current user doesn’t have permission to directly edit an object or field, but the user activates a trigger that changes an object or field with history tracking enabled, no history of the change is recorded.
  • Callouts must be made asynchronously from a trigger so that the trigger process isn’t blocked while waiting for the external service's response. The asynchronous callout is made in a background process, and the response is received when the external service returns it. To make an asynchronous callout, use asynchronous Apex such as a future method. See Invoking Callouts Using Apex for more information.
  • In API version 20.0 and earlier, if a Bulk API request causes a trigger to fire, each chunk of 200 records for the trigger to process is split into chunks of 100 records. In Salesforce API version 21.0 and later, no further splits of API chunks occur. If a Bulk API request causes a trigger to fire multiple times for chunks of 200 records, governor limits are reset between these trigger invocations for the same HTTP request.