You need to sign in to do that
Don't have an account?
vish h
How to update lookup field in the parent object.
Hi ,
I'm attempting to update the lookup field in the object and unable to do so.. Please anyone guide me the correct way of updating the field in apex.
PO_requisition__c poreq = new PO_requisition__c();
poreq = [select SecondApprover__r.FirstName from PO_requisition__c where ID ='a0J9000000tinJl'];
poreq.SecondApprover__r.Id = UserInfo.getUserId();
update poreq;
System.debug('----------------------This is approved now-----'+poreq.SecondApprover__r.Id);
getting below error..
System.NullPointerException: Attempt to de-reference a null object
Thanks
VIshwa
I'm attempting to update the lookup field in the object and unable to do so.. Please anyone guide me the correct way of updating the field in apex.
PO_requisition__c poreq = new PO_requisition__c();
poreq = [select SecondApprover__r.FirstName from PO_requisition__c where ID ='a0J9000000tinJl'];
poreq.SecondApprover__r.Id = UserInfo.getUserId();
update poreq;
System.debug('----------------------This is approved now-----'+poreq.SecondApprover__r.Id);
getting below error..
System.NullPointerException: Attempt to de-reference a null object
Thanks
VIshwa
Please give a try with below code :
PO_requisition__c poreq = new PO_requisition__c();
poreq = [select SecondApprover__r.FirstName from PO_requisition__c where ID ='a0J9000000tinJl'];
poreq.SecondApprover__c = UserInfo.getUserId();
update poreq;
System.debug('----------------------This is approved now-----'+poreq.SecondApprover__c);
Thanks,
Vishal
All Answers
Please give a try with below code :
PO_requisition__c poreq = new PO_requisition__c();
poreq = [select SecondApprover__r.FirstName from PO_requisition__c where ID ='a0J9000000tinJl'];
poreq.SecondApprover__c = UserInfo.getUserId();
update poreq;
System.debug('----------------------This is approved now-----'+poreq.SecondApprover__c);
Thanks,
Vishal