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
Leo CarcamoLeo Carcamo 

Custom Object field change to update standard object field

Hi - I have a custom object and I want an update of 75 (score) or higher to Score__c (field in custom object) to update the Lead status on the corresponding lead to "Marketing Qualified Lead". I can only do this via an apex trigger and was hoping that someone here had some sample code for me to be able to make this happen in my instance of SFDC.

Custome Object Name: Infer Entity Score
Custom field name: Infer Score
Standard Object Name: Lead
Standard Field name: Lead Status

Syntax should be something like this:
When custom object infer score is 75 or greater then update lead status to Marketing qualified lead.

Thanks!
Chris ShadeChris Shade
Hey Leo,

Is the Score field a formula field?  If not could you just use a workflow?


Leo CarcamoLeo Carcamo
Hi Chris,

I need to use a trigger because I can't create a relationship between the standard object and the custom object. the Score field is just a number field. I've tried the workflow rules and both support and the company that provides the service has pointed me in the direction of a trigger =(.
rohitsfdcrohitsfdc
Hello Leo,
As you mentioned that there is no relationship between lead and the custom object. How do we get to know that which lead's status will get updated with the score?


Leo CarcamoLeo Carcamo
Hi Chris,

There is an entity ID which contains the ID of the lead that the custom object is linked to. Here's the sample code that was provided to me when I asked for help with my trigger.

trigger updateLead on Infer_Entity_Score__c (after update) {
    List<String> leadIds = new List<String>();
    for (Infer_Entity_Score__c score : trigger.new) {
        if (score.Entity_Type__c == 'lead') {
            leadIds.add(score.Entity_ID__c);

         }

    }
  
    if (leadIds.size() == 0) {
        return;
    }
  
    Lead[] leads = [
        SELECT Id, Owner FROM Lead WHERE Id in :leadIds
    ];
  
    for (Lead lead : leads) {
  // update lead owner

This trigger is for updating the lead owner and I'm trying to update the lead status whenever the Infer Score is >= 75.

Thanks!
Surgaya KhundrakpamSurgaya Khundrakpam
Can we update Custom object's field whenever a standard object field is updated ?
As I went through this document https://help.salesforce.com/articleView?id=workflow_cross_object_field_updates.htm&language=en_US&type=0
It allows only 3 types:
Custom Object to Custom Object
Custom Object to Standard Object
Standard Object to Standard Object (** only these standard-to-standard relationships are supported.)

What about Standard Objet to Custom Objects ??

Could we have this feature in salesforce