• wiseguy
  • NEWBIE
  • 30 Points
  • Member since 2013

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

Hi, I was wondering if someone could help me with an Apex trigger I'm trying to write? I am completely new to coding, please bear with me -

 

I am working with a custom object and Accounts. In the custom object, when a checkbox = true, values in that record should update the corresponding Account's fields. Every record in this custom object is related to an Account so I tried at first creating a master-detail relationship and then using SF's workflows, but we will also need to see history on these custom object records (particularly which of our users checked the checkbox), which I've read you can't get using master-detail relationships so it's a lookup currently.

 

This is what I have so far - a record in this custom object will never have the checkbox ("Approved__c") selected upon insert, only upon update:

 

trigger CQApprovedUpsertChurch on Church_Questionnaire__c (before update) {
    List<Account> a = new List<Account> ();
    for (Church_Questionnaire__c ApprovedCQ: Trigger.New)
    if (ApprovedCQ.Approved__c = True)
        {
            a.add (new Account (
            CORE_Yearbook_ID__c = ApprovedCQ.Church_Yearbook_ID__c,
            Mailing_Street_1__c = ApprovedCQ.Mailing_Street_1__c,
            Mailing_Street_2__c = ApprovedCQ.Mailing_Street_2__c,
            Mailing_Street_3__c = ApprovedCQ.Mailing_Street_3__c,
            Mailing_City__c = ApprovedCQ.Mailing_City__c,
            Mailing_State_Province__c = ApprovedCQ.Mailing_State_Province__c,
            Mailing_Zip_Postal_Code__c = ApprovedCQ.Mailing_Zip_Postal_Code__c
            ));
        }
    upsert a Account.CORE_Yearbook_ID__c;
}

 

It is working to update the Account's address when the custom object record is saved and Approved__c = True, however when I edit that same record to uncheck Approved__c and save, it becomes checked again.

 

I tried changing my "before update" statement to "before insert, before update", and when that's in place, if I insert a record Approved__c is checked regardless of whether I actually checked it or not.

 

Can someone tell me what I'm doing wrong/what's wrong with my logic?

I have the following issue:

 

While deploying to production, I am encountering multiple test class failures, reproting the UNABLE_TO_LOCK_ROW error.

The failure is when the test class is trying to create an account record for testing - the error is thrown when trying to insert an account record.

 

When running all tests in a sandbox, the issue does not occur. I was able to test the deployment to a full sandbox with no issue, it's just the production environemnt that is failing.

 

I read the FAQs and trying switching off all autonumber and external id fields, but that did not make any difference. I don;t have any roll up summery fields, I'm not using any multi-threading, so can;t really find any other issue related to an 'insert' statment

 

I tried SFDC support, which refered me to the FAQ (that's premier support money well spent)

 

I'll attach an exrept of the log file, the class cuasing the issue and the account metadata file

'd appraciate any idea as we are currently stuck with this deployment ...

I have the following issue:

 

While deploying to production, I am encountering multiple test class failures, reproting the UNABLE_TO_LOCK_ROW error.

The failure is when the test class is trying to create an account record for testing - the error is thrown when trying to insert an account record.

 

When running all tests in a sandbox, the issue does not occur. I was able to test the deployment to a full sandbox with no issue, it's just the production environemnt that is failing.

 

I read the FAQs and trying switching off all autonumber and external id fields, but that did not make any difference. I don;t have any roll up summery fields, I'm not using any multi-threading, so can;t really find any other issue related to an 'insert' statment

 

I tried SFDC support, which refered me to the FAQ (that's premier support money well spent)

 

I'll attach an exrept of the log file, the class cuasing the issue and the account metadata file

'd appraciate any idea as we are currently stuck with this deployment ...

Hi, I was wondering if someone could help me with an Apex trigger I'm trying to write? I am completely new to coding, please bear with me -

 

I am working with a custom object and Accounts. In the custom object, when a checkbox = true, values in that record should update the corresponding Account's fields. Every record in this custom object is related to an Account so I tried at first creating a master-detail relationship and then using SF's workflows, but we will also need to see history on these custom object records (particularly which of our users checked the checkbox), which I've read you can't get using master-detail relationships so it's a lookup currently.

 

This is what I have so far - a record in this custom object will never have the checkbox ("Approved__c") selected upon insert, only upon update:

 

trigger CQApprovedUpsertChurch on Church_Questionnaire__c (before update) {
    List<Account> a = new List<Account> ();
    for (Church_Questionnaire__c ApprovedCQ: Trigger.New)
    if (ApprovedCQ.Approved__c = True)
        {
            a.add (new Account (
            CORE_Yearbook_ID__c = ApprovedCQ.Church_Yearbook_ID__c,
            Mailing_Street_1__c = ApprovedCQ.Mailing_Street_1__c,
            Mailing_Street_2__c = ApprovedCQ.Mailing_Street_2__c,
            Mailing_Street_3__c = ApprovedCQ.Mailing_Street_3__c,
            Mailing_City__c = ApprovedCQ.Mailing_City__c,
            Mailing_State_Province__c = ApprovedCQ.Mailing_State_Province__c,
            Mailing_Zip_Postal_Code__c = ApprovedCQ.Mailing_Zip_Postal_Code__c
            ));
        }
    upsert a Account.CORE_Yearbook_ID__c;
}

 

It is working to update the Account's address when the custom object record is saved and Approved__c = True, however when I edit that same record to uncheck Approved__c and save, it becomes checked again.

 

I tried changing my "before update" statement to "before insert, before update", and when that's in place, if I insert a record Approved__c is checked regardless of whether I actually checked it or not.

 

Can someone tell me what I'm doing wrong/what's wrong with my logic?

Hi,

 

I have written trigger which does some functionality upon inserting the records.When I am trying to load the data the trigger executes and giving me the error Too many script statements: 20001.

 

None of theSOQL queries are inside the for loop.I have used collections like list and map.

 

Can anyone please help me how  can I resolve this issue.

 

Thanks,

Srilakshmi B