function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sourav PSourav P 

Autopopulate teh fields based on a look field value from a different object

Hi, Can anyone help me out with thiis,
User-added image
This is from a custom object " Quotation", The look up field " Main Driver" is a look up to Personal account object. The below fields are as well exists in the personal account. I need whatever value would be choosen in the main driver, automatically the below values will get pop up.

I amm trying to write a trigger for this, but just got stuck,
Error showing as, Error: Compile Error: Variable does not exist: Account.Age__c at line 7 column 17
How can i define the Account variable in the Quotation object trigger ?


trigger MainDriverRelatedFields on Quotation__c (before insert,before update) {

for(Quotation__c obj : Trigger.new){

if(obj.Main_Driver__c!=null) {

obj.AgeMainD__c=Account.Age__c;
obj.GenderMainD__c=Account.Contact_Individual_Gender__c;

}
}
}

 
Vyankatesh Choulwar 15Vyankatesh Choulwar 15
Where you are getting Account from in this code?
Sourav PSourav P
Hi vyankatesh

Ya, i am missing that. i dont know where to call the Account variable. Without calling the Account varibale it doesnt work. plz suggest
Is it somthing i need to put, Is that will work ? I tried that but it was not. If yes, where to place that in teh code ? Thanks
Account Acc=New Account
Acc.Age__c
Vyankatesh Choulwar 15Vyankatesh Choulwar 15
Let me know the relationship between Quotation and Account Object
Sourav PSourav P
Quotation and Account objects are linked through a many to many relationship ( by a junction object)
The "Main driver" field above in the screenshot is actually a look up to the account field . Thnx
Vyankatesh Choulwar 15Vyankatesh Choulwar 15
If they are linked via Junction Object then why there is direct lookup to Account via Main Driver field? I am not getting this. (by lookup it will be one to many relationship)

Considering this case,
You will have to create VF Page for this part. Then on select of Account on lookup field, you will have to rerender the other fields to fetch the values from Account selected.
 
Sourav PSourav P
I created many to many as there is another need of this. But Here, actually the " Maain Driver" field is getting autopopulated from another account look up field selected as per below ( for which i wrote a trigger). Its a standard page, If i write a VF page, I think i need to create a VF page section, But as per need the fields should visible on Edit mode, VF section will not visible in teh edit mode, also this autopopulation will not work. plz suggest. thanks. Isnt it trigger works in this case ?

User-added image
Nithya S 1Nithya S 1
Would you want them to be displayed in the Edit mode as well? You could have just the lookup and upon save populate the corresponding fields on the layout. Would that work?
Sourav PSourav P
Hi Nithya,
yes that would work, But say, if we dont have the " Main Driver" look up field been filled. ( Its replicating from the account name field above, only if the field " Are you driving" field is "YES", if its "NO", then the user have to search in the " Main driver" look up. If not found any suitable value, user just need to fill the below fields, leaving the Main Driver field blank. So, if those are not visible in the edit mode, they cant fill that. So, basically if the Main Driver is filled, its ok, those will not visible in the edit mode, but if its not filled, those need to be to manually filled ( Actually , thats a Driver name, and we need to calculate premium, as per the below field, so even if no name, thats OK, but if the driver name is already there in the system, then the users have the flexibility of not to fill the below fields and those will be populated). Thanks. Can you plz suggest a way