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
raseshtcsraseshtcs 

Opportunity name Automantion

Hi All,

My requirement is to automate the name of the opportunity in the following format Account Name-"{Custom Field}". If multiple Opportunities exist for the same Account and the custom field value, the Opportunity Name should reflect that iteration (e.g. "Account1 - xyz", "Account1 - xyz(2)", "Account1 - xyz(3)", etc).

I have written a trigger which populates the name properly but I am struggling with the Iteration number which I need to have. Please suggest.

 

Thanks in Advance

Rasesh

dotnet developedotnet develope

Hi,

 

To achieve your requirement, you need to do two things,

 

1) Define a custom setting value

2) Define a trigger on Opportunity and get the value from custom setting and update according to it.

 

 

 

kiranmutturukiranmutturu

This will work for you.. i dont enough time to spend on this...check it out 

 

trigger automate on Opportunity (before insert) {
    
    set<id> sids = new set<id>();
    for(Opportunity obj : trigger.new){
        sids.add(obj.accountid);
    }
    
    list<Opportunity> lst = [select id,account.name from Opportunity where accountid in :sids]; 
    
    integer i = lst.size();
    
    
    for(integer ival = 0; ival <= i; ival++){
    
        if(ival > 0){
            for(Opportunity obj : trigger.new){
                system.debug('*******'+obj.account.name);
                obj.name = lst[0].account.name+'-'+obj.StageName+'('+ival+')';
            }
        }
    
    }
}

 

I checked in DE its worked out fine for  me..

 

 

Regards,.

 

Kiran

raseshtcsraseshtcs
Hi Kiran
raseshtcsraseshtcs

Hi Kiran,

 

My requirement is to add the count to the oppty name only when there is a similar opportunity with the similar product value on the same account. And increment the count as and when there is a new opportunity created on the same account with the same custom field value.

 

Please let me know in case i am not making myself clear.

 

Regards

Rasesh