0

I am trying to invoke a trigger for a object after insert but that is invoking fine when I am trying to update object for updating from salesforce UI but not working when data is coming from the external system (SAP).

The code which i m trying :

trigger Trigger on obj1(after insert,before update,before insert,after update) {
ObjHandler objHandler = new ObjHandler();


if(Trigger.IsBefore || Trigger.IsUpdate)
{
   objHandler.beforeInsertUpdate(Trigger.new,Trigger.oldMap);
}
}
4
  • Can you elaborate on how the data is inserted from SAP to SFDC? – Sebastian Kessel Nov 26 '15 at 8:17
  • we are sending data from SAP through PI and we have passed the standard object in PI . – user2424427 Nov 26 '15 at 8:59
  • can i know the code of beforeInsertUpdate ()? – unidha Nov 26 '15 at 10:43
  • Problem is trigger is not firing and its not going inside beforeInsertUpdate – user2424427 Nov 26 '15 at 10:46
1

The problem you're having is caused by he structure of your trigger's code. See below for how it needs to be modified, which assumes all before triggers go to the same before handler and all after triggers go to the same after handler:

trigger Trigger on obj1(after insert,before update,before insert,after update) {
    ObjHandler objHandler = new ObjHandler();


    if(Trigger.IsBefore{
       if(Trigger.isInsert || Trigger.isUpdate){
           objHandler.beforeInsertUpdate(Trigger.new,Trigger.oldMap);
       }
    }
    else if(Trigger.IsAfter{
       if(Trigger.isInsert || Trigger.isUpdate){
           objHandler.afterInsertUpdate(Trigger.new,Trigger.oldMap);
       {
    {

}

I'll add that the if(Trigger.isInsert || Trigger.isUpdate) is superfluous and can be removed in both of situations above. However, if you need to separate them out and send the isInsert or isUpdate to different handlers, then you'll want to have if statements to determine which handlers they go to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.