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

Simple Trigger Help Needed

Needing help with a simple trigger. I have a value in a custom field on a Custom Object. I want to query Accounts to find the AccountId where the custom field value on my Custom Object = the value of a custom field value on Account. I then want to insert the AccountId into a lookup field on the Custom Object. Help is much appreciated. 

trigger recordUpdate on Custom_Object__c (after insert, after update)
    String a = // need to create a variable for the value of a custom_field__c (text) on Custom_Object__c

    List<Id> accountId= [SELECT Id FROM Account WHERE account_custom_field__c = :a];

    insert // not sure how to then insert the value of accountId to a different custom field on Custom_Object__c
Pramodh KumarPramodh Kumar
Hey Justin,

What exactly you wants to do with this trigger.
what is a in the trigger and what you are trying to insert.

Trying to find the accountId where the value from custom_object__c matches a value on the Account. Then I want to insert accountId onto a different field on the same record of the custom object (custom_object__c)
To add to the above, "a" just represents the value that I want to match from the custom object to the Account
Pramodh KumarPramodh Kumar
does your account have the exact value of Custom_Object__c.field

what is  String a = in your trigger. does this matches to your account.

after querying this List<Id> accountId= [SELECT Id FROM Account WHERE account_custom_field__c = :a];.
if you get more than one value which value you wanna insert to that record.

If you dont know much about trigger please go through the documentation or try to understand what exactly the triggers in Salesforce.