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
selva kumar 14selva kumar 14 

Trigger for copy Lead text field values into same lead lookup field

Hi Everyone,

I don't have much knowledge about coding. I have tried few triggers using some developers sample available in discussion board. But i can't able to acheive my goal. My requirement is given below.

There are a few fields that cannot be updated through the standard SalesForce interface, and can only be updated via Apex code.  We need to duplicate some information from a text field on the Lead and Opportunity screens, and populate it into a lookup field.  Please see the details below:

Object - Lead
Originating field (from) - Referral Text (text)
Destination field (to)  - Referral Partner (lookup)
When to trigger - Upon update/Insert of Referral Text value


Can anyone please help on this.

Thanks in advance.

My trigger which i have created is given below. But it doesn't work.

       trigger Referral_Lead on Lead(After insert || After Update) { {
        for(Lead newLead:Trigger.new){       
            if (newLead.Referral_Text__c!=null) {            
                String refString = newLead.Referral_Text__c;           
                Id referralID = refString;           
                newLead.Referral_Partner__c = referralID;      
            }     
        }   
    }
    }


 
Nishant SharmaNishant Sharma
1. Lookup field is refrence field and cannot hold arbitory text. It has to Id.
2. While assigning String to Id, you have to type cast it. If String is a valid id, it will typecast properly, else will throw error. and you have to handle execption accordingly.