You need to sign in to do that
Don't have an account?
How to Combined fields using Apex Class
Hi Team,
I have an object called "Projects" and fields on the project record. What I would like to attempt to acheive is when I create an Opp from the Projects object by clicking a create opp button, is to populate two or more fieldsfrom project into one field in an opp. Is this possible? Example below.
Projects Object
Fields
Project Name: Freedom Middle School Gym
Project Owner: City of Bakersfield
City: Bakersfield
State: CA
The above fields to populate on field on an Opp below. See Example:
Opp Object
Field
Opportunity Name: Freedom Middle School Gym
City of Bakersfield
Bakersfield, CA
Here is an example:
opp.Name = Proj.Name + ',' + Proj.Project_Owner__c ; < -------- Like this
All Answers
Yes, concatenate the fields together from project when assigning them to the opportunity name.
Thank you for taking a look at my post. See below:
public with sharing class CreateOppController {
private Project__c Proj ;
public CreateOppController(ApexPages.standardController std)
{
Proj = (Project__c)std.getRecord();
Proj = [select id , Name__c, Project_Owner__c, Bid_Date__c, City__c, State__c , Low_Bidder__c from Project__c where id =: Proj.Id limit 1];
}
public PageReference doCreateOpportunity(){
Opportunity opp = new Opportunity();
opp.Name = Proj.Name &","& Proj.Project_Owner__c ; < -------- Like this?
opp.BidDate__c = Proj.Bid_Date__c ;
opp.City__c = Proj.City__c;
opp.CloseDate = Date.today();
opp.State__c = Proj.State__c ;
opp.StageName = 'Bid Phase';
opp.Project__c = Proj.id;
Here is an example:
opp.Name = Proj.Name + ',' + Proj.Project_Owner__c ; < -------- Like this
As of right now it is separated by a comma. Like this: Freedom Middle School Gym,City of Bakersfield
Example:
Opportunity Name: Freedom Middle School Gym
City of Bakersfield
Bakersfield, CA
In Apex, you would concatenate by using '\n' instead of ','
However, opportunity.name field is a text field, not a textarea field so it won't display 'stacked'. That is, the '\n' is not converted to <br/> by SFDC. If your application permits it, use a textarea field instead