How to Resolve the Links of Internal Components which doesn't have Pages in Tridion

In one of my Recent Project - we had situation where we need to resolve the link of Internal Components in Tridion but those DO NOT HAVE PAGES

 i.e. we have a Link Model – in general by default Tridion has a Link Model where it allows below fields.

Schema:

Model:

 

But here: in InternalLink by default we add the internal Tridion Comps which resolves the link automatically but in My Case: am adding internal comp where the pages doesn’t exists means those comps are dynamic one, then the issue arises in resolving the link which breaks my Model and return Null.

For e.g.: am inserting a comp of Schema ExternalLink which has Link (external Type) and AltText (Text) as parameters.

 

To overcome that here is the solution: am checking the whether the added Link is external or internal, if internal then by default it resolved the link otherwise it gets the values from new Model i.e. ExternalLink Model and get the value and returns the same. By this way you can pass any model that you are going to link and get those values as per logic.

Below you will find the sample code, you can modify the same as per your implementation.