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
Vanitha ManiVanitha Mani 

Trigger question..its urgent please anyone help

Hi,

I have a case trigger.when creating a case based on the value given in these fields I need to autopopulate two other fields.

Account--user entered
Product--user entered
system-user entered
Environment --user entered

We need to autopopulate 
ticket.productbuild =
Ticket.system version=

These values comes from account.
svc-product-build is another object with lookup account .

Need to fetch values of product build and system version from svc product build object with account as a lookup.

It's very challenging. Can anyone help with this autopopulation of fields
AbhishekAbhishek (Salesforce Developers) 
/* Note that this is just a working code. However, you might need to modify this code in order to make it appropriate for your use or make it bulkified so that it can handle multiple records */
trigger copyAccountMemberinContact1 on Case(before insert, before update) {

    List < Id > newOrUpdatedCases = new List < Id > ();
    List < account > acclist = new List < account > ();
    list <case> casesToBeUpdated = new List <case>();

    for (case c: trigger.new) {
         newOrUpdatedCases.add(c.AccountId);
        casesToBeUpdated.add(c);
    }

    acclist = [Select AccountMember__c from Account where Id in : newOrUpdatedCases];

    System.Debug('newOrUpdatedCases' + newOrUpdatedCases);  
    System.debug('acclist ' + acclist);

    for (integer i = 0; i < casesToBeUpdated.size(); i++) {
        casesToBeUpdated[i].Contact1__c = acclist[i].AccountMember__c;
    }
}


Try the code snippet for your requirement.


For further reference check this,

https://salesforce.stackexchange.com/questions/40188/autopopulate-case-field-with-related-account-field-value


If it helps you and close your query by marking it as solved so that it can help others in the future

Thanks.
Vanitha ManiVanitha Mani
Hi.

I need to populate the values based on the values given in product and environment field ..it should match here User-added image
this is the account where installed product name value should diplay in product build and installed system should get display in system version ..
where this table comes from svc product build object with account as a lookup.
Vanitha ManiVanitha Mani
for example if environment given as production in case and product as ABS in case it should lookup this table for tat account entered while creating a case..it should match and autopopulate value in those fields