+ Start a Discussion
pbondpbond 

I need to update the lookup field

I have Look up field in Account - Sales_orgnizaion__c

i need a lookup field in opportunity - Sales_Organization__c

i need to auto populate the opportunity field and editable .

I think we need to use updating the filed update , Can any one please give ,what is the procedure and code  

NikhilNikhil

First of all create a field on opportunity as Sales_orgnizaion__c

 

Then if you want to populate this field value from Account. then fetch that field value first.

Id AccountId = 'some accountid';

Id opportunityId = 'some opp id';

 

Account a = [Select Id,Sales_orgnizaion__c from Account where id=: AccountId ];

 

if (a != null)

{

Opportunity o = new Oppirtunity(id=opportunityId,Sales_orgnizaion__c = a.Sales_orgnizaion__c);

update o;

}