• MattyDHL
  • NEWBIE
  • 25 Points
  • Member since 2009

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

Hi all,

 

I am new in Apex and Salesforce. 

I have seen some posts to that issue.

But is there also a simple way (for example copy and paste) to migrate my trigger from Sandbox to production environment?

 

Thanks! 

Hi,

 

I am totally confused how to get the Users Profile Name to the Task Page. I am writing a trigger and needed to use something like this:

 

 

Select u.Name, (Select Name From Profile) From User u

 

 

But it doesn't work, because of the relationship.

 

I then though about creating Map's

 

So I would have these Maps:

TaskId/UserId

UserId/ProfileId

ProfileId/ProfileName

UserId/ProfileName

TaskId/Profile

 

And looping through them till I can get the Profile Name on the Task Page, then I thought, there has gotta be something I'm missing I am making life hard for myself.

 

Can anybody please advise me of the best practice, so I can get to work.


Thanks

Matt

Muitos executivos de outros países têm vindo trabalhar em empresas brasileiras. E a maioria deles se depara com uma grande dificuldade, que é entender a maneira como nós contamos o tempo no Brasil.

Uma pergunta simples é: "Quanto vai demorar para o trabalho ficar pronto?" Uma resposta como "12 minutos" nem passaria pela cabeça de um brasileiro. Porque nós somos muito mais criativos do que isso. Portanto, a resposta mais usual é: depende.

E no Brasil, depende é uma medida quântica, porque envolve várias incógnitas, e todas elas, desfavoráveis. Em algumas situações, depende pode até significar imediatamente. Mas esse tipo de resultado, até hoje, só foi conseguido com cobaias, em testes de laboratório.

Outra resposta é já já. Para quem ouve, já já pode parecer uma medida de tempo mais rápida do que já. Mas é o contrário. Já quer dizer agora. Já já quer dizer "assim que eu terminar o que estou fazendo, vou pensar a respeito".

E tem também o logo. Logo quer dizer que uma providência pode levar entre 5 minutos e centenas de anos. Por exemplo, "logo chegaremos a Marte".

Outra frase que confunde é na semana que vem. Como todas as semanas futuras cedo ou tarde virão, qualquer semana entre a próxima e a última do século 21 pode ser tecnicamente classificada como a semana que vem.

E tem também o um minutinho, que é um intervalo de tempo que nada tem a ver com 60 segundos e raramente leva menos que 20 minutos.

E finalmente há o veja bem e o com certeza. A diferença entre os dois é que o veja bem é um com certeza um pouco mais detalhado. Mas no fundo, as duas expressões querem dizer a mesma coisa: ou seja, depende.

Como se vê, nós não somos um povo muito complicado. Nós até que nos entendemos muito bem. Quem vem de fora é que não compreende que amanhã sem falta significa preciso de mais um dia para pensar numa boa desculpa.

Max Gehringer, para CBN.

I have a custom object that linked to account that contains revenue information.

 

The Custom Object can have many rows, and I need to find the Sum of one column for the all rows.

 

I have created a trigger that fires on the update of the custom object.

 

If I add the account ID and the revenue into a map, how can I add them all together?

 

Something Like?

 

Map<Id, Double> AccUpdate = new Map<Id, Double>();

 

Sum WHERE Account ID's are the same?


Thanks in Advance.

 

Matt

 

Hi,

 

I have spent 9 hours on this trigger and I really am unsure why I am getting these errors? The thing is this is simular to many tiggers I have wrote in the past so its hard for me to understand.


The trigger is trying to change the currency of a Lead to USD whenever the record type is NA Leads.

 

I would appreciate any help at all. Many Thanks for your time.

 

Trigger:

trigger NALeadsWeb2LeadCurrencyChange on Lead (before update) { Map<String,String> LeadMap = new Map<String,String>(); for(Lead l:trigger.new){ if (l.RecordTypeId == [ select Id from RecordType where Name = 'NA Lead' and SobjectType = 'Lead' limit 1].id){ LeadMap.put(l.id, 'USD'); } } List<Lead> recordsforupdates = new list<Lead>(); for(Lead nl : [Select Id, CurrencyIsoCode from Lead where Id IN : LeadMap.keySet()]){ if (LeadMap.containsKey(nl.Id)){ nl.CurrencyIsoCode = 'USD'; recordsforupdates.add(nl); } } update recordsforupdates; }

 

Test Case:

@isTest private class NALeadsWeb2LeadCurrencyChanger { static testMethod void myUnitTest() { // TO DO: implement unit test Lead lead = new Lead(firstname= 'TestTestTest', lastname = 'Testing', company = 'Salesforce.com', email = 't.test@salesforce.com', recordtypeid =[select Id from RecordType where Name = 'ADMIN Master Web to Lead' and SobjectType = 'Lead' limit 1].Id); insert lead; lead.RecordTypeId=[select Id from RecordType where Name = 'NA Lead' and SobjectType = 'Lead' limit 1].id; update lead; } }

 

Error:

*** Beginning Test 1: NALeadsWeb2LeadCurrencyChanger.static testMethod void myUnitTest() 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 10, column 22: SOQL query with 1 row finished in 5 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 11, column 4: Insert: SOBJECT:Lead 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 11, column 4: DML Operation executed in 146 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 13, column 22: SOQL query with 1 row finished in 4 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4: Update: SOBJECT:Lead *** Beginning NALeadsWeb2LeadCurrencyChange on Lead trigger event BeforeUpdate for 00QS0000003OZhJ 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 3, column 2: SelectLoop:LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 4, column 25: SOQL query with 1 row finished in 16 ms 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 3, column 2: Number of iterations: 1 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 2: SelectLoop:LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 16: SOQL query with 1 row finished in 21 ms 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 2: Number of iterations: 1 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: Update: LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: DML Operation executed in 2 ms System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00QS0000003OZhJ) is currently in trigger NALeadsWeb2LeadCurrencyChange, therefore it cannot recursively update itself: [] Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2 Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 4 out of 100 Number of query rows: 4 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 3 out of 100 Number of DML rows: 3 out of 500 Number of script statements: 10 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Total email recipients queued to be sent : 0 Static variables and sizes: NALeadsWeb2LeadCurrencyChange:LeadMap:29 NALeadsWeb2LeadCurrencyChange:recordsforupdates:58 Stack frame variables and sizes: Frame0 l:0 nl:0 *** Ending NALeadsWeb2LeadCurrencyChange on Lead trigger event BeforeUpdate for 00QS0000003OZhJ 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4: DML Operation executed in 74 ms System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, NALeadsWeb2LeadCurrencyChange: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00QS0000003OZhJ) is currently in trigger NALeadsWeb2LeadCurrencyChange, therefore it cannot recursively update itself: [] Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: [] Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4 External entry point Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 2 out of 100 Number of query rows: 2 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 2 out of 100 Number of DML rows: 2 out of 500 Number of script statements: 4 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Total email recipients queued to be sent : 0 Stack frame variables and sizes: Frame0 *** Ending Test NALeadsWeb2LeadCurrencyChanger.static testMethod void myUnitTest()

 


 


 

I keep getting this error when running the test case on the trigger and I have no idea why.

 

Can anybody shed any light on the situation?

 

The Trigger and Test Case are Below.

 

 

trigger UpdateTeamMembers on Account (before update, before insert) { AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add Map<Id,Id> ForDel = new Map<Id,Id>(); //map of team members and shares to delete for(Account a:trigger.new){ //for all changing accounts if (trigger.old[0].X2ndOwnerTM__c != a.X2ndOwnerTM__c ){ //if the owner has changed ForDel.put(a.Id,trigger.old[0].X2ndOwnerTM__c); //add account id and old user id to map AccountTeamMember Teammemberad=new AccountTeamMember(); Teammemberad.AccountId=a.id; Teammemberad.UserId=a.X2ndOwnerTM__c; Teammemberad.TeamMemberRole = a.X2nd_Owner_Role__c; newmembers.add(Teammemberad); //add new team member to list } } //del all old account shares List<AccountShare> delASQ = [Select Id, AccountId, UserOrGroupId FROM AccountShare WHERE AccountId IN : ForDel.keySet()]; List<AccountShare> delAS = new List<AccountShare>(); for(AccountShare ASfor: delASQ){ if(ASfor.UserOrGroupId==ForDel.get(ASfor.AccountId)){ delAS.add(ASfor); } } delete delAS; // delete All Account Share //del all old team members List<AccountTeamMember> delATMQ = [Select Id, AccountId, UserId FROM AccountTeamMember WHERE AccountId IN : ForDel.keySet()]; List<AccountTeamMember> delATM = new List<AccountTeamMember>(); for(AccountTeamMember ATMfor: delATMQ){ if(ATMFor.UserId==ForDel.get(ATMfor.AccountId)){ delATM.add(ATMfor); } } delete delATM; Database.SaveResult[] lsr = Database.insert(newmembers,false);//insert any valid members then add their share entry if they were successfully added Integer newcnt=0; for(Database.SaveResult sr:lsr){ if(!sr.isSuccess()){ //if not success throw error message Database.Error emsg =sr.getErrors()[0]; system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg); }else{ newShare.add(new AccountShare (UserOrGroupId=newmembers[newcnt].UserId, AccountId=newmembers[newcnt].Accountid, AccountAccessLevel='Edit',OpportunityAccessLevel='Edit',ContactAccessLevel='Edit', CaseAccessLevel='Edit' )); } newcnt++; } Database.SaveResult[] lsr0 =Database.insert(newShare,false); //insert the new shares Integer newcnt0=0; for(Database.SaveResult sr0:lsr0){ if(!sr0.isSuccess()){ Database.Error emsg0=sr0.getErrors()[0]; system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0); } newcnt0++; } }

 

 

@isTest private class UpdateTeamMembersTest { static testMethod void myUnitTest() { // TO DO: implement unit test Account account = new Account( Name = 'Apex Test Account', Type = 'Customer', OwnerId='00520000000rd6FAAQ', IF_City__c='Singapore', IF_PostalCode__c='629065', IF_Street__c='41 Joo Koon Circle', IF_Region__c='NULL', IF_Country__c='Singapore', Phone='+65 6862 3811', IF_Fax__c='NULL', Industry='Others', IF_Classification__c='D (<25.000 EUR)', RecordTypeId='012200000004g6HAAQ', IF_Name2__c='NULL', IF_Name4__c='NULL', Website='www.echthaar.nl', UsePOBoxAddress__c='NULL', IF_POBoxNumber__c='NULL', IF_POBoxPostalCode__c='NULL',Type_Detail__c='NULL', NA_Key_Account__c='NULL'); insert account; //select statement to get the id of account created account AccID = [select id from account where IF_Street__c = '41 Joo Koon Circle' limit 1]; AccountSetupForm__c accsetup = new AccountSetupForm__c( AccountName__c= AccID.Id, ACH_WIRE_CHECK__c = 'CHECK', Attachment_Media__c ='No Attachment', Attachment_Reports__c = 'No Attachment', CurrencyIsoCode='USD', H100MinimumOrder__c=TRUE, Invoice_Currency__c='USD (US Dollars)', Invoice_Frequency__c='Weekly', Invoice_Media_Type__c='Email', Layout_Type__c='Summary by Date and Product', Name='41 Joo Koon Circle', No_Costomer_References__c=FALSE, Primary_Email__c='stan@temp.com', Rebate__c=FALSE, RecordTypeId='012200000004o6TAAQ', Required_Customer_References__c=FALSE, Same_as_Bill_To_Address__c=FALSE, Same_as_Billing_Contact__c = FALSE, Status__c='Draft', Template_Type__c='Standard', Terms__c='Net 15', Validated_Customer_References__c=FALSE); insert accsetup; account.X2ndOwnerTM__c = '005200000015nd1AAA'; account.X2nd_Owner_Role__c = 'Temp'; update account; } }

 

 

 

 

 

 Hi,

 

I am currently stuck on a trigger. I have 2 Lists which I want to loop through to delete all the record matching the criteria.

 

I would like to loop through to create a List of AccountShare records with the values in LAccId and LUserId. The query will look something like this:


List<AccountShare> accsharedel = [SELECT Id FROM AccountShare where (AccountId =  LAccId AND UserOrGroup = LUserId)];

 

How can I loop through the LAccId list and the LUserId list to populate the accsharedel list which I can then delete?


Thanks in advance.

 

 

 

trigger UpdateTeamMembers on Account (before update) { AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add Integer delcnt=0; List<String> LAccId = new List<String>(); List<String> LUserId = new List<String>(); for(Account a:trigger.new){ if (trigger.old[0].X2ndOwnerTM__c != a.X2ndOwnerTM__c ){ AccountTeamMember Teammemberad=new AccountTeamMember(); Teammemberad.AccountId=a.id; Teammemberad.UserId=a.X2ndOwnerTM__c; Teammemberad.TeamMemberRole = a.X2ndOwnerRole__c; newmembers.add(Teammemberad); LAccId.add(delcnt,a.id); LUserId.add(delcnt,a.X2ndOwnerTM__c); delcnt++; } } List<AccountTeamMember> DelATM = new List<AccountTeamMember>(); List<AccountShare> DelAS = new List<AccountShare>();

 

 

 

Hi,

 

I am still new to coding triggers and coding in general but I have a problem that I am struggling to get around.

 

The trigger I currently have fires after update and transfers a completed field to another objects field. 

 

The problem is this happens after every Account update, I need this only to happen after the one field (IF_SAP__c) has changed, and if that field hasn't changed then do not do the update.

 

 This my current code, I understand I can use the Trigger.old, but I dont know how to compare the Trigger.old to the Trigger.new. Can some one please point me in the right direction.

 

Many Thanks


Matt

 

 

trigger UpdateToAccSetupForm on Account (after update) { Map<String, String> SetupFormMap = new Map<String, String>(); for (Account acc : System.Trigger.new){ if (acc.IF_SAP__c != null){ SetupFormMap.put(acc.ID, acc.IF_SAP__c); } else{ } } List<AccountSetupForm__c> recordsforupdates = new list<AccountSetupForm__c>(); for (AccountSetupForm__c aacc :[Select Id, AccountName__c, SAP_Number__c from AccountSetupForm__c where AccountName__c IN : SetupFormMap.keySet()] ){ if (SetupFormMap.containsKey(aacc.AccountName__c)) { aacc.SAP_Number__c = SetupFormMap.get(aacc.AccountName__c); recordsforupdates.add(aacc); } } update recordsforupdates; }

 

 

 

Hi,

I am still new to Apex, and learning more functions and expected this to work:

 

 

trigger DelCustPrevent on Account (before delete) { for (Account a : Trigger.old) { if (a.IF_SAP__c != NULL && a.RecordTypeId.equals('0122000000000lZAAQ')){ a.addError('You do not have permission to delete this record'); } { } } }

 

Can someone please help me, the error is on the RecordTypeId check, how can I make this  Boolean check?

 

Regards

 

Matt

 

 

 

 

 Hi,

 

I have created a trigger and tested on the sandbox and it works fine. I implemented it on the production last night and recieved the following errors this morning.

 

 

Apex script unhandled trigger exception by user/organization: 00520000000lct9/00D200000000Aq6 UpdateToAccSetupForm: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0220000005vt34AAA; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, This category is under construction. An email notofication will be sent when available.: [] Trigger.UpdateToAccSetupForm: line 21, column 2

 

 

 

 I have no idea why I am getting these errors, I recieved around 4 of them, can somebody please shine a light on this for me because I thought I had mastered the trigger.

 

Thanks in advance.

 

Here is my code:

 

 

trigger UpdateToAccSetupForm on Account (after update) { //Map to store SAP number - Map key is AccountID Map<String, String> SetupFormMap = new Map<String, String>(); //Loop for each update for (Account acc : System.Trigger.new){ //If SAP Number is not Null if (acc.IF_SAP__c != null){ //Put SAP ID into map. SetupFormMap.put(acc.ID, acc.IF_SAP__c); } else{ } } //Create a list to put all records in that need updating. List<AccountSetupForm__c> recordsforupdates = new list<AccountSetupForm__c>(); //For each key that is in the map and has an AccountSetupForm for (AccountSetupForm__c aacc :[Select Id, AccountName__c, SAP_Number__c from AccountSetupForm__c where AccountName__c IN : SetupFormMap.keySet()] ){ //If the Map contains the AccountSetupForm Foreign Key if (SetupFormMap.containsKey(aacc.AccountName__c)){ //Take SAP Number from map and add to AccountSetupForm aacc.SAP_Number__c = SetupFormMap.get(aacc.AccountName__c); //Add updated AccountSetupForm record to list. recordsforupdates.add(aacc); } } //Update all AccountSetupForm records update recordsforupdates; }

 

 

 

 

Hi,

 

I have managed to create one trigger in my time with Salesforce which works perfectly but am working on another and am really stuck. Myprevious trigger was for validation, so im lost with this one.

 

I need field data to be passed from the account page to a field custom object. 

The Custom Objects Name is the AccountID. I have put the data that needs passing into a map, how do I then take it out of the map and place it into the field?

I need the field data from SAP_Number__c in account be placed into a field of the same name in the custom object AccountSetupForm__c.

 

Here is what I have so far, any help would be appriciated.

 

 

trigger UpdateToAccSetupForm on Account (after insert, after update) {
    Map<String, String> SetupFormMap = new Map<String, String>();
    for (Account acc : System.Trigger.new){
        if (acc.IF_SAP__c != null){   
            SetupFormMap.put(acc.ID, acc.IF_SAP__c);
        }
        else{
           
        }
        for (Account aacc :[Select AccountName__c, SAP_Number__c from AccountSetupForm__c where
        AccountName__c IN : SetupFormMap.keySet()] ){
           
           
        }
       
    }

 

Thanks

 

Matt

I have a custom object that linked to account that contains revenue information.

 

The Custom Object can have many rows, and I need to find the Sum of one column for the all rows.

 

I have created a trigger that fires on the update of the custom object.

 

If I add the account ID and the revenue into a map, how can I add them all together?

 

Something Like?

 

Map<Id, Double> AccUpdate = new Map<Id, Double>();

 

Sum WHERE Account ID's are the same?


Thanks in Advance.

 

Matt

 

Hi

 

I have an application custom object and recommender custom object, I have an look up relationship from the application to the recommender.I have an pick list field status in both of these objects, and the values are received and not received.Once , I have the status pick list field  as received in the recommender custom object, I need even the status pick list field in the application field to automatically change to received.Can anyone give me an idea on writing a trigger to kick start with this....I would appreciate any help...

 

thank you

 

 

  • April 25, 2010
  • Like
  • 0

Hi,

 

I have spent 9 hours on this trigger and I really am unsure why I am getting these errors? The thing is this is simular to many tiggers I have wrote in the past so its hard for me to understand.


The trigger is trying to change the currency of a Lead to USD whenever the record type is NA Leads.

 

I would appreciate any help at all. Many Thanks for your time.

 

Trigger:

trigger NALeadsWeb2LeadCurrencyChange on Lead (before update) { Map<String,String> LeadMap = new Map<String,String>(); for(Lead l:trigger.new){ if (l.RecordTypeId == [ select Id from RecordType where Name = 'NA Lead' and SobjectType = 'Lead' limit 1].id){ LeadMap.put(l.id, 'USD'); } } List<Lead> recordsforupdates = new list<Lead>(); for(Lead nl : [Select Id, CurrencyIsoCode from Lead where Id IN : LeadMap.keySet()]){ if (LeadMap.containsKey(nl.Id)){ nl.CurrencyIsoCode = 'USD'; recordsforupdates.add(nl); } } update recordsforupdates; }

 

Test Case:

@isTest private class NALeadsWeb2LeadCurrencyChanger { static testMethod void myUnitTest() { // TO DO: implement unit test Lead lead = new Lead(firstname= 'TestTestTest', lastname = 'Testing', company = 'Salesforce.com', email = 't.test@salesforce.com', recordtypeid =[select Id from RecordType where Name = 'ADMIN Master Web to Lead' and SobjectType = 'Lead' limit 1].Id); insert lead; lead.RecordTypeId=[select Id from RecordType where Name = 'NA Lead' and SobjectType = 'Lead' limit 1].id; update lead; } }

 

Error:

*** Beginning Test 1: NALeadsWeb2LeadCurrencyChanger.static testMethod void myUnitTest() 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 10, column 22: SOQL query with 1 row finished in 5 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 11, column 4: Insert: SOBJECT:Lead 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 11, column 4: DML Operation executed in 146 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 13, column 22: SOQL query with 1 row finished in 4 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4: Update: SOBJECT:Lead *** Beginning NALeadsWeb2LeadCurrencyChange on Lead trigger event BeforeUpdate for 00QS0000003OZhJ 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 3, column 2: SelectLoop:LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 4, column 25: SOQL query with 1 row finished in 16 ms 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 3, column 2: Number of iterations: 1 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 2: SelectLoop:LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 16: SOQL query with 1 row finished in 21 ms 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 2: Number of iterations: 1 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: Update: LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: DML Operation executed in 2 ms System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00QS0000003OZhJ) is currently in trigger NALeadsWeb2LeadCurrencyChange, therefore it cannot recursively update itself: [] Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2 Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 4 out of 100 Number of query rows: 4 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 3 out of 100 Number of DML rows: 3 out of 500 Number of script statements: 10 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Total email recipients queued to be sent : 0 Static variables and sizes: NALeadsWeb2LeadCurrencyChange:LeadMap:29 NALeadsWeb2LeadCurrencyChange:recordsforupdates:58 Stack frame variables and sizes: Frame0 l:0 nl:0 *** Ending NALeadsWeb2LeadCurrencyChange on Lead trigger event BeforeUpdate for 00QS0000003OZhJ 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4: DML Operation executed in 74 ms System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, NALeadsWeb2LeadCurrencyChange: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00QS0000003OZhJ) is currently in trigger NALeadsWeb2LeadCurrencyChange, therefore it cannot recursively update itself: [] Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: [] Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4 External entry point Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 2 out of 100 Number of query rows: 2 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 2 out of 100 Number of DML rows: 2 out of 500 Number of script statements: 4 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Total email recipients queued to be sent : 0 Stack frame variables and sizes: Frame0 *** Ending Test NALeadsWeb2LeadCurrencyChanger.static testMethod void myUnitTest()

 


 


 

F

Hi,

 

When I try to modify a field in an object I get this error(which is actually in a trigger).

 

 Update failed. First exception on row 0 with id; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, : execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 2 with id; first error: FIELD_INTEGRITY_EXCEPTION, Value does not exist or does not match filter criteria. Click icon to select a value.: [] 

 

Pls. let me know how to solve this issue and also if you need more details

 

Message Edited by gv on 02-18-2010 08:42 AM
  • February 17, 2010
  • Like
  • 0

I keep getting this error when running the test case on the trigger and I have no idea why.

 

Can anybody shed any light on the situation?

 

The Trigger and Test Case are Below.

 

 

trigger UpdateTeamMembers on Account (before update, before insert) { AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add Map<Id,Id> ForDel = new Map<Id,Id>(); //map of team members and shares to delete for(Account a:trigger.new){ //for all changing accounts if (trigger.old[0].X2ndOwnerTM__c != a.X2ndOwnerTM__c ){ //if the owner has changed ForDel.put(a.Id,trigger.old[0].X2ndOwnerTM__c); //add account id and old user id to map AccountTeamMember Teammemberad=new AccountTeamMember(); Teammemberad.AccountId=a.id; Teammemberad.UserId=a.X2ndOwnerTM__c; Teammemberad.TeamMemberRole = a.X2nd_Owner_Role__c; newmembers.add(Teammemberad); //add new team member to list } } //del all old account shares List<AccountShare> delASQ = [Select Id, AccountId, UserOrGroupId FROM AccountShare WHERE AccountId IN : ForDel.keySet()]; List<AccountShare> delAS = new List<AccountShare>(); for(AccountShare ASfor: delASQ){ if(ASfor.UserOrGroupId==ForDel.get(ASfor.AccountId)){ delAS.add(ASfor); } } delete delAS; // delete All Account Share //del all old team members List<AccountTeamMember> delATMQ = [Select Id, AccountId, UserId FROM AccountTeamMember WHERE AccountId IN : ForDel.keySet()]; List<AccountTeamMember> delATM = new List<AccountTeamMember>(); for(AccountTeamMember ATMfor: delATMQ){ if(ATMFor.UserId==ForDel.get(ATMfor.AccountId)){ delATM.add(ATMfor); } } delete delATM; Database.SaveResult[] lsr = Database.insert(newmembers,false);//insert any valid members then add their share entry if they were successfully added Integer newcnt=0; for(Database.SaveResult sr:lsr){ if(!sr.isSuccess()){ //if not success throw error message Database.Error emsg =sr.getErrors()[0]; system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg); }else{ newShare.add(new AccountShare (UserOrGroupId=newmembers[newcnt].UserId, AccountId=newmembers[newcnt].Accountid, AccountAccessLevel='Edit',OpportunityAccessLevel='Edit',ContactAccessLevel='Edit', CaseAccessLevel='Edit' )); } newcnt++; } Database.SaveResult[] lsr0 =Database.insert(newShare,false); //insert the new shares Integer newcnt0=0; for(Database.SaveResult sr0:lsr0){ if(!sr0.isSuccess()){ Database.Error emsg0=sr0.getErrors()[0]; system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0); } newcnt0++; } }

 

 

@isTest private class UpdateTeamMembersTest { static testMethod void myUnitTest() { // TO DO: implement unit test Account account = new Account( Name = 'Apex Test Account', Type = 'Customer', OwnerId='00520000000rd6FAAQ', IF_City__c='Singapore', IF_PostalCode__c='629065', IF_Street__c='41 Joo Koon Circle', IF_Region__c='NULL', IF_Country__c='Singapore', Phone='+65 6862 3811', IF_Fax__c='NULL', Industry='Others', IF_Classification__c='D (<25.000 EUR)', RecordTypeId='012200000004g6HAAQ', IF_Name2__c='NULL', IF_Name4__c='NULL', Website='www.echthaar.nl', UsePOBoxAddress__c='NULL', IF_POBoxNumber__c='NULL', IF_POBoxPostalCode__c='NULL',Type_Detail__c='NULL', NA_Key_Account__c='NULL'); insert account; //select statement to get the id of account created account AccID = [select id from account where IF_Street__c = '41 Joo Koon Circle' limit 1]; AccountSetupForm__c accsetup = new AccountSetupForm__c( AccountName__c= AccID.Id, ACH_WIRE_CHECK__c = 'CHECK', Attachment_Media__c ='No Attachment', Attachment_Reports__c = 'No Attachment', CurrencyIsoCode='USD', H100MinimumOrder__c=TRUE, Invoice_Currency__c='USD (US Dollars)', Invoice_Frequency__c='Weekly', Invoice_Media_Type__c='Email', Layout_Type__c='Summary by Date and Product', Name='41 Joo Koon Circle', No_Costomer_References__c=FALSE, Primary_Email__c='stan@temp.com', Rebate__c=FALSE, RecordTypeId='012200000004o6TAAQ', Required_Customer_References__c=FALSE, Same_as_Bill_To_Address__c=FALSE, Same_as_Billing_Contact__c = FALSE, Status__c='Draft', Template_Type__c='Standard', Terms__c='Net 15', Validated_Customer_References__c=FALSE); insert accsetup; account.X2ndOwnerTM__c = '005200000015nd1AAA'; account.X2nd_Owner_Role__c = 'Temp'; update account; } }

 

 

 

 

 

 Hi,

 

I am currently stuck on a trigger. I have 2 Lists which I want to loop through to delete all the record matching the criteria.

 

I would like to loop through to create a List of AccountShare records with the values in LAccId and LUserId. The query will look something like this:


List<AccountShare> accsharedel = [SELECT Id FROM AccountShare where (AccountId =  LAccId AND UserOrGroup = LUserId)];

 

How can I loop through the LAccId list and the LUserId list to populate the accsharedel list which I can then delete?


Thanks in advance.

 

 

 

trigger UpdateTeamMembers on Account (before update) { AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add Integer delcnt=0; List<String> LAccId = new List<String>(); List<String> LUserId = new List<String>(); for(Account a:trigger.new){ if (trigger.old[0].X2ndOwnerTM__c != a.X2ndOwnerTM__c ){ AccountTeamMember Teammemberad=new AccountTeamMember(); Teammemberad.AccountId=a.id; Teammemberad.UserId=a.X2ndOwnerTM__c; Teammemberad.TeamMemberRole = a.X2ndOwnerRole__c; newmembers.add(Teammemberad); LAccId.add(delcnt,a.id); LUserId.add(delcnt,a.X2ndOwnerTM__c); delcnt++; } } List<AccountTeamMember> DelATM = new List<AccountTeamMember>(); List<AccountShare> DelAS = new List<AccountShare>();

 

 

 

Hi,

 

I am still new to coding triggers and coding in general but I have a problem that I am struggling to get around.

 

The trigger I currently have fires after update and transfers a completed field to another objects field. 

 

The problem is this happens after every Account update, I need this only to happen after the one field (IF_SAP__c) has changed, and if that field hasn't changed then do not do the update.

 

 This my current code, I understand I can use the Trigger.old, but I dont know how to compare the Trigger.old to the Trigger.new. Can some one please point me in the right direction.

 

Many Thanks


Matt

 

 

trigger UpdateToAccSetupForm on Account (after update) { Map<String, String> SetupFormMap = new Map<String, String>(); for (Account acc : System.Trigger.new){ if (acc.IF_SAP__c != null){ SetupFormMap.put(acc.ID, acc.IF_SAP__c); } else{ } } List<AccountSetupForm__c> recordsforupdates = new list<AccountSetupForm__c>(); for (AccountSetupForm__c aacc :[Select Id, AccountName__c, SAP_Number__c from AccountSetupForm__c where AccountName__c IN : SetupFormMap.keySet()] ){ if (SetupFormMap.containsKey(aacc.AccountName__c)) { aacc.SAP_Number__c = SetupFormMap.get(aacc.AccountName__c); recordsforupdates.add(aacc); } } update recordsforupdates; }

 

 

 

Hi all,

 

I am new in Apex and Salesforce. 

I have seen some posts to that issue.

But is there also a simple way (for example copy and paste) to migrate my trigger from Sandbox to production environment?

 

Thanks! 

Hi,

I am still new to Apex, and learning more functions and expected this to work:

 

 

trigger DelCustPrevent on Account (before delete) { for (Account a : Trigger.old) { if (a.IF_SAP__c != NULL && a.RecordTypeId.equals('0122000000000lZAAQ')){ a.addError('You do not have permission to delete this record'); } { } } }

 

Can someone please help me, the error is on the RecordTypeId check, how can I make this  Boolean check?

 

Regards

 

Matt

 

 

 

 

 Hi,

 

I have created a trigger and tested on the sandbox and it works fine. I implemented it on the production last night and recieved the following errors this morning.

 

 

Apex script unhandled trigger exception by user/organization: 00520000000lct9/00D200000000Aq6 UpdateToAccSetupForm: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0220000005vt34AAA; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, This category is under construction. An email notofication will be sent when available.: [] Trigger.UpdateToAccSetupForm: line 21, column 2

 

 

 

 I have no idea why I am getting these errors, I recieved around 4 of them, can somebody please shine a light on this for me because I thought I had mastered the trigger.

 

Thanks in advance.

 

Here is my code:

 

 

trigger UpdateToAccSetupForm on Account (after update) { //Map to store SAP number - Map key is AccountID Map<String, String> SetupFormMap = new Map<String, String>(); //Loop for each update for (Account acc : System.Trigger.new){ //If SAP Number is not Null if (acc.IF_SAP__c != null){ //Put SAP ID into map. SetupFormMap.put(acc.ID, acc.IF_SAP__c); } else{ } } //Create a list to put all records in that need updating. List<AccountSetupForm__c> recordsforupdates = new list<AccountSetupForm__c>(); //For each key that is in the map and has an AccountSetupForm for (AccountSetupForm__c aacc :[Select Id, AccountName__c, SAP_Number__c from AccountSetupForm__c where AccountName__c IN : SetupFormMap.keySet()] ){ //If the Map contains the AccountSetupForm Foreign Key if (SetupFormMap.containsKey(aacc.AccountName__c)){ //Take SAP Number from map and add to AccountSetupForm aacc.SAP_Number__c = SetupFormMap.get(aacc.AccountName__c); //Add updated AccountSetupForm record to list. recordsforupdates.add(aacc); } } //Update all AccountSetupForm records update recordsforupdates; }

 

 

 

 

Hi,

 

I have managed to create one trigger in my time with Salesforce which works perfectly but am working on another and am really stuck. Myprevious trigger was for validation, so im lost with this one.

 

I need field data to be passed from the account page to a field custom object. 

The Custom Objects Name is the AccountID. I have put the data that needs passing into a map, how do I then take it out of the map and place it into the field?

I need the field data from SAP_Number__c in account be placed into a field of the same name in the custom object AccountSetupForm__c.

 

Here is what I have so far, any help would be appriciated.

 

 

trigger UpdateToAccSetupForm on Account (after insert, after update) {
    Map<String, String> SetupFormMap = new Map<String, String>();
    for (Account acc : System.Trigger.new){
        if (acc.IF_SAP__c != null){   
            SetupFormMap.put(acc.ID, acc.IF_SAP__c);
        }
        else{
           
        }
        for (Account aacc :[Select AccountName__c, SAP_Number__c from AccountSetupForm__c where
        AccountName__c IN : SetupFormMap.keySet()] ){
           
           
        }
       
    }

 

Thanks

 

Matt