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
Sourav PSourav P 

How to choose a field value in the master as per a criteria from the related list records

Dear All,
In my Quote object, i have a related list called " Named Driver" , as per below,
I want to create a field in Quote, which will show me the youngest driver i.e in this case 21. If less one say 18 added later, it will change to 18.  Can you plz suggest how to create such field, It would be a look up or text ( if text should be a hyperlink) to go inside the record.
Or if apex trigger needed, any sample code writing suggestions.
Thnx

User-added image
Best Answer chosen by Sourav P
Deepak Maheshwari 7Deepak Maheshwari 7

Please Make the Youngest Driver Name field of Rich Text Area.

 

And then copy the below code in Apex class:

 

public class OpportunityHandlers
{
    list<Quote> oppList = new list<Quote>();
    set<id> oppIDs = new set<id>();
    Map<string, Integer> mapMinAge = new Map<string, Integer>();
    
    public void oppInsert(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c !=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    
    public void oppUpdate(List<Quotation_Driver__c> oppLists,Map<Id,Quotation_Driver__c> oppOldmap)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
                if(oppOldmap.get(opp.id).Quote__c!=opp.Quote__c)
                {
                    oppIDs.add(oppOldmap.get(opp.id).Quote__c);
                }
            }
             
        }
        aggregateResults();

    }
    
    public void oppDelete(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    public void oppundelete(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    
    public void aggregateResults()
    {
        AggregateResult[] groupedResults = [SELECT MIN(AgeUpdated__c), Quote__c FROM Quotation_Driver__c where Quote__c IN :oppIDs GROUP BY Quote__c];
        for(AggregateResult ar:groupedResults) 
        {
            mapMinAge.put((String)ar.get('Quote__c'),(Integer)ar.get('expr0')); 
            /*Id oppId = (ID)ar.get('Quote__c');
            Double min = (DOUBLE)ar.get('expr0');
            Quote opp1 = new Quote(Id=oppId);
            opp1.Youngest_DriverT__c = min;
            oppList.add(opp1);*/
        }
        
        for (Quotation_Driver__c objNamedDriver : [SELECT Id,Name, AgeUpdated__c, Quote__c

                                                        FROM Quotation_Driver__c
                                                        WHERE Quote__c IN :oppIDs ]) {

            Quote objQuote;

            if(mapMinAge.containsKey(objNamedDriver.Quote__c)){

                if (mapMinAge.get(objNamedDriver.Quote__c) == objNamedDriver.AgeUpdated__c){
                oppList.add(new Quote(Id = objNamedDriver.Quote__c, Youngest_DriverT__c = '<a href=/' + objNamedDriver.Id+ '>'+objNamedDriver.Name+ '</a>'));

               }

            }

        } 
            if(oppList.size()>0 && oppList!=null)
            {
                update oppList;
            }
    }
}

All Answers

Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

 

If there is master-detail relationship between quote and named driver  then it can be done by making rollup summary field on Quote which will select the minimum value.

 

If relationship is lookup then we need to go for trigger.

 

Sourav PSourav P
Hi Deepak, Thanks. Its a look up relationship. So if you can suggest me on teh apex code, as i am not yet expert on apex.
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

 

Please provide me the API name of Named Driver object and its fields.

 

Thanks

Sourav PSourav P
Hi Deepak,
The API name of Named Driver is : Quotation_Driver__c
and the Age field on this object is : AgeUpdated__c

Thanks
Deepak Maheshwari 7Deepak Maheshwari 7
Please provide me the API name of lookup field of Quote which is on  Named Driver
Sourav PSourav P
Ya , sure. sorry i missed.
In Quote the field where the youngest driver should reflect is : Youngest_DriverT__c ( its a text field),
In Named Driver, the Quote look up field is : Quote__c
In Quote, once it reflect the youngest driver name, it should be a hyperlink to go the Named driver record.
Thank you.
If i missed somthing, plz let me know 
Deepak Maheshwari 7Deepak Maheshwari 7

Please create a Integer field on Quote with API name "Min_of_Age_Updated__c".

And then try below trigger and class.

FYI- I have assumed API of lookup field as Quote__c.

******************************************************************Trigger*******************************************************

trigger DealTrigger on Deal__c (after delete,after update, after insert, after undelete)
{
    if(trigger.isInsert)
    {
        OpportunityHandlers oppHandler =new OpportunityHandlers();
        oppHandler.oppInsert(Trigger.New); 
    }
    else if(trigger.isDelete)
    {
        OpportunityHandlers oppHandler =new OpportunityHandlers();
        oppHandler.oppDelete(Trigger.Old);
    }
    else if(trigger.isUnDelete)
    {
        OpportunityHandlers oppHandler =new OpportunityHandlers();
        oppHandler.oppundelete(Trigger.New);
    }
    else if(trigger.isUpdate)
    {
        OpportunityHandlers oppHandler =new OpportunityHandlers();
        oppHandler.oppUpdate(Trigger.New,Trigger.Oldmap);
    }

}

*******************************************************************Class***************************************************************************************************************************

public class OpportunityHandlers
{
    list<Quote> oppList = new list<Quote>();
    set<id> oppIDs = new set<id>();

    
    public void oppInsert(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quotation_Driver__c !=null)
            {
                oppIDs.add(opp.Quotation_Driver__c);
            }
        }
        aggregateResults();
    }
    
    public void oppUpdate(List<Quotation_Driver__c> oppLists,Map<Id,Quotation_Driver__c> oppOldmap)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
                if(oppOldmap.get(opp.id).Quote__c!=opp.Quote__c)
                {
                    oppIDs.add(oppOldmap.get(opp.id).Quote__c);
                }
            }
             
        }
        aggregateResults();

    }
    
    public void oppDelete(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    public void oppundelete(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    
    public void aggregateResults()
    {
        AggregateResult[] groupedResults = [SELECT MIN(AgeUpdated__c), Quote__c FROM Quotation_Driver__c where Quote__c IN :oppIDs GROUP BY Quote__c];
        for(AggregateResult ar:groupedResults) 
        {
            Id oppId = (ID)ar.get('Quote__c');
            Integer min = (INTEGER)ar.get('expr0');
            Quote opp1 = new Quote(Id=oppId);
            opp1.Min_of_Age_Updated__c= min;
            oppList.add(opp1);
        }
            if(oppList.size()>0 && oppList!=null)
            {
                update oppList;
            }
    }
}
 

LBKLBK
Try this trigger.

This will update the text field with the ID of the youngest driver.
 
trigger UpdateDriverAge on Quotation_Driver__c (after insert, after update, after delete) {
    Set<Id> setQuoteIDs = new Set<Id>();

    if (!Trigger.isDelete) {
        for (Quotation_Driver__c objNamedDriver : Trigger.new) {
            setQuoteIDs.add(objNamedDriver.Quote__c);
        }
    }
	else{
        for (Quotation_Driver__c objNamedDriver : Trigger.old) {
            setQuoteIDs.add(objNamedDriver.Quote__c);
        }
    }
	
    if (!setQuoteIDs.isEmpty()) {
        List<Quote__c> lstQuotesToUpdate = new List<Quote__c>();
		
		Map<Id, Integer> mapMinAge = new Map<Id, Integer>();
		
		for (AggregateResult ar : [SELECT MIN(AgeUpdated__c), Quote__c FROM Quotation_Driver__c 
								WHERE Quote__c IN :setQuoteIDs GROUP BY Quote__c]) {
            mapMinAge.put(ar.Quote__r.Id, ar.get('expr0'));
        }
		
        for (Quotation_Driver__c objNamedDriver : [SELECT Id, AgeUpdated__c, Quote__c
														FROM Quotation_Driver__c
														WHERE Quote__c IN :setQuoteIDs]) {
            Quote__c objQuote;
			if(mapMinAge.containsKey(objNamedDriver.Quote__r.Id)){
				if (mapMinAge.get(objNamedDriver.Quote__r.Id) == objNamedDriver.AgeUpdated__c){
					lstQuotesToUpdate.add(new Quote__c(Id = objNamedDriver.Quote__r.Id, Youngest_DriverT__c = (String)objNamedDriver.Id));
				}
			}
        }

        if (!lstQuotesToUpdate.isEmpty()) {
            update lstQuotesToUpdate;
        }
    }
}
Let me know if this helps.
 
LBKLBK
By the way, if you want to change Youngest_DriverT__c to a lookup relationship, you just need to remove (String) from line 31.
Sourav PSourav P
Thanks Dipak and LBK. Let me try the code.
Sourav PSourav P
Hi LBK, I tried to use, its giving me teh below error while saving, Can you plz suggest why so

Error: Compile Error: Invalid type: Quote__c at line 16 column 53

That is, the Quote look up in teh Named Driver object( below one)

User-added image
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

 

As you are using standard Quote object so please use Quote in place of Quote__c

LBKLBK
+1 Deepak

Yes. If it is standard quote object, please change the object reference from Quote__c to Quote.

A word of caution, please do not change the lookup relationship names in your Named Driver object.
Sourav PSourav P
Hi Deepak, OK. But if we use from Named Driver, The look up field API name is Quote__c actually. So shall i use Quote or Quote__c ? Thnx

User-added image
LBKLBK
You need to change the object name in line 16 and 31.

and, you can remove line 28.

 
Sourav PSourav P
So Object name to Quote, Isnt it ? thnx
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

 

Please let me know if issue is resolved and if not please let me know what error is coming

 

Thanks

Sourav PSourav P
Hi Dipak, If i use only Quote, rather than Quote__c, its giving me teh below error, as there is no Quote in Named Driver, i think it should be Quote__c, but dont know why its showing issue.

Error: Compile Error: No such column 'Quote' on entity 'Quotation_Driver__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 20 column 35
Sourav PSourav P
Hi Dipak, I am just trying your code. I have to write a separate class as well, isnt it.
Deepak Maheshwari 7Deepak Maheshwari 7
trigger DealTrigger on Quotation_Driver__c (after delete,after update, after insert, after undelete)
{
    if(trigger.isInsert)
    {
        OpportunityHandlers oppHandler =new OpportunityHandlers();
        oppHandler.oppInsert(Trigger.New); 
    }
    else if(trigger.isDelete)
    {
        OpportunityHandlers oppHandler =new OpportunityHandlers();
        oppHandler.oppDelete(Trigger.Old);
    }
    else if(trigger.isUnDelete)
    {
        OpportunityHandlers oppHandler =new OpportunityHandlers();
        oppHandler.oppundelete(Trigger.New);
    }
    else if(trigger.isUpdate)
    {
        OpportunityHandlers oppHandler =new OpportunityHandlers();
        oppHandler.oppUpdate(Trigger.New,Trigger.Oldmap);
    }

}

************************************************************************************Class**********************************************************************************************************

public class OpportunityHandlers
{
    list<Quote> oppList = new list<Quote>();
    set<id> oppIDs = new set<id>();

    
    public void oppInsert(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c !=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    
    public void oppUpdate(List<Quotation_Driver__c> oppLists,Map<Id,Quotation_Driver__c> oppOldmap)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
                if(oppOldmap.get(opp.id).Quote__c!=opp.Quote__c)
                {
                    oppIDs.add(oppOldmap.get(opp.id).Quote__c);
                }
            }
             
        }
        aggregateResults();

    }
    
    public void oppDelete(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    public void oppundelete(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    
    public void aggregateResults()
    {
        AggregateResult[] groupedResults = [SELECT MIN(AgeUpdated__c), Quote__c FROM Quotation_Driver__c where Quote__c IN :oppIDs GROUP BY Quote__c];
        for(AggregateResult ar:groupedResults) 
        {
            Id oppId = (ID)ar.get('Quote__c');
            Double min = (DOUBLE)ar.get('expr0');
            Quote opp1 = new Quote(Id=oppId);
            opp1.Youngest_DriverT__c = min;
            oppList.add(opp1);
        }
            if(oppList.size()>0 && oppList!=null)
            {
                update oppList;
            }
    }
}

 
Sourav PSourav P
Hi Dipak, Thanks
while trying to save the apex class, i am getting the below error, Do you know why?

User-added image
Deepak Maheshwari 7Deepak Maheshwari 7

same code I am using in my org it is working.

Can you please again copy and paste the code?

Sourav PSourav P
I think it was alignments, i tried put it on extreme left, but now its showing below error

Compile Error: line 58:39 no viable alternative at character ' ' at line 58 column 39
public class OpportunityHandlers
{
list<Quote> oppList = new list<Quote>();
set<id> oppIDs = new set<id>();
public void oppInsert(List<Quotation_Driver__c> oppLists)
{
for(Quotation_Driver__c opp : oppLists)
{
if(opp.Quote__c !=null)
{
oppIDs.add(opp.Quote__c);
}
}
aggregateResults();
}
public void oppUpdate(List<Quotation_Driver__c> oppLists,Map<Id,Quotation_Driver__c> oppOldmap)
{
for(Quotation_Driver__c opp : oppLists)
{
if(opp.Quote__c!=null)
{
oppIDs.add(opp.Quote__c);
if(oppOldmap.get(opp.id).Quote__c!=opp.Quote__c)
{
oppIDs.add(oppOldmap.get(opp.id).Quote__c);
}
}
}
aggregateResults();

}
public void oppDelete(List<Quotation_Driver__c> oppLists)
{
for(Quotation_Driver__c opp : oppLists)
{
if(opp.Quote__c!=null)
{
oppIDs.add(opp.Quote__c);
}
}
aggregateResults();
}
public void oppundelete(List<Quotation_Driver__c> oppLists)
{
for(Quotation_Driver__c opp : oppLists)
{
if(opp.Quote__c!=null)
{
oppIDs.add(opp.Quote__c);
}
}
aggregateResults();
}
public void aggregateResults()
{
AggregateResult[] groupedResults = [SELECT MIN(AgeUpdated__c), Quote__c FROM Quotation_Driver__c where Quote__c IN :oppIDs GROUP BY Quote__c];
for (AggregateResult ar:groupedResults) 
{
Id oppId = (ID)ar.get('Quote__c');
Double min = (DOUBLE)ar.get('expr0');
Quote opp1 = new Quote(Id=oppId);
opp1.Youngest_DriverT__c = min;
oppList.add(opp1);
}
if(oppList.size()>0 && oppList!=null)
{
update oppList;
}
}
}

 
Deepak Maheshwari 7Deepak Maheshwari 7

This is again the same type of error which you received earlier.

It can be resolved again in same way.

Sourav PSourav P
Hi Dipak , Now this :(. i formatted all
Error: Compile Error: Illegal assignment from Double to String at line 62 column 1

User-added image
Deepak Maheshwari 7Deepak Maheshwari 7

Actually, you have taken Youngest driver as text field, please make it number type because age will be in number.

Deepak Maheshwari 7Deepak Maheshwari 7

I got you point you want the name of Youngest Driver name in the text field.

No issue first you try this then I will add the logic for that in my class

Sourav PSourav P
Hi Deepak, Thanks a lot. Yes you are right. i want the name of the Driver field ( API : Name) in a text field as well. Can you plz help me with that. and finally the above code is working perfect now. But its giving the age number. So Can i chaange it back to text field, so that we can get the Name in teh field.
Deepak Maheshwari 7Deepak Maheshwari 7

ok let me add that functionality in code.

 

As soon as I will do will let you know

Sourav PSourav P
Thanks Deepak.
Deepak Maheshwari 7Deepak Maheshwari 7

Please Make the Youngest Driver Name field of Rich Text Area.

 

And then copy the below code in Apex class:

 

public class OpportunityHandlers
{
    list<Quote> oppList = new list<Quote>();
    set<id> oppIDs = new set<id>();
    Map<string, Integer> mapMinAge = new Map<string, Integer>();
    
    public void oppInsert(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c !=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    
    public void oppUpdate(List<Quotation_Driver__c> oppLists,Map<Id,Quotation_Driver__c> oppOldmap)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
                if(oppOldmap.get(opp.id).Quote__c!=opp.Quote__c)
                {
                    oppIDs.add(oppOldmap.get(opp.id).Quote__c);
                }
            }
             
        }
        aggregateResults();

    }
    
    public void oppDelete(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    public void oppundelete(List<Quotation_Driver__c> oppLists)
    {
        for(Quotation_Driver__c opp : oppLists)
        {
            if(opp.Quote__c!=null)
            {
                oppIDs.add(opp.Quote__c);
            }
        }
        aggregateResults();
    }
    
    public void aggregateResults()
    {
        AggregateResult[] groupedResults = [SELECT MIN(AgeUpdated__c), Quote__c FROM Quotation_Driver__c where Quote__c IN :oppIDs GROUP BY Quote__c];
        for(AggregateResult ar:groupedResults) 
        {
            mapMinAge.put((String)ar.get('Quote__c'),(Integer)ar.get('expr0')); 
            /*Id oppId = (ID)ar.get('Quote__c');
            Double min = (DOUBLE)ar.get('expr0');
            Quote opp1 = new Quote(Id=oppId);
            opp1.Youngest_DriverT__c = min;
            oppList.add(opp1);*/
        }
        
        for (Quotation_Driver__c objNamedDriver : [SELECT Id,Name, AgeUpdated__c, Quote__c

                                                        FROM Quotation_Driver__c
                                                        WHERE Quote__c IN :oppIDs ]) {

            Quote objQuote;

            if(mapMinAge.containsKey(objNamedDriver.Quote__c)){

                if (mapMinAge.get(objNamedDriver.Quote__c) == objNamedDriver.AgeUpdated__c){
                oppList.add(new Quote(Id = objNamedDriver.Quote__c, Youngest_DriverT__c = '<a href=/' + objNamedDriver.Id+ '>'+objNamedDriver.Name+ '</a>'));

               }

            }

        } 
            if(oppList.size()>0 && oppList!=null)
            {
                update oppList;
            }
    }
}

This was selected as the best answer
Sourav PSourav P
Hi Deepak , Thanks a lot.
So you mean i make the "Youngest_DriverT__c" as Text Area (Rich) ? Is that not working if i make that a look up field kind ? as it should be clickable to go to that record.
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

 

Yes you have to make "Youngest_DriverT__c" as Text Area (Rich). It will store record as a link. When you will click on that link then you can go to that record.

Deepak Maheshwari 7Deepak Maheshwari 7

Hope this works for you!

If not then please let me know.

Sourav PSourav P
Hi Deepak, sure,  thnx.
I was just trying to edit it. One error constantly showing, its like before , i am not able to chck how to resolve it, In Before code it went automatically

User-added image
Deepak Maheshwari 7Deepak Maheshwari 7

In line 57 why you have put semi colon ;.

Please again copy and paste the code which I have sent to you

Deepak Maheshwari 7Deepak Maheshwari 7
Did your code saved without any error?
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

 

Please mark as a best answer if this helps you!

Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,
 

Did my solution doesn't work for you?

Please let me know where did you stuck.

 

Thanks

Deepak

dpkm20@gmail.com
 

Sourav PSourav P
Hi Deepak, Thanks , and sry i couldnt do teh changes in teh ween end. I am just working now, and let you know incase any issue. I am trying to copy , paste again.
Sourav PSourav P
Hi Deepak, after the formatting , now i am able to save the Opp handlers class. But shall i need to change the apex trigger? as its showing the below error,
Also, i saved the field as text rich, but it will not proper, as on edit page its showing me a very big space in the Young driver field, Do making it as a text field work ? Thanks


Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger DealTrigger caused an unexpected exception, contact your administrator: DealTrigger: execution of AfterInsert caused by: System.TypeException: Invalid conversion from runtime type Decimal to Integer: Class.OpportunityHandlers.aggregateResults: line 59, column 1
Sourav PSourav P
Hi Deepak, I am not able to add a new " Named driver" below is the error, i taken the Young_DriverT__c data type as TEXT.

User-added image
Deepak Maheshwari 7Deepak Maheshwari 7
Please change Integer to Double at all places in the code.
Deepak Maheshwari 7Deepak Maheshwari 7

If you donot want rich text area type field then  Young_DriverT__c as text field which will store id of record.

Then we will create a formula field to show as a link.

 

Please confirm for this then I need to some changes in the code.

Sourav PSourav P
Hi Deepak. sure, let me change all integer.
Yes, Can we plz change it to text field. As making it text rich, is not showing proper in the edit page. Thanks
Sourav PSourav P
Hi Deepak, Now its showing me the below error, But here i made the Young Driver field as text field.( may be due to this ? )


Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger DealTrigger caused an unexpected exception, contact your administrator: DealTrigger: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0Q0N00000007tcPKAQ; first error: STRING_TOO_LONG, Youngest DriverT: data value too large: <a href=/a0eN0000004fg9YIAQ>QD-02023</a> (max length=25): [Youngest_DriverT__c]: Class.OpportunityHandlers.aggregateResults: line 75, column 1
Sourav PSourav P
Worked :), But happening like this , i think below format support only rich text.

<a href=/a0eN0000004fg9nIAA>QD-02026</a>
Sourav PSourav P
Hi Dipak, I just removed the hyperlink, and made it as per below and its working now. Is that fine to remove here ? or we have to write in a different way ? Thnx

oppList.add(new Quote(Id = objNamedDriver.Quote__c, Youngest_DriverT__c = objNamedDriver.Name));
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

Please create 1 more text field: "Name of Driver"  on Quote which will show name of field.

Please change below line of code :

 oppList.add(new Quote(Id = objNamedDriver.Quote__c, Youngest_DriverT__c = '<a href=/' + objNamedDriver.Id+ '>'+objNamedDriver.Name+ '</a>'));

 

to

oppList.add(new Quote(Id = objNamedDriver.Quote__c, Youngest_DriverT__c = URL.getSalesforceBaseUrl().toExternalForm() + '/' + objNamedDriver.Id,Name_of_Driver__c=objNamedDriver.Name));

 

After that create a formula field "Young Driver" and put below in it:

 

HYPERLINK( Youngest_DriverT__c , Name_of_Driver__c ).

 

Also, increase the size of the text field. then remove both the text field from layout and only formula field will be visible on layout.

 

 

Sourav PSourav P
Ohh, i cant click and go inside the record now, we need the hyperlink :). plz suggest.
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

 

Hope this works for you!

Thanks

Deepak

dpkm20@gmail.com

Sourav PSourav P
Hi Deepak, Thanks a lot.
Finally it worked :).
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Sourav,

 

You can directly drop me a mail if you face any issue in future.

 

Thanks

Deepak

dpkm20@gmail.com

Sourav PSourav P
Thanks Deepak, for the support. :)

Regards,
Sourav