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
Ralf WittenbergerRalf Wittenberger 

Trigger to autofill a lookup field on account with Grouping ID

Hi,
I need to have a lookup field on Account to be filled with Grouping ID upon creating or converting a Account.
Unfortunately, it is not possible to do this with a workflow, so i guess, writing a Trigger oder Code would be the easiest way here, right?
There is another condition for a specific field, if this is filled with specific content.
So, formular, I would have written like:
If(And(isnew(),ispickval(country_responsible_for_account__c,"Germany")),a0fD00...,null)

Is there anyone out here, that can help me with that? 

Thanks a lot in advance for your help

PS: is there anything, you can recommend to learn how to write trigger etc?
Best Answer chosen by Ralf Wittenberger
Ralf WittenbergerRalf Wittenberger
Thanks for this, i found a shorter version, working fine for me

trigger SetCustomerGrouping on Account ( before insert) {
for (Account a: Trigger.new)
{
    if(a.country_responsible_for_account__c == 'BCA Germany'&& a.Top100__C ==null){
        a.Top100__c ='a0fD0000008iqQZ' ;        
    }}}

All Answers

NagaNaga (Salesforce Developers) 
Hi Ralf,

Please check the below code where the lookup field is autofilled.
Its quite similar to your requirement.

User-added imageplease follow the below link for more information on this code

http://salesforce.stackexchange.com/questions/35254/autopopulate-lookup-field-with-account-id-using-an-apex-trigger

Best Regards
Naga Kiran
Ralf WittenbergerRalf Wittenberger
Thanks for this, i found a shorter version, working fine for me

trigger SetCustomerGrouping on Account ( before insert) {
for (Account a: Trigger.new)
{
    if(a.country_responsible_for_account__c == 'BCA Germany'&& a.Top100__C ==null){
        a.Top100__c ='a0fD0000008iqQZ' ;        
    }}}
This was selected as the best answer