+ Start a Discussion
sujatha dhanekulasujatha dhanekula 

Hi, I am not a developer. I need to write trigger on opportunity object, opp name should be auto populate accountname:oppname entered by user

Hi, I am not a developer. I need to write trigger on opportunity object,  opp name should be auto populate accountname:oppname entered by user.
requirement is
company has decided to have the Opportunity naming convention as “<Account Name>: <Opportunity Name>”. For example, if the opportunity is pertaining to 200 laptops, from Account ABC, the Opportunity naming convention should be “ABC: 200 laptops”. However, do not mandate this to be filled in as such by users. Instead, automatically update the Opportunity name as <Account Name>: <Opportunity Name> if someone creates the Opportunity without Account Name already in it.
sowmya Inturi 9sowmya Inturi 9
Hi Sujatha,

I don't think you need a trigger for that. You can do it with worflow itself.

Workflow Rule:
User-added image

Workflow Field Update:
User-added image

Thanks,
Sowmya.
sujatha dhanekulasujatha dhanekula
Tried with work flow didn't work. Does it need time based trigger. Can you please inform how to create work flow for this. I created when on opportunity account name is null and opportunity name is not null then update opportunity name field only on create, but didn't update when I created new opportunity
sowmya Inturi 9sowmya Inturi 9
Hi Sujatha,
1. Opportunity Account Name Should not be null (Should take Account Name NOT null).
2. No need of taking Opportunity Name condition as it is a mandatory field.
3. Make sure that you activated your workflow rule.



Thanks,
Sowmya.
sujatha dhanekulasujatha dhanekula
Hi Sowmya, Thank you. I activated workflow rule. However, account name is too long how to trim it before update opp name field with accountname.oppname and only one workflow rule to be active is this per object? Thank you SUjatha
sowmya Inturi 9sowmya Inturi 9
Hi Sujatha,
You want to shorten the Account Name?
If it is your requirement, How much exactly you need your Account Name length should be? 


Thanks,
Sowmya.
sujatha dhanekulasujatha dhanekula
Should be the first word in account name up to 10 char
SFDC Beginner745SFDC Beginner745
Hi Sujatha,

Please find the below code as per your requirement :

trigger OppNameTrigger on Opportunity (before insert) {
    
    List<Account> acList =[select id,name from Account];
    for(Opportunity op: Trigger.new){
        for(Account acc:acList){
            if(acc.id==op.Accountid){
                
                op.name=acc.name+' '+op.name;
                
            }
        }
    }
    
}

Thanks
Salesforce Developer Group
Abdulla d 5Abdulla d 5
HI,
trigger OpNameApend on Opportunity (before insert) {    
    List<Account> acc =[select id,name from Account];
    string name;
    for(Opportunity op: Trigger.new){
        for(Account a:acList){
            if(a.id==op.Accountid){
        if(acc.name.size()<=10){
        name=a.Name;
        }
                else{
        name=a.name.substring(0,10);
        }
                op.name=name+' '+op.name;                
            }
        }
    }
    
}
sowmya Inturi 9sowmya Inturi 9
Hi Sujatha,
Replace your formula in Workflow FieldUpdate with the below formula,

LEFT(Account.Name, 10)  +' : '+  Name
sujatha dhanekulasujatha dhanekula
Hi Ankit, Thank you for the code. However, When I converted lead then opportunity name is as below [cid:311f9979-c46f-46e1-8e57-048f92ba68b0] But when I create an opportunity manually without selecting account name in it and enter opp name = xyz then opp name is not updated with accountname:xyz I am not sure how to interpret the requirement in the first place. it says if opportunity is pertaining to 200 laptops then abc:200 laptops will be opp name. is this mean i have to have a custom field to have number of products and then accountname:number of products will be opp name from web to lead and convert lead process. How about manual opportunity creation when I don't enter account name how will this know that this opportunity for for what account? Thank you Sujatha
sujatha dhanekulasujatha dhanekula
Hi Sowmya, Thank you for your replies. However, did I interpret the requirement corectly. please read it and if you understand more can you please explain to me. Thanks for your help Sujatha
SFDC Beginner745SFDC Beginner745
Hi Sujatha,

You have mentioned only one scenario before, let me know the requirement in details.

Thanks
Salesforce Developer Group
sujatha dhanekulasujatha dhanekula
Hi Ankit, requirement is company has decided to have the Opportunity naming convention as “: ”. For example, if the opportunity is pertaining to 200 laptops, from Account ABC, the Opportunity naming convention should be “ABC: 200 laptops”. However, do not mandate this to be filled in as such by users. Instead, automatically update the Opportunity name as : if someone creates the Opportunity without Account Name already in it. my concern is when there is no account name entered how does the update knows which account name it should link to opportunity? Thank you
sowmya Inturi 9sowmya Inturi 9
Hi Sujatha,
What if there are multiple products (ex: Mobiles & Laptops) for an opportunity? Should it be 200 Laptops 100 Mobiles Account Name?


Thanks,
Sowmya
sujatha dhanekulasujatha dhanekula
This is what i did not really understand I think this feature is available in lightening. Need more clarification on this one.
sujatha dhanekulasujatha dhanekula
Hi Sowmya, in lightening I found when I convert lead opportunity name is auto populating to companyname company name - and we need to enter after - whatever we want to but the requirement this should auto populate. do you have any idea?
sowmya Inturi 9sowmya Inturi 9
Hi Sujatha,
That feature is there in Classic also. If you convert any lead a new opportunity is created with the Account Name. 
But What exactly you need? You want to auto populate your Opportunity Name with  Account Name + Opportunity Name or you want something else to be populated there?


Thanks,
Sowmya
sujatha dhanekulasujatha dhanekula
Hi Sowmya, If you refer https://resources.docs.salesforce.com/198/latest/en-us/sfdc/pdf/salesforce_useful_workflow_rules.pdf on page 5 auto populate opportunity is there as workflow rule But how many workflow rules can be active at any time cause i have to create another work flow rule for Report Lost Opportunities on page 8 by the way in both work flow rules criteria met followed by fields i need to select so I am not sure where to place rule criteria filter code they mentioned in this document. can you please help. Thanks sujatha
sowmya Inturi 9sowmya Inturi 9
Hi,
For Single Workflow rule you can create multiple workflow Actions.

Thanks,
Sowmya 
sujatha dhanekulasujatha dhanekula
Yes Sowmya, I have the below workflow rule, which create a task and send email when opportunity is closed lost now how can i add field update when opportunity name does not have accouname: opportunity name it seems the requirement is misunderstood by me . when user enter opportunity name as Sujatha then it should be auto populated on save or submit to Account name: opportuntiy name Can you please help. how to add this action in the below workflow rule? please refer page 5 from the link i sent you earlier. [cid:38ade955-e3eb-4491-ac84-33cdfb3e5b13]
sujatha dhanekulasujatha dhanekula
Also I have to sent email to ceo when lead rating becomes HOT is this another workflow rule but since this is on lead can I create a new active workflow rule?
sowmya Inturi 9sowmya Inturi 9
Hi,
The answer was given in my first reply itself. Please refer.
You can create a new workflow for lead.
sujatha dhanekulasujatha dhanekula
Is this mean one active workflow per object? correct? how to do auto update for opportunity name then I am trying to add it as field update on opportunity rule but all 3 are trigerred. I only want this one to happen or the other two when opportunity is lost please advise
sujatha dhanekulasujatha dhanekula
Hi Somya, I cannot find Assign using assignment rule check box on lead in lightening. It was there is classic and working fine. I cannot also see edit button on lightening on lead details. I can click on any field edit pencil icon and update all and save. I have checked page layout in lightening and this check box is not there to bring on to page layout. Is this bug? also when i try to map lead custom fields to opportunity some fiedls are not displayed. for example i have created product category and selected products pick lists on lead and try to map these values to opportunity same fields but i can map product category but nothing shown in opportunity for selected products on opportuntiy drop down to map. can you please clarify. Thank you Sujatha
sujatha dhanekulasujatha dhanekula
Sowmya, thank you for your help. Requirement is when opportunity name is not in required format whet entered or edited it should update to required format. Is this work flow or can I combine this with opportunity related requirements and make a process builder? Or can this be formula which I doubt
sowmya Inturi 9sowmya Inturi 9
Hi,
If your requirement is the same you can do it with workfllow itself.
Please replace your workflow rule with the below code
AND(Account.Name!= Null, NOT(CONTAINS( Name ,LEFT(Account.Name, 10) +' : ')) )

and your workflow field update with this:
LEFT(Account.Name, 10) +' : '+ Name

Mark it as a best answer if it satisfies your requirement.


Thanks,
Sowmya.
sujatha dhanekulasujatha dhanekula
Where to enter filter code it will only show fields to filter
sowmya Inturi 9sowmya Inturi 9
Hi,
User-added image
clock the drop down you will see formula editor.
 
sujatha dhanekulasujatha dhanekula
Hi Sowmya, in Opportunity object When created or existing record is edited when user enter or update opportunity name to just ex: sujatha then it should auto update to acount name: opportunity name (ABC:sujatha) is this work flow or process builder? in workflow there is no option to enter criteria/filter code please advise how to do? Thank you SUjatha
sujatha dhanekulasujatha dhanekula
Hi Sowmya, Now i have clear requirement. When Opporutniyt is saved when created or edited if Opportunity name is not in the format Accountname:OpportunityName then set to Accountname:OpportunityName Can you pease provide code for me to have formula evaluates to true I wrote AND(Name!= Null, NOT(CONTAINS(Account.Name & ' : ' & Name)) I can set it to Account.Name & ':' & Name Please advise. Thank you Sujatha
sowmya Inturi 9sowmya Inturi 9
Hi,
Try thi in formula evaluates to true:
AND(Account.Name!= Null, NOT(CONTAINS( Name ,LEFT(Account.Name, 10) +' : ')) )


Thanks,
Sowmya.
sujatha dhanekulasujatha dhanekula
Sorry Sowmya, did not work. create opportunity I entered Opportunity name = Sujatha Account name = Test save opp name = Test:Sujatha (good) but I edited other fileds and save the opportunity then oppname = Test:Test:Sujatha Please help Thank you Sujatha
sowmya Inturi 9sowmya Inturi 9
Hi,
Modify your Rule criteria as:
User-added image

And FieldUpdate with the below formula:
IF(AND(NOT( ISCHANGED( AccountId ) ) ,NOT(CONTAINS( Name ,Account.Name +' : ')) ),Account.Name &' : '& Name,IF(AND( ISCHANGED(AccountId) ,NOT(CONTAINS( Name ,Account.Name +' : ')) ),Account.Name+' : '+SUBSTITUTE(Name, LEFT(Name, FIND(":", Name)), ''),Name))


I have checked it and it is working fine.

Thanks,
Sowmya.
sujatha dhanekulasujatha dhanekula
will try 
sowmya Inturi 9sowmya Inturi 9
Hi Sujatha,
Is it working fine?


Thanks,
Sowmya.
 
sujatha dhanekulasujatha dhanekula
Hi sowmya, it worked till I got personal account enabled and then working only for business account s.when I create opportunity with account name personal then not updating. Can you help please
sujatha dhanekulasujatha dhanekula
Sowmya,% by website 1 and website2 I have created report on lead with lead source grouping summary report. How to get this %. Thank you Sujatha
sujatha dhanekulasujatha dhanekula
Hi Sowmya,

Set opportunity name criteria 
AND( NOT(ISBLANK( Account.Name )),  NOT( CONTAINS( Name ,  Account.Name +':')) ) not working when I convert consumer leads.
create opportunity 
enter opportunity name = 200PC
select existiing account name = lendlease etc company name
submit opporuntiy name is updated to lendlease:200PC
but if you enterexisitn account name =  person name (Uma ABB)
then submit opportunityname i still 200PC
any soulution please.
sujatha dhanekulasujatha dhanekula
Sowmya, Can you please help I need to create days open formula field on opportunity I have entered F(ISPICKVAL(StageName, Closed Won), Closeddate - CreatedDate, TODAY()) - CreatedDate ) error as below Error: Syntax error. Found 'Closed' and highlighted the one in red above. But this is the value of stage. How to fix this. Thanks sujatha