You need to sign in to do that
Don't have an account?

get parent record
In below code am getting , am trying so many different method sample lot is parent and sample transaction is child could you please suggets me what is the reason for below error
Compile Error: Didn't understand relationship 'Sample_Transaction__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 44
Compile Error: Didn't understand relationship 'Sample_Transaction__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 44
trigger quantityleft on Sample_Transaction__c (after insert,after update,after delete,after undelete) { List<Sample_Lot__c> list_Account= new List<Sample_Lot__c>(); set<Id> set_Opportunity = new set<Id>(); for(Sample_Transaction__c objOpp: trigger.new){ set_Opportunity.add(objOpp.Sample_Lot_ID__c); } Decimal Sum; for(Sample_Lot__c objAccount : [SELECT Id,(SELECT Id,sample_lot FROM Sample_Transaction__c),Quantity_Left__c FROM Sample_Lot__c WHERE Id IN: set_Opportunity]){ Sum=0; for(Sample_Transaction__c objOpp01: objAccount.Quantity_Left__c){ Sum+=objOpp01.Confirmed_Quantity__c ; } objAccount.Quantity_left__c =Sum; list_Account.add(objAccount); } update list_Account; }
So you want to sum all the register of the child object, and show in the field Quantity__c the total, is it?
if is it that you want, you must do something like that:
Decimal Sum;
for(Sample_Transaction__c sample_transaction : [SELECT Id,Sample_Lot_ID__c, Confirmed_Quantity__c FROM Sample_Transaction__c WHERE Id = : set_Opportunity]){
Sum+= sample_transaction.Confirmed_Quantity__c;
for(Sample_Lot__c objAccount : [SELECT Id, Quantity_Left__c FROM Sample_Lot__c WHERE Id = : sample_transaction.Sample_Lot_ID__c]){
objAccount.Quantity_left__c = Sum ;
list_Account.add(objAccount);
}
}
update list_Account;
All Answers
In the line 8 of your code, you must change the follow code:
for(Sample_Lot__c objAccount : [SELECT Id, SELECT Id,sample_lot FROM Sample_Transaction__c),Quantity_Left__c FROM Sample_Lot__c WHERE Id IN: set_Opportunity])
to this code:
for(Sample_Lot__c objAccount : [SELECT Id,(SELECT Id,sample_lot FROM Sample_Transactions__r),Quantity_Left__c FROM Sample_Lot__c WHERE Id IN: set_Opportunity])
Note: When you make a SELECT inside of another, you must use the plural name of the object and change the __c for __r.
Best Regards
Rafael
For example lets consider Account and Opportunity object. Here I have taken the example of "Account Name" field in Opportunity which is a lookup to Account. This means Account is a parent and Opportunity is a child.
Now if I want the Account and its related Opportunities in a single query, this is how you should write the SOQL - If it is a Custom Object, you will have to append "__r" to the Child Relationship Name.
In your case, you will have to go to the Lookup field ( Lookup field pointing to the Sample_Lot__c ) on the Sample_Transaction__c object and look on its Child Relationship Name and append "__r" to it.
Most probably it should look something like this -
Error: Compile Error: Variable does not exist: objAccount.Quantity_Left__c at line 21 column 45
for(Sample_Transaction__c objOpp01: Sample_Transactions__r.Quantity_Left__c){
Sum+=objOpp01.Confirmed_Quantity__c ;
}
i guess the below code has collection of sample lot created from transaction
for(Sample_Lot__c objAccount : [SELECT Id,(SELECT Id,Sample_Lot_ID__c FROM Sample_Transactions__r),Quantity_Left__c FROM Sample_Lot__c WHERE Id IN: set_Opportunity])
after this i would like to sum all the confirmed quantity from sample lot and update in quantity left field in sampel transcation obeject
in this scenario how to get sum of all confirmed quantity by looping the below line
for(Sample_Transaction__c objOpp01: Sample_Transactions__r.Quantity_Left__c){
Sum+=objOpp01.Confirmed_Quantity__c ;
}
https://developer.salesforce.com/forums/?id=906F0000000AtWEIA0
So you want to sum all the register of the child object, and show in the field Quantity__c the total, is it?
if is it that you want, you must do something like that:
Decimal Sum;
for(Sample_Transaction__c sample_transaction : [SELECT Id,Sample_Lot_ID__c, Confirmed_Quantity__c FROM Sample_Transaction__c WHERE Id = : set_Opportunity]){
Sum+= sample_transaction.Confirmed_Quantity__c;
for(Sample_Lot__c objAccount : [SELECT Id, Quantity_Left__c FROM Sample_Lot__c WHERE Id = : sample_transaction.Sample_Lot_ID__c]){
objAccount.Quantity_left__c = Sum ;
list_Account.add(objAccount);
}
}
update list_Account;
This field make the SUM automatically for you even you edit a child object.
Excellent your code compiled well and mine is not master child relation ship it is lookup one
your code complied nicely and when i tested it i noticed that nothing happened , in the below code in set_opputunity i guess am not storing the id
am using set_Opportunity.add(objOpp.Sample_Lot_ID__c) how to store the id of child
or(Sample_Transaction__c sample_transaction : [SELECT Id,Sample_Lot_ID__c, Confirmed_Quantity__c FROM Sample_Transaction__c WHERE Id = : set_Opportunity]){
WHERE Id = : set_Opportunity
for this:
WHERE Id = : : Trigger.newMap.keyset() limit 1
this getting the current register ID.
I thought this issue is due to am not adding id in set_oppurtunity so i changed to store id i may be wrong and after changing the code as suggested this time i got
Apex trigger quantityleft caused an unexpected exception, contact your administrator: quantityleft: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.quantityleft: line 17, column 1
what are we missing
39.0 APEX_CODE,FINEST;APEX_PROFILING,NONE;CALLOUT,NONE;DB,NONE;SYSTEM,FINE;VALIDATION,NONE;VISUALFORCE,NONE;WAVE,INFO;WORKFLOW,FINER 12:01:19.0 (329734)|USER_INFO|[EXTERNAL]|00524000001xWet|somasundaram.s@quintiles.com.prod.training|Eastern Standard Time|GMT-04:00 12:01:19.0 (355303)|EXECUTION_STARTED 12:01:19.0 (359036)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Sample_Transaction:a0i0E0000000YDu 12:01:19.0 (1315526)|CODE_UNIT_FINISHED|Validation:Sample_Transaction:a0i0E0000000YDu 12:01:19.0 (1323814)|EXECUTION_FINISHED 12:01:19.30 (30487746)|USER_INFO|[EXTERNAL]|00524000001xWet|somasundaram.s@quintiles.com.prod.training|Eastern Standard Time|GMT-04:00 12:01:19.30 (30500389)|EXECUTION_STARTED 12:01:19.30 (30504235)|CODE_UNIT_STARTED|[EXTERNAL]|01q0E000000Cexp|quantityleft on Sample_Transaction trigger event AfterUpdate for [a0i0E0000000YDu] 12:01:19.30 (30547560)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8 12:01:19.30 (30576874)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8 12:01:19.30 (30882525)|HEAP_ALLOCATE|[72]|Bytes:3 12:01:19.30 (30917382)|HEAP_ALLOCATE|[77]|Bytes:152 12:01:19.30 (30930150)|HEAP_ALLOCATE|[342]|Bytes:408 12:01:19.30 (30944185)|HEAP_ALLOCATE|[355]|Bytes:408 12:01:19.30 (30956531)|HEAP_ALLOCATE|[467]|Bytes:48 12:01:19.30 (30981086)|HEAP_ALLOCATE|[139]|Bytes:6 12:01:19.30 (31022984)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:22 12:01:19.30 (31123631)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:16 12:01:19.30 (31132070)|VARIABLE_SCOPE_BEGIN|[1]|this|quantityleft|true|false 12:01:19.30 (31175547)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x5c1aa4b9 12:01:19.30 (31202449)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:16 12:01:19.30 (31207502)|VARIABLE_SCOPE_BEGIN|[1]|this|quantityleft|true|false 12:01:19.30 (31221496)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x5c1aa4b9 12:01:19.30 (31225430)|STATEMENT_EXECUTE|[1] 12:01:19.30 (31227333)|STATEMENT_EXECUTE|[2] 12:01:19.30 (31230600)|HEAP_ALLOCATE|[2]|Bytes:8 12:01:19.30 (31260574)|HEAP_ALLOCATE|[50]|Bytes:5 12:01:19.30 (31283753)|HEAP_ALLOCATE|[56]|Bytes:5 12:01:19.30 (31289585)|HEAP_ALLOCATE|[64]|Bytes:7 12:01:19.30 (31317887)|SYSTEM_METHOD_ENTRY|[2]|System.debug(ANY) 12:01:19.30 (31345865)|USER_DEBUG|[2]|DEBUG|11111111 12:01:19.30 (31351803)|SYSTEM_METHOD_EXIT|[2]|System.debug(ANY) 12:01:19.30 (31355915)|STATEMENT_EXECUTE|[3] 12:01:19.30 (31360992)|HEAP_ALLOCATE|[3]|Bytes:4 12:01:19.30 (31396368)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>() 12:01:19.30 (31412860)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>() 12:01:19.30 (31433752)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4 12:01:19.30 (31444306)|VARIABLE_ASSIGNMENT|[3]|this.list_Account|[]|0x5c1aa4b9 12:01:19.30 (31446741)|STATEMENT_EXECUTE|[5] 12:01:19.30 (31452985)|HEAP_ALLOCATE|[5]|Bytes:4 12:01:19.30 (31466138)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>(Integer) 12:01:19.30 (31475885)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>(Integer) 12:01:19.30 (31503946)|VARIABLE_ASSIGNMENT|[5]|this.set_Opportunity|[]|0x5c1aa4b9 12:01:19.30 (31578663)|SYSTEM_METHOD_ENTRY|[7]|List<Sample_Transaction__c>.iterator() 12:01:19.30 (31689462)|SYSTEM_METHOD_EXIT|[7]|List<Sample_Transaction__c>.iterator() 12:01:19.30 (31707497)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext() 12:01:19.30 (31720155)|HEAP_ALLOCATE|[7]|Bytes:5 12:01:19.30 (31726045)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext() 12:01:19.30 (31746559)|VARIABLE_SCOPE_BEGIN|[7]|objOpp|Sample_Transaction__c|true|false 12:01:19.30 (38745700)|VARIABLE_ASSIGNMENT|[7]|objOpp|{"LastModifiedDate":"2017-06-08T16:01:19.000Z","Transfer_Executed__c":false,"Eloqua_Order__c":false,"decile__c":0.00,"Account_ID__c":"0012400001837s0AAA","Name":"ST-0041918","Quantity__c":7,"CUSTOMER__c":"Reckitt","CreatedById":"00524000001xWetAAE","OwnerId":"00524000001xWetAAE","Completed_Transactio (4 more) ...":false,"Address_ID__c":"a012400000tS8vZAAS","Parent_id__c":"a0h0E0000004ZHFQA2","RecordTypeId":"01224000000kJPQAA2","Person_Account_Last_ (7 more) ...":"TEST","Product__c":"a0e24000007krpgAAA","ID_18__c":"a0i0E0000000YDuQAM","Sample_Lot_ID__c":"a0h0E0000004ZHFQA2","IsDeleted":false,"SAsln__c":"1234","Person_Account_Crede (9 more) ...":"MD","SystemModstamp":"2017-06-08T16:01:19.000Z","Reckitt_Professional (17 more) ...":false,"UPDATE__c":false,"Transaction_Quantity (3 more) ...":-7,"CreatedDate":"2017-06-08T05:32:15.000Z","Id":"a0i0E0000000YDuQAM","Status__c":"Acknowledged","LastModifiedById":"00524000001xWetAAE","Person_Account_First (8 more) ...":"ROMAN"}|0x37505a2b 12:01:19.30 (38757544)|STATEMENT_EXECUTE|[7] 12:01:19.30 (38759366)|STATEMENT_EXECUTE|[9] 12:01:19.30 (38820056)|SYSTEM_METHOD_ENTRY|[9]|Set<Id>.add(Object) 12:01:19.30 (38848789)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4 12:01:19.30 (38858525)|SYSTEM_METHOD_EXIT|[9]|Set<Id>.add(Object) 12:01:19.30 (38867374)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext() 12:01:19.30 (38874679)|HEAP_ALLOCATE|[7]|Bytes:5 12:01:19.30 (38880079)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext() 12:01:19.30 (38889982)|VARIABLE_ASSIGNMENT|[7]|objOpp|null| 12:01:19.30 (38893549)|STATEMENT_EXECUTE|[12] 12:01:19.30 (38897011)|HEAP_ALLOCATE|[12]|Bytes:20 12:01:19.30 (38907145)|SYSTEM_METHOD_ENTRY|[12]|System.debug(ANY) 12:01:19.30 (38920219)|USER_DEBUG|[12]|DEBUG|22222222222222222222 12:01:19.30 (38923863)|SYSTEM_METHOD_EXIT|[12]|System.debug(ANY) 12:01:19.30 (38926237)|STATEMENT_EXECUTE|[13] 12:01:19.30 (38938317)|VARIABLE_ASSIGNMENT|[13]|this.Sum|null|0x5c1aa4b9 12:01:19.30 (38940403)|STATEMENT_EXECUTE|[14] 12:01:19.30 (38969011)|HEAP_ALLOCATE|[14]|Bytes:28 12:01:19.30 (38971415)|HEAP_ALLOCATE|[14]|Bytes:28 12:01:19.30 (38982491)|VARIABLE_ASSIGNMENT|[14]|this.Sum|0|0x5c1aa4b9 12:01:19.30 (38984374)|STATEMENT_EXECUTE|[15] 12:01:19.30 (38986798)|HEAP_ALLOCATE|[15]|Bytes:5 12:01:19.30 (38992695)|SYSTEM_METHOD_ENTRY|[15]|System.debug(ANY) 12:01:19.30 (39000545)|USER_DEBUG|[15]|DEBUG|99999 12:01:19.30 (39003958)|SYSTEM_METHOD_EXIT|[15]|System.debug(ANY) 12:01:19.30 (39007533)|HEAP_ALLOCATE|[16]|Bytes:97 12:01:19.30 (39016226)|HEAP_ALLOCATE|[16]|Bytes:4 12:01:19.30 (39024004)|HEAP_ALLOCATE|[16]|Bytes:7 12:01:19.30 (50334404)|SYSTEM_METHOD_ENTRY|[16]|Database.QueryLocator.iterator() 12:01:19.30 (50445220)|HEAP_ALLOCATE|[16]|Bytes:49 12:01:19.30 (50452924)|HEAP_ALLOCATE|[16]|Bytes:8 12:01:19.30 (50463199)|SYSTEM_METHOD_ENTRY|[7]|QueryLocatorIterator.QueryLocatorIterator() 12:01:19.30 (50465890)|STATEMENT_EXECUTE|[7] 12:01:19.30 (50474554)|SYSTEM_METHOD_EXIT|[7]|QueryLocatorIterator 12:01:19.30 (50480373)|HEAP_ALLOCATE|[16]|Bytes:28 12:01:19.30 (50494637)|HEAP_ALLOCATE|[16]|Bytes:8 12:01:19.30 (50496572)|HEAP_ALLOCATE|[16]|Bytes:8 12:01:19.30 (50500705)|VARIABLE_SCOPE_BEGIN|[15]|this|Database.QueryLocatorIterator|true|false 12:01:19.30 (50524257)|VARIABLE_ASSIGNMENT|[15]|this|{}|0x690e2c0a 12:01:19.30 (50527356)|VARIABLE_SCOPE_BEGIN|[15]|values|List<SObject>|true|false 12:01:19.30 (50531142)|VARIABLE_ASSIGNMENT|[15]|values|null| 12:01:19.30 (50532804)|VARIABLE_SCOPE_BEGIN|[15]|ql|Database.QueryLocator|true|false 12:01:19.30 (50544654)|VARIABLE_ASSIGNMENT|[15]|ql|{"query":"SELECT Id, Sample_Lo (77 more) ..."}|0x6d1b4d01 12:01:19.30 (50546890)|VARIABLE_SCOPE_BEGIN|[15]|totalNumRecords|Integer|false|false 12:01:19.30 (50550741)|VARIABLE_ASSIGNMENT|[15]|totalNumRecords|0 12:01:19.30 (50552460)|VARIABLE_SCOPE_BEGIN|[15]|queryMoreSize|Integer|false|false 12:01:19.30 (50554658)|VARIABLE_ASSIGNMENT|[15]|queryMoreSize|50000 12:01:19.30 (50621269)|HEAP_ALLOCATE|[16]|Bytes:28 12:01:19.30 (50627217)|SYSTEM_METHOD_EXIT|[16]|Database.QueryLocator.iterator() 12:01:19.30 (50640431)|METHOD_ENTRY|[16]||Database.QueryLocatorIterator.hasNext() 12:01:19.30 (50657199)|METHOD_EXIT|[16]||Database.QueryLocatorIterator.hasNext() 12:01:19.30 (50665268)|VARIABLE_ASSIGNMENT|[16]|sample_transaction|null| 12:01:19.30 (50668244)|STATEMENT_EXECUTE|[16] 12:01:19.30 (50681946)|STATEMENT_EXECUTE|[30] 12:01:19.30 (50684804)|HEAP_ALLOCATE|[30]|Bytes:11 12:01:19.30 (50692708)|SYSTEM_METHOD_ENTRY|[30]|System.debug(ANY) 12:01:19.30 (50705299)|USER_DEBUG|[30]|DEBUG|66666666666 12:01:19.30 (50708868)|SYSTEM_METHOD_EXIT|[30]|System.debug(ANY) 12:01:19.30 (51597519)|CODE_UNIT_FINISHED|quantityleft on Sample_Transaction trigger event AfterUpdate for [a0i0E0000000YDu] 12:01:19.30 (52432397)|EXECUTION_FINISHED 12:01:19.53 (53773759)|USER_INFO|[EXTERNAL]|00524000001xWet|somasundaram.s@quintiles.com.prod.training|Eastern Standard Time|GMT-04:00 12:01:19.53 (53783692)|EXECUTION_STARTED 12:01:19.53 (53786925)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:01I24000001drLB 12:01:19.53 (61373722)|WF_RULE_EVAL_BEGIN|Workflow 12:01:19.53 (61390780)|WF_CRITERIA_BEGIN|[Sample Transaction: ST-0041918 a0i0E0000000YDu]|Process_Submitted_Sample_Transactions30124000000QTOx|01Q24000000VBjh|ON_ALL_CHANGES|0 12:01:19.53 (61462815)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]true|Values: 12:01:19.53 (61466748)|WF_CRITERIA_END|true 12:01:19.53 (62001937)|WF_CRITERIA_BEGIN|[Sample Transaction: ST-0041918 a0i0E0000000YDu]|Process_Sample_Transaction_Reckitt_Orders30124000000QWgL|01Q24000000VDWp|ON_ALL_CHANGES|0 12:01:19.53 (62035143)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]true|Values: 12:01:19.53 (62038074)|WF_CRITERIA_END|true 12:01:19.53 (62046091)|WF_CRITERIA_BEGIN|[Sample Transaction: ST-0041918 a0i0E0000000YDu]|Process_Sample_Transaction_Reckitt_Transfer30124000000DIGt|01Q24000000LRlR|ON_RECURSIVE_UPDATE|0 12:01:19.53 (62062334)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]true|Values: 12:01:19.53 (62064035)|WF_CRITERIA_END|true 12:01:19.53 (62073606)|WF_SPOOL_ACTION_BEGIN|Workflow 12:01:19.53 (62092077)|WF_ACTION| Flow Trigger: 3; 12:01:19.53 (62094159)|WF_RULE_EVAL_END 12:01:19.53 (62655833)|WF_FLOW_ACTION_BEGIN|09L240000000Mti 12:01:19.53 (62671474)|WF_FLOW_ACTION_DETAIL|09L240000000Mti|[Sample Transaction: ST-0041918 a0i0E0000000YDu]|Id=09L240000000Mti|CurrentRule:Process_Sample_Transaction_Reckitt_Transfer30124000000DIGt (Id=01Q24000000LRlR) 12:01:19.62 (62708401)|FLOW_CREATE_INTERVIEW_BEGIN|00D0E0000000PY9|30024000000PRiy|30124000000QTOx 12:01:19.62 (64011524)|FLOW_CREATE_INTERVIEW_END|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|Process Submitted Sample Transactions 12:01:19.53 (64254243)|WF_FLOW_ACTION_DETAIL|Param Name: myVariable_current, Param Value: ENCODED:{![treatNullAsNull]{!ID:this}}, Evaluated Param Value: {Entity type: Sample_Transaction__c, id: a0i0E0000000YDuQAM}|Param Name: myVariable_old, Param Value: {!old}, Evaluated Param Value: {Entity type: Sample_Transaction__c, id: a0i0E0000000YDuQAM} 12:01:19.64 (64296997)|FLOW_START_INTERVIEWS_BEGIN|1 12:01:19.64 (65090375)|FLOW_START_INTERVIEW_BEGIN|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|Process Submitted Sample Transactions 12:01:19.64 (65117305)|FLOW_VALUE_ASSIGNMENT|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|myVariable_old|moduleapi.interaction.SObjectRowWithSavePoint@561339df 12:01:19.64 (66046237)|FLOW_VALUE_ASSIGNMENT|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|myVariable_current|{Id=a0i0E0000000YDuQAM, OwnerId=00524000001xWetAAE, IsDeleted=false, Name=ST-0041918, RecordTypeId=01224000000kJPQAA2, CreatedDate=2017-06-08 05:32:15, CreatedById=00524000001xWetAAE, LastModifiedDate=2017-06-08 16:01:19, LastModifiedById=00524000001xWetAAE, SystemModstamp=2017-06-08 16:01:19, LastViewedDate=null, LastReferencedDate=null, ConnectionReceivedId=null, ConnectionReceivedDate=null, ConnectionSentId=null, ConnectionSentDate=null, Account_Credentials__c=null, Account_Email__c=null, Account_First_Name__c=null, Account_ID__c=0012400001837s0AAA, Account_Last_Name__c=null, Account_Middle_Name__c=null, Account_NPI__c=null, Account_Phone__c=null, Account_Salutation__c=null, Address_Address_Line_1__c=null, Address_Address_Line_2__c=null, Address_City__c=null, SAsln__c=1234, Address_ID__c=a012400000tS8vZAAS, Address_State__c=null, Call_Date__c=null, Address_ZIP__c=null, CUSTOMER__c=Reckitt, Call_ID__c=null, Call_Submitted_Date__c=null, Comments__c=null, Confirmed_Quantity__c=null, Eloqua_Order__c=false, Person_Account_Credentials__c=MD, Person_Account_First_Name__c=ROMAN, Person_Account_Last_Name__c=TEST, Person_Account_Middle_Name__c=null, Person_Account_NPI__c=null, Person_Account_Phone__c=null, Person_Account_Salutation__c=null, Product_Name__c=null, Product__c=a0e24000007krpgAAA, Quantity__c=7.0, Return_Reason__c=null, Sample_Lot_ID__c=a0h0E0000004ZHFQA2, Status__c=Acknowledged, Tracking_Number__c=null, Transaction_Date__c=null, Transaction_Quantity__c=-7.0, Transfer_Executed__c=false, Transfer_To__c=null, Transferred_From__c=null, Account_SLN__c=null, Sample_Lot_for_Promotional_Product__c=null, Product_Description__c=null, ID_18__c=a0i0E0000000YDuQAM, UPDATE__c=false, Completed_Transaction__c=false, Reckitt_Professional_Website_Order__c=false, AMA__c=null, decile__c=0.0, Parent_id__c=a0h0E0000004ZHFQA2} 12:01:19.64 (66109230)|FLOW_ELEMENT_BEGIN|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|FlowAssignment|myVariable_waitStartTimeAssignment 12:01:19.64 (66163161)|FLOW_ASSIGNMENT_DETAIL|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|myVariable_waitStartTimeVariable|ASSIGN|6/8/2017 12:01 PM 12:01:19.64 (66173207)|FLOW_VALUE_ASSIGNMENT|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|myVariable_waitStartTimeVariable|2017-06-08T16:01:19Z 12:01:19.64 (66180494)|FLOW_ELEMENT_END|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|FlowAssignment|myVariable_waitStartTimeAssignment 12:01:19.64 (66193050)|FLOW_ELEMENT_BEGIN|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|FlowDecision|myDecision 12:01:19.64 (66412086)|FLOW_RULE_DETAIL|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|myRule_1|false 12:01:19.64 (66421571)|FLOW_VALUE_ASSIGNMENT|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|myRule_1|false 12:01:19.64 (66428726)|FLOW_ELEMENT_END|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|FlowDecision|myDecision 12:01:19.64 (66517218)|FLOW_START_INTERVIEW_END|94107b55bff6c64be466b65d59e15c886cf6ab-5d20|Process Submitted Sample Transactions 12:01:19.64 (66527465)|FLOW_START_INTERVIEWS_END|1 12:01:19.53 (67174704)|WF_FLOW_ACTION_END|09L240000000Mti 12:01:19.53 (67186527)|WF_FLOW_ACTION_BEGIN|09L24000000LAZO 12:01:19.53 (67198199)|WF_FLOW_ACTION_DETAIL|09L24000000LAZO|[Sample Transaction: ST-0041918 a0i0E0000000YDu]|Id=09L24000000LAZO|CurrentRule:Process_Sample_Transaction_Reckitt_Transfer30124000000DIGt (Id=01Q24000000LRlR) 12:01:19.67 (67227591)|FLOW_CREATE_INTERVIEW_BEGIN|00D0E0000000PY9|30024000000PRiw|30124000000DIGt 12:01:19.67 (68393264)|FLOW_CREATE_INTERVIEW_END|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|Process Sample Transaction: Reckitt Transfer 12:01:19.53 (68541500)|WF_FLOW_ACTION_DETAIL|Param Name: myVariable_current, Param Value: ENCODED:{![treatNullAsNull]{!ID:this}}, Evaluated Param Value: {Entity type: Sample_Transaction__c, id: a0i0E0000000YDuQAM}|Param Name: RecursiveCountVariable, Param Value: {!triggerRecurseCount}, Evaluated Param Value: 0|Param Name: myVariable_old, Param Value: {!old}, Evaluated Param Value: {Entity type: Sample_Transaction__c, id: a0i0E0000000YDuQAM} 12:01:19.68 (68579575)|FLOW_START_INTERVIEWS_BEGIN|1 12:01:19.68 (69193856)|FLOW_START_INTERVIEW_BEGIN|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|Process Sample Transaction: Reckitt Transfer 12:01:19.68 (69218650)|FLOW_VALUE_ASSIGNMENT|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|myVariable_old|moduleapi.interaction.SObjectRowWithSavePoint@6748044e 12:01:19.68 (70035371)|FLOW_VALUE_ASSIGNMENT|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|myVariable_current|{Id=a0i0E0000000YDuQAM, OwnerId=00524000001xWetAAE, IsDeleted=false, Name=ST-0041918, RecordTypeId=01224000000kJPQAA2, CreatedDate=2017-06-08 05:32:15, CreatedById=00524000001xWetAAE, LastModifiedDate=2017-06-08 16:01:19, LastModifiedById=00524000001xWetAAE, SystemModstamp=2017-06-08 16:01:19, LastViewedDate=null, LastReferencedDate=null, ConnectionReceivedId=null, ConnectionReceivedDate=null, ConnectionSentId=null, ConnectionSentDate=null, Account_Credentials__c=null, Account_Email__c=null, Account_First_Name__c=null, Account_ID__c=0012400001837s0AAA, Account_Last_Name__c=null, Account_Middle_Name__c=null, Account_NPI__c=null, Account_Phone__c=null, Account_Salutation__c=null, Address_Address_Line_1__c=null, Address_Address_Line_2__c=null, Address_City__c=null, SAsln__c=1234, Address_ID__c=a012400000tS8vZAAS, Address_State__c=null, Call_Date__c=null, Address_ZIP__c=null, CUSTOMER__c=Reckitt, Call_ID__c=null, Call_Submitted_Date__c=null, Comments__c=null, Confirmed_Quantity__c=null, Eloqua_Order__c=false, Person_Account_Credentials__c=MD, Person_Account_First_Name__c=ROMAN, Person_Account_Last_Name__c=TEST, Person_Account_Middle_Name__c=null, Person_Account_NPI__c=null, Person_Account_Phone__c=null, Person_Account_Salutation__c=null, Product_Name__c=null, Product__c=a0e24000007krpgAAA, Quantity__c=7.0, Return_Reason__c=null, Sample_Lot_ID__c=a0h0E0000004ZHFQA2, Status__c=Acknowledged, Tracking_Number__c=null, Transaction_Date__c=null, Transaction_Quantity__c=-7.0, Transfer_Executed__c=false, Transfer_To__c=null, Transferred_From__c=null, Account_SLN__c=null, Sample_Lot_for_Promotional_Product__c=null, Product_Description__c=null, ID_18__c=a0i0E0000000YDuQAM, UPDATE__c=false, Completed_Transaction__c=false, Reckitt_Professional_Website_Order__c=false, AMA__c=null, decile__c=0.0, Parent_id__c=a0h0E0000004ZHFQA2} 12:01:19.68 (70046220)|FLOW_VALUE_ASSIGNMENT|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|RecursiveCountVariable|0 12:01:19.68 (70081805)|FLOW_ELEMENT_BEGIN|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|FlowAssignment|myVariable_waitStartTimeAssignment 12:01:19.68 (70100208)|FLOW_ASSIGNMENT_DETAIL|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|myVariable_waitStartTimeVariable|ASSIGN|6/8/2017 12:01 PM 12:01:19.68 (70107239)|FLOW_VALUE_ASSIGNMENT|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|myVariable_waitStartTimeVariable|2017-06-08T16:01:19Z 12:01:19.68 (70111293)|FLOW_ELEMENT_END|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|FlowAssignment|myVariable_waitStartTimeAssignment 12:01:19.68 (70116544)|FLOW_ELEMENT_BEGIN|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|FlowDecision|myDecision 12:01:19.68 (82128969)|FLOW_RULE_DETAIL|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|myRule_1|false 12:01:19.68 (82137015)|FLOW_VALUE_ASSIGNMENT|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|myRule_1|false 12:01:19.68 (82143529)|FLOW_ELEMENT_END|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|FlowDecision|myDecision 12:01:19.68 (82205880)|FLOW_START_INTERVIEW_END|94207b55bff6c64be466b65d59e15c886cf6ab-5d1f|Process Sample Transaction: Reckitt Transfer 12:01:19.68 (82216146)|FLOW_START_INTERVIEWS_END|1 12:01:19.53 (82691566)|WF_FLOW_ACTION_END|09L24000000LAZO 12:01:19.53 (82707201)|WF_FLOW_ACTION_BEGIN|09L240000000NnY 12:01:19.53 (82723049)|WF_FLOW_ACTION_DETAIL|09L240000000NnY|[Sample Transaction: ST-0041918 a0i0E0000000YDu]|Id=09L240000000NnY|CurrentRule:Process_Sample_Transaction_Reckitt_Transfer30124000000DIGt (Id=01Q24000000LRlR) 12:01:19.82 (82754512)|FLOW_CREATE_INTERVIEW_BEGIN|00D0E0000000PY9|30024000000PRiv|30124000000QWgL 12:01:19.82 (84677324)|FLOW_CREATE_INTERVIEW_END|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|Process Sample Transaction: Reckitt Orders 12:01:19.53 (84945981)|WF_FLOW_ACTION_DETAIL|Param Name: myVariable_current, Param Value: ENCODED:{![treatNullAsNull]{!ID:this}}, Evaluated Param Value: {Entity type: Sample_Transaction__c, id: a0i0E0000000YDuQAM}|Param Name: myVariable_old, Param Value: {!old}, Evaluated Param Value: {Entity type: Sample_Transaction__c, id: a0i0E0000000YDuQAM} 12:01:19.85 (85003610)|FLOW_START_INTERVIEWS_BEGIN|1 12:01:19.85 (85935992)|FLOW_START_INTERVIEW_BEGIN|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|Process Sample Transaction: Reckitt Orders 12:01:19.85 (85956174)|FLOW_VALUE_ASSIGNMENT|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|myVariable_old|moduleapi.interaction.SObjectRowWithSavePoint@7d6cd02c 12:01:19.85 (87530116)|FLOW_VALUE_ASSIGNMENT|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|myVariable_current|{Id=a0i0E0000000YDuQAM, OwnerId=00524000001xWetAAE, IsDeleted=false, Name=ST-0041918, RecordTypeId=01224000000kJPQAA2, CreatedDate=2017-06-08 05:32:15, CreatedById=00524000001xWetAAE, LastModifiedDate=2017-06-08 16:01:19, LastModifiedById=00524000001xWetAAE, SystemModstamp=2017-06-08 16:01:19, LastViewedDate=null, LastReferencedDate=null, ConnectionReceivedId=null, ConnectionReceivedDate=null, ConnectionSentId=null, ConnectionSentDate=null, Account_Credentials__c=null, Account_Email__c=null, Account_First_Name__c=null, Account_ID__c=0012400001837s0AAA, Account_Last_Name__c=null, Account_Middle_Name__c=null, Account_NPI__c=null, Account_Phone__c=null, Account_Salutation__c=null, Address_Address_Line_1__c=null, Address_Address_Line_2__c=null, Address_City__c=null, SAsln__c=1234, Address_ID__c=a012400000tS8vZAAS, Address_State__c=null, Call_Date__c=null, Address_ZIP__c=null, CUSTOMER__c=Reckitt, Call_ID__c=null, Call_Submitted_Date__c=null, Comments__c=null, Confirmed_Quantity__c=null, Eloqua_Order__c=false, Person_Account_Credentials__c=MD, Person_Account_First_Name__c=ROMAN, Person_Account_Last_Name__c=TEST, Person_Account_Middle_Name__c=null, Person_Account_NPI__c=null, Person_Account_Phone__c=null, Person_Account_Salutation__c=null, Product_Name__c=null, Product__c=a0e24000007krpgAAA, Quantity__c=7.0, Return_Reason__c=null, Sample_Lot_ID__c=a0h0E0000004ZHFQA2, Status__c=Acknowledged, Tracking_Number__c=null, Transaction_Date__c=null, Transaction_Quantity__c=-7.0, Transfer_Executed__c=false, Transfer_To__c=null, Transferred_From__c=null, Account_SLN__c=null, Sample_Lot_for_Promotional_Product__c=null, Product_Description__c=null, ID_18__c=a0i0E0000000YDuQAM, UPDATE__c=false, Completed_Transaction__c=false, Reckitt_Professional_Website_Order__c=false, AMA__c=null, decile__c=0.0, Parent_id__c=a0h0E0000004ZHFQA2} 12:01:19.85 (87598837)|FLOW_ELEMENT_BEGIN|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|FlowAssignment|myVariable_waitStartTimeAssignment 12:01:19.85 (87629000)|FLOW_ASSIGNMENT_DETAIL|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|myVariable_waitStartTimeVariable|ASSIGN|6/8/2017 12:01 PM 12:01:19.85 (87641764)|FLOW_VALUE_ASSIGNMENT|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|myVariable_waitStartTimeVariable|2017-06-08T16:01:19Z 12:01:19.85 (87649752)|FLOW_ELEMENT_END|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|FlowAssignment|myVariable_waitStartTimeAssignment 12:01:19.85 (87659277)|FLOW_ELEMENT_BEGIN|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|FlowDecision|myDecision 12:01:19.85 (88096939)|FLOW_RULE_DETAIL|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|myRule_1|false 12:01:19.85 (88106310)|FLOW_VALUE_ASSIGNMENT|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|myRule_1|false 12:01:19.85 (88114079)|FLOW_ELEMENT_END|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|FlowDecision|myDecision 12:01:19.85 (88195998)|FLOW_START_INTERVIEW_END|94307b55bff6c64be466b65d59e15c886cf6ab-5d1e|Process Sample Transaction: Reckitt Orders 12:01:19.85 (88210934)|FLOW_START_INTERVIEWS_END|1 12:01:19.53 (88699788)|WF_FLOW_ACTION_END|09L240000000NnY 12:01:19.53 (88771927)|WF_ACTIONS_END| Flow Trigger: 3; 12:01:19.53 (88777123)|CODE_UNIT_FINISHED|Workflow:01I24000001drLB 12:01:19.53 (89620399)|EXECUTION_FINISHED
Apex trigger quantityleft caused an unexpected exception, contact your administrator: quantityleft: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.quantityleft: line 17, column 1
probally the field "Transaction_Quantity__c" is empty. put some value in this field like "0".
For example:
System.debug('Trasaction value: ' + sample_transaction.Transaction_Quantity__c);
So that you will see what is going on and what is missing.
but when the line start line no 16 its not executing after that it goes last line i mena what ever i mentioned system debug its not printing
for(Sample_Transaction__c sample_transaction : [SELECT Id,Sample_Lot_ID__c,
for(Sample_Transaction__c sample_transaction : [SELECT Id,Sample_Lot_ID__c, Confirmed_Quantity__c FROM Sample_Transaction__c WHERE Id = : set_Opportunity]){
if yes, try print the value of "set_Opportunity", before getting in this for.
I think this for is not executed because in the query don't found any register.
i think we limit to 1
for(Sample_Transaction__c sample_transaction : [SELECT Id,Sample_Lot_ID__c, Transaction_Quantity__c FROM Sample_Transaction__c WHERE Id = : Trigger.newMap.keyset() limit 1 if i replace it with set_oppurtunity no result is coming
You have to get another brothers of this register.
So you have a "for" tha get the current child data, and a second for that is getting the data of the parent of this register.
You can create now another "for" inside of the parent "for" to read all the child register.
Doing that you use the SUM in the last "for" to store the values of all child register, and after that you can update the parent field with the total SUM of these registers.
now i will write test case , so i need all the record to create sample and sample lot, if sample is refered account in lookup i have to create account am i right
It's a pleasure to help.
I don't understand well what you mean about create account.
If your Sample and Sample lot are child of account, depending what you want do, you don't need use account. But if you have to bring a list of account, so you will need make a call from object Account too.
The limit depends of what you want.
For example:
You need especify the record Id in the SELECT on "for". So will return a list of records that you want.
If for example, you have a record of Sample Lot with Id "ABC123", and this record have many other records making realationship with him, so will bring all records. You can filter more if you pull a condition in the query.
About the update, I think you can do as many as you can, but you need implement a validation to not getting a loop pn your updates.
Create another class e call this method to update only one time each record.
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if(run){
run=false;
return true;
}
else{
return run;
}
}
}
now my question is this code has after insert , update,delete, undelte i have given my test code too , i just inserted the required record in test code and it shows 82% code coverage. My test code ddint check anything ,if i move this code in production will it work
and also advise me how to cover after insert,update,delete undelte in my test code
test code
To check what the test code is checking, go to Developer Console, click on the test button in your Test Class. After doing that, in the bottom you will see some tabs, search for a tab called Tests, and you will see in the bottom on the right side a list of classes, find your Class you want to Test in this list and make a double click in this class.
Now you can see your class with a clolor in RED. This color will show to you the code that don't was tested.
You must cover all the code to be 100%.
But I see in your code that you make a UPDATE and DELETE trigger too, so you must create a TEST that make an UPDATE and DELETE record too.
I advise you that you try cover the maximum of your code.
For example, I created I code and a Test class that cover 98% of my code, but in the production are occured an error in another classes that I not covered 100% before.
So, if you not fix this now, maybe you must fix your code later.
But if you feelling safe to publish, go on.