• InsertWittyName
  • NEWBIE
  • 125 Points
  • Member since 2009

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 15
    Replies

Hello.

I want to create ApexTrigger(before insert) calls Apex class.

But I try the code run normally in developer organization, don't run in operational organization.

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

[Trigger]

trigger instCode on CustomObjectA (before insert) {
    CustomObjectA[] a = Trigger.new;
    Class01.addData(a);
}

 

[Class]

 public class Class01 {
    public static void addData(CustomObjectA[] a){
        if(wd.size()>0){
                for(CustomObjectA wdc:wd){
                    CustomObjectB b = [select RunningHour__c from CustomObjectB where Id= :wdc.SerialNum__c];
                    If(a.RunningHour__c > b.RunningHour__c){
                        b.RunningHour__c = a.RunningHour__c;
                        update a;
        }

    //testMethod
    public static testMethod void testAddData(){
        CustomObjectB b = [select Id,Name,RecordTypeId,RunningHour__c from CustomObjectB where Name='10785'];
        b.RunningHour__c = 120.0;
        update b;
        //CustomObjectA>CustomObjectB

       CustomObjectA a = new CustomObjectA(WorkNum__c='a0910000005zwM2AAI',SerialNum__c='a0810000002ZEtGAAW', RunningHour__c=125.5);
        insert a1; //call trigger
        CustomObjectB b01 = [select Id,Name,RunningHour__c from CustomObjectB where Id= :a1.Id];
        System.assertNotEquals(b01.RunningHour__c,a1.RunningHour__c);
        //CustomObjectA<CustomObjectB

       CustomObjectA a2 = new CustomObjectA(WorkNum__c='a0910000005zwM2AAI',SerialNum__c='a0810000002ZEtGAAW',RunningHour__c=119);
        insert a2; //call trigger
        CustomObjectB b02 = [select Id,Name,RunningHour__c from CustomObjectB where Id= :a2.Id];
        System.assertNotEquals(b02.RunningHour__c,a2.RunningHour__c);
    }

}

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

Testmethod:testAddData run normally,but don't call Trigger: instCode apparently.

Why don't call Trigger.

Hello,


I have a test file i'm trying to import into Salesforce with Data Loader and all the fields are being mapped correctly, however I only get errors no successes.  The error says "Contact <name of an Admin> if you require this Account information changed".

 

My role in salesforce is System Administrator as well.

 

Any help would be great!!

 

Thanks

  • January 07, 2010
  • Like
  • 0

The problem is that the Opportunity was given two sets of custom fields: date paid (1 & 2), Amount paid (1 & 2) etc.

 

I've made a custom object, "payments", so that I can have any number of payment entries, but of course now I'd like to try and copy the old data, from the Opportunity, into the new object.

 

Would anyone know of any instruction material online (I've been looking but no joy so far) that might help me code such a project?

 

I'm possibly missing some obvious prebuilt method for doing so but then again, it seems a slightly custom chore.

 

Once I have all of these fields copied over I can delete these fields from the Opportunity.

 

The other reason I thought this piece of machinary (coding) invaluable is in the case that I need to redesign an object, eg. I dsicover I should have built it with Field Tracking or Reporting capabilities, and I then need to make a new object with such.

 

Many Thanks for any advice or links you might know of.

 

Dee

  • January 07, 2010
  • Like
  • 0

I have two triggers:

  

 trigger CleanDRLineItem on Opportunity_Tracker_Products__c (before delete) {

    for (Integer i = 0; i < Trigger.old.size(); i++) {

        try {

            //replace OppLineId__c with actual refference name.

            List<Design_Registration__c> oDRs = [select id, DP_reg_id__c, OwnerID, Inactive__c from Design_Registration__c where Opp_tracker_line_ID__c = :trigger.old[i].id];

            for (Design_registration__c dr: oDRs)

            {

             dr.OwnerId = '00540000000oJjiAAE';

             dr.Inactive__c = true;

             string old_dr_number = dr.DP_reg_id__c;

             dr.DP_reg_id__c = 'IN-' + old_dr_number;

             update dr;

            }

            

            

        } catch (System.QueryException ex) {

            //Do Nothing - There must not have been any to delete.

        }

    }

}

 

 and 

 

 trigger CleanOppTrackerLineItem on Opportunity_Trackers__c (before delete) {

    for (Integer i = 0; i < Trigger.old.size(); i++) {

        

            //replace OppLineId__c with actual refference name.

            Opportunity_Tracker_Products__c[] oTRs = [select id from Opportunity_Tracker_Products__c where Opportunity_Tracker__c = :trigger.old[i].id];

            //System.Debug('Removing the following: '+oTRs.id);

            delete oTRs;

        

    }

}

  Now I am receiving errors and i do not understand why they are getting them, Here is the text of one of the emails I am receiving:

 

 

Apex script unhandled trigger exception by user/organization: 00540000000yFVO/00D300000006AVjCleanOppTrackerLineItem: execution of BeforeDeletecaused by: System.DmlException: Delete failed. First exception on row 0 with id a0B4000000282XlEAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CleanDRLineItem: execution of BeforeDeletecaused by: System.Exception: Too many SOQL queries: 21Trigger.CleanDRLineItem: line 5, column 49: []Trigger.CleanOppTrackerLineItem: line 7, column 13

 

 

 

 I would appreciate any feedback and help, 

 

Thanks,

Mike Simonds 

 

 

 

Message Edited by msimonds on 01-06-2010 07:40 PM

I have created a custom object, named VAR (Value at Risk). It is, and must be, a singleton object. There must be one and only one VAR record in the system. It makes absolutely no sense to have more than one VAR record. Having no VAR record is equally ridiculous.

 

Many other objects must have access this systemwide singleton value. Of course, it needs to be easily updated by authorized users.

 

The VAR record's value is tracked via "Set History Tracking." Each time VAR changes, Salesforce's Track History shows when it was changed, who changed it, and what the change was, leaving a perfect audit trail on the VAR record -- exactly per requirements.

 

I was able to make this work very easily in the sandbox, but I can not deploy it in Production via Eclipse because Salesforce insists on running both the insertVAR and deleteVAR triggers before allowing the deployment to succeed. And, given the triggers, of course it fails, and therefore code coverage is zero for those triggers, and I'm out of luck....

 

Here are the two trivial triggers:

 

trigger insertVAR on CES_VAR__c (before insert) {

Trigger.new[0].addError('\r\nThere can only be one VaR record! To change VaR, click the Edit button.');

}

 

trigger deleteVAR on CES_VAR__c (before delete) {

Trigger.old[0].addError('Can not delete the VAR record! To change VaR, click the Edit button.');

}

 

How can I get this to deploy? Is there some way to fool Salesforce into accepting this? Is there a singleton pattern in Salesforce that I'm not aware of?

 

Has anyone been able to get this (rather standard design pattern) to work on Salesforce?

 

Thank you very much for your time.

 

  • January 06, 2010
  • Like
  • 0

Hi folks.

 

I have an Apex Trigger that I'm trying to write unit tests for.

 

The problem is I'm unsure how to test the following:

 

 

Opportunity newOpp = oldOpp.clone(false);

insert newOpp;

OpportunityLineItem oli = product.clone(false);

oli.OpportunityId = newOpp.Id;

oli.Objection__c = '';

oli.Outcome__c = '';

newProducts.add(oli);

 

 

Every line is marked as not tested and because of this my unit test fails.

 

Any advice?

 

Many thanks. 

Message Edited by InsertWittyName on 11-02-2009 07:46 AM
Message Edited by InsertWittyName on 11-02-2009 07:47 AM

Hi.

 

I'm trying to have a checkbox either selected or not selected based on a value in a picklist.

 

The value of the checkbox should be dynamic based on the picklist selection and not require the record saving or a page refresh.

 

Any pointers?

 

Many thanks. 

Hi all,

 

I need to add rule on opportunity which will prevent from moving back the stage of opportunity.

 

Could you please help me doing this.

Any help will be appreciated.

 

Thanks in advacnce,

  • January 13, 2010
  • Like
  • 0

I am running into soql limits for my triggers... I am trying to condense as much as I can.  Is there any way to condense the following trigger?  I was hoping to only have one select statement but not sure how to achieve this.. thanks so much!!!

 

Fred

 

trigger UpdateManager on Quote__c (before insert, before update) { //this trigger is used for two things: //1. update the record owners manager on the quote record //2. update the underwriter field on quote with the name of the underwriter... this is needed so // I can get the UW name as a user on the quote so I can use in automated emails (can't use workflow) //create list to hold quote owner id List<Id> quoteOwners = new List<Id>(); //create list to hold underwriter id List<Id> Underwriters = new List<Id>(); //loop through quotes and save owner id to quoteOwners list, save underwriter id to underwriters list for (Quote__c q : Trigger.new){ quoteOwners.add(q.ownerid); Underwriters.add(q.UnderwriterID__c); } //create map to hold the UserID and the Direct Manager Map<Id,User> userToDirectManagerMap = new Map<Id,User>([select Id, Direct_Manager__c from User where Id IN :quoteowners]); //create map to hold the UserID and User Name Map<Id,User> UserToUnderwriterMap = new Map<Id,User>([select Id, Name from User where Id IN :Underwriters]); //Loop through the quotes that caused the trigger for(Quote__c q : Trigger.new){ //update the manager field on quote based on the owner of the record q.Manager__c = userToDirectManagerMap.get(q.OwnerId).Direct_Manager__c; //update the Underwriter field on quote based on the underwriterID field on quote if(UserToUnderwriterMap.get(q.UnderwriterID__c) <> null) { q.UnderwriterToEmail__c = UserToUnderwriterMap.get(q.UnderwriterID__c).ID; } } }

 

  • January 08, 2010
  • Like
  • 0

Hello.

I want to create ApexTrigger(before insert) calls Apex class.

But I try the code run normally in developer organization, don't run in operational organization.

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

[Trigger]

trigger instCode on CustomObjectA (before insert) {
    CustomObjectA[] a = Trigger.new;
    Class01.addData(a);
}

 

[Class]

 public class Class01 {
    public static void addData(CustomObjectA[] a){
        if(wd.size()>0){
                for(CustomObjectA wdc:wd){
                    CustomObjectB b = [select RunningHour__c from CustomObjectB where Id= :wdc.SerialNum__c];
                    If(a.RunningHour__c > b.RunningHour__c){
                        b.RunningHour__c = a.RunningHour__c;
                        update a;
        }

    //testMethod
    public static testMethod void testAddData(){
        CustomObjectB b = [select Id,Name,RecordTypeId,RunningHour__c from CustomObjectB where Name='10785'];
        b.RunningHour__c = 120.0;
        update b;
        //CustomObjectA>CustomObjectB

       CustomObjectA a = new CustomObjectA(WorkNum__c='a0910000005zwM2AAI',SerialNum__c='a0810000002ZEtGAAW', RunningHour__c=125.5);
        insert a1; //call trigger
        CustomObjectB b01 = [select Id,Name,RunningHour__c from CustomObjectB where Id= :a1.Id];
        System.assertNotEquals(b01.RunningHour__c,a1.RunningHour__c);
        //CustomObjectA<CustomObjectB

       CustomObjectA a2 = new CustomObjectA(WorkNum__c='a0910000005zwM2AAI',SerialNum__c='a0810000002ZEtGAAW',RunningHour__c=119);
        insert a2; //call trigger
        CustomObjectB b02 = [select Id,Name,RunningHour__c from CustomObjectB where Id= :a2.Id];
        System.assertNotEquals(b02.RunningHour__c,a2.RunningHour__c);
    }

}

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

Testmethod:testAddData run normally,but don't call Trigger: instCode apparently.

Why don't call Trigger.

Hello,


I have a test file i'm trying to import into Salesforce with Data Loader and all the fields are being mapped correctly, however I only get errors no successes.  The error says "Contact <name of an Admin> if you require this Account information changed".

 

My role in salesforce is System Administrator as well.

 

Any help would be great!!

 

Thanks

  • January 07, 2010
  • Like
  • 0

The problem is that the Opportunity was given two sets of custom fields: date paid (1 & 2), Amount paid (1 & 2) etc.

 

I've made a custom object, "payments", so that I can have any number of payment entries, but of course now I'd like to try and copy the old data, from the Opportunity, into the new object.

 

Would anyone know of any instruction material online (I've been looking but no joy so far) that might help me code such a project?

 

I'm possibly missing some obvious prebuilt method for doing so but then again, it seems a slightly custom chore.

 

Once I have all of these fields copied over I can delete these fields from the Opportunity.

 

The other reason I thought this piece of machinary (coding) invaluable is in the case that I need to redesign an object, eg. I dsicover I should have built it with Field Tracking or Reporting capabilities, and I then need to make a new object with such.

 

Many Thanks for any advice or links you might know of.

 

Dee

  • January 07, 2010
  • Like
  • 0

I have two triggers:

  

 trigger CleanDRLineItem on Opportunity_Tracker_Products__c (before delete) {

    for (Integer i = 0; i < Trigger.old.size(); i++) {

        try {

            //replace OppLineId__c with actual refference name.

            List<Design_Registration__c> oDRs = [select id, DP_reg_id__c, OwnerID, Inactive__c from Design_Registration__c where Opp_tracker_line_ID__c = :trigger.old[i].id];

            for (Design_registration__c dr: oDRs)

            {

             dr.OwnerId = '00540000000oJjiAAE';

             dr.Inactive__c = true;

             string old_dr_number = dr.DP_reg_id__c;

             dr.DP_reg_id__c = 'IN-' + old_dr_number;

             update dr;

            }

            

            

        } catch (System.QueryException ex) {

            //Do Nothing - There must not have been any to delete.

        }

    }

}

 

 and 

 

 trigger CleanOppTrackerLineItem on Opportunity_Trackers__c (before delete) {

    for (Integer i = 0; i < Trigger.old.size(); i++) {

        

            //replace OppLineId__c with actual refference name.

            Opportunity_Tracker_Products__c[] oTRs = [select id from Opportunity_Tracker_Products__c where Opportunity_Tracker__c = :trigger.old[i].id];

            //System.Debug('Removing the following: '+oTRs.id);

            delete oTRs;

        

    }

}

  Now I am receiving errors and i do not understand why they are getting them, Here is the text of one of the emails I am receiving:

 

 

Apex script unhandled trigger exception by user/organization: 00540000000yFVO/00D300000006AVjCleanOppTrackerLineItem: execution of BeforeDeletecaused by: System.DmlException: Delete failed. First exception on row 0 with id a0B4000000282XlEAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CleanDRLineItem: execution of BeforeDeletecaused by: System.Exception: Too many SOQL queries: 21Trigger.CleanDRLineItem: line 5, column 49: []Trigger.CleanOppTrackerLineItem: line 7, column 13

 

 

 

 I would appreciate any feedback and help, 

 

Thanks,

Mike Simonds 

 

 

 

Message Edited by msimonds on 01-06-2010 07:40 PM

I have created a custom object, named VAR (Value at Risk). It is, and must be, a singleton object. There must be one and only one VAR record in the system. It makes absolutely no sense to have more than one VAR record. Having no VAR record is equally ridiculous.

 

Many other objects must have access this systemwide singleton value. Of course, it needs to be easily updated by authorized users.

 

The VAR record's value is tracked via "Set History Tracking." Each time VAR changes, Salesforce's Track History shows when it was changed, who changed it, and what the change was, leaving a perfect audit trail on the VAR record -- exactly per requirements.

 

I was able to make this work very easily in the sandbox, but I can not deploy it in Production via Eclipse because Salesforce insists on running both the insertVAR and deleteVAR triggers before allowing the deployment to succeed. And, given the triggers, of course it fails, and therefore code coverage is zero for those triggers, and I'm out of luck....

 

Here are the two trivial triggers:

 

trigger insertVAR on CES_VAR__c (before insert) {

Trigger.new[0].addError('\r\nThere can only be one VaR record! To change VaR, click the Edit button.');

}

 

trigger deleteVAR on CES_VAR__c (before delete) {

Trigger.old[0].addError('Can not delete the VAR record! To change VaR, click the Edit button.');

}

 

How can I get this to deploy? Is there some way to fool Salesforce into accepting this? Is there a singleton pattern in Salesforce that I'm not aware of?

 

Has anyone been able to get this (rather standard design pattern) to work on Salesforce?

 

Thank you very much for your time.

 

  • January 06, 2010
  • Like
  • 0

I am new to flex and had a couple of questions before diving in.  Currently, I use Eclipse to build Visualforce pages, apex classes and triggers.  If I am required to build external pages using the Salesforce API, I will develop the external pages using VisualStudio 2008 by compiling the enterprise wsdl into an assembly and creating aspx pages to build the external app.

 

I've built a pretty simple app in Visual Studio that handles a simple insert into a Salesforce custom object.  This works well.  Now, I'd like to try to incorporate flex.  As an example, I'd like to use a flex datagrid to display all the records in the custom oject, enable sorting and paging and editing capabilities.

 

Can flex be used with Visual Studio?  Can I build the flex apps in Eclipse and then integrated into an aspx page using Visual Studio?  I've looked at a couple of quick flex demos, but they use flex builder and I'm trying to get a handle on the possibilities using Eclipse/Visual Studio?

 

Also, I'm using Eclipse 3.3.2.

 

Thanks.

Hi folks.

 

I have an Apex Trigger that I'm trying to write unit tests for.

 

The problem is I'm unsure how to test the following:

 

 

Opportunity newOpp = oldOpp.clone(false);

insert newOpp;

OpportunityLineItem oli = product.clone(false);

oli.OpportunityId = newOpp.Id;

oli.Objection__c = '';

oli.Outcome__c = '';

newProducts.add(oli);

 

 

Every line is marked as not tested and because of this my unit test fails.

 

Any advice?

 

Many thanks. 

Message Edited by InsertWittyName on 11-02-2009 07:46 AM
Message Edited by InsertWittyName on 11-02-2009 07:47 AM
In the apex language reference manual i read this:

"Note: A trigger invoked by an insert, delete or update, of a recurring event results in a runtime error when
the trigger is called in bulk from the Force.com API."

I need to do a mass update in Events and any of this events can be recurring and I have a trigger asociate to Event, what should I change or control to avoid this runtine error?


Thanks for All
  • July 29, 2008
  • Like
  • 0