• Anup Kabra 2
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 2
    Replies
Hi All, 
I have created a visualforce page which uses account lookup fields. I am using these page in lightning by giving lightningstylesheets  = "true".
However, when I click on the search Icon of lookup field, the lookup pop opens in classic mode but I need this lookup field in lightning style. Is there anyway to get it work using Visualforce page?
User-added image
User-added image


 
I have visualforce page with two few fileds out of which there are two account fileds. I want to throw an error message when user tries to edit an existing record and enter same account name in both the account fields. I am not able to achieve this. below is my code: (It works fine for NEW record).

Visualforce Page:
<apex:page standardController="GRP_Fund_Relationship__c" extensions="GRP_EditNew_FundRelationshipCon" lightningStylesheets="true">
    <apex:form >
        <div align="center" draggable="false">
            <apex:commandbutton action="{!SaveAndRedirect}" Value="Save"/>   
            <apex:commandbutton action="{!CancelAndRedirect}" Value="Cancel" immediate="true" />   
        </div>
        <apex:pageBlock mode="edit">
            <apex:pageBlockSection title="Fund Relationship" columns="2" rendered="{!NOT(ISBLANK(GRP_Fund_Relationship__c.Id))}">
                            
                <apex:inputField value="{!GRP_Fund_Relationship__c.Name}"/>          
                <apex:inputField value="{!GRP_Fund_Relationship__c.GRP_Start_Date__c}"/>
                <apex:inputField value="{!GRP_Fund_Relationship__c.GRP_Account1__c}"/>
                <apex:inputField value="{!GRP_Fund_Relationship__c.GRP_End_Date__c}"/>
                <apex:inputField value="{!GRP_Fund_Relationship__c.GRP_Account2__c}"/>              
                <apex:inputField value="{!GRP_Fund_Relationship__c.GRP_Type_of_Relationship__c}"/>
               
            </apex:pageBlockSection>
            <apex:pageMessages />
            <apex:pageBlockSection title="New Fund Relationship" columns="2" rendered="{!(ISBLANK(GRP_Fund_Relationship__c.Id))}">
                            
                <apex:inputField value="{!NewFundRelationship.GRP_Account1__c}"/>
                <apex:inputField value="{!NewFundRelationship.GRP_Start_Date__c}"/>
                <apex:inputField value="{!NewFundRelationship.GRP_Account2__c}"/>
                <apex:inputField value="{!NewFundRelationship.GRP_End_Date__c}"/>
                <apex:inputField value="{!NewFundRelationship.GRP_Type_of_Relationship__c}"/>
               
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>

Controller:
public class GRP_EditNew_FundRelationshipCon {
    
    public account acc {set;get;}
    public string FundRelationshipID {get;set;}
    public string AccountParentId {get;set;}
    private ApexPages.StandardController controller;
    public GRP_Fund_Relationship__c NewFundRelationship {set;get;}
    public list<GRP_Fund_Relationship__c> FundRelationship {set;get;}
    public list<GRP_Fund_Relationship__c> CheckFundRelationship {set;get;}
    
    public GRP_EditNew_FundRelationshipCon (ApexPages.StandardController controller) {
         
        this.controller = controller;
        
        try{
            
            AccountParentId    = ApexPages.currentPage().getParameters().get('pid');
            FundRelationshipID = ApexPages.currentPage().getParameters().get('id');
            
            FundRelationship = [Select Name, GRP_Account1__c, GRP_Account2__c, GRP_Type_of_Relationship__c, GRP_Start_Date__c, GRP_End_Date__c 
                                from GRP_Fund_Relationship__c where id =:FundRelationshipID];
            
            NewFundRelationship = new GRP_Fund_Relationship__c(GRP_Account1__c = AccountParentId );
            
        }catch(Exception ex){
            
            system.debug('The following exception has occured in GRP_EditNew_FundRelationshipCon.GRP_EditNew_FundRelationshipCon --> ' + ex.getMessage() + ' || Row Number --> ' + ex.getLineNumber());
        }
    }
    
    public pagereference SaveAndRedirect(){
        
        try{
            
            if(FundRelationship.size() > 0){
                
                controller.save();
                
                CheckFundRelationship = [Select GRP_Account1__c, GRP_Account2__c from GRP_Fund_Relationship__c where id =:FundRelationshipID];
                
                system.debug('checkaccount 1---->'+CheckFundRelationship[0].GRP_Account1__c);
                system.debug('checkaccount 2---->'+CheckFundRelationship[0].GRP_Account2__c);
                
                if(checkFundRelationship[0].GRP_Account1__c == checkFundRelationship[0].GRP_Account2__c){
                    
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Account fields cannot have same Account Name'));
                    
                }else
                {    
                   system.debug('account 1---->'+FundRelationship[0].GRP_Account1__c);
                   system.debug('account 2---->'+FundRelationship[0].GRP_Account2__c);
                   
                   acc = [select id from account where id = :FundRelationship[0].GRP_Account1__c];
                }
                
            }else
            {
                if(NewFundRelationship.GRP_Account1__c == NewFundRelationship.GRP_Account2__c){
                    
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Account fields cannot have same Account Name'));

                }else
                {
                    Insert NewFundRelationship;
                    acc = [select id from account where id = :NewFundRelationship.GRP_Account1__c];
                }
            }
            
            PageReference ToAcc = new PageReference('/'+acc.Id);
            return ToAcc;

        }catch(Exception ex){
            
            system.debug('The following exception has occured in GRP_EditNew_FundRelationshipCon.SaveAndRedirect --> ' + ex.getMessage() + ' || Row Number --> ' + ex.getLineNumber());
            return null;
        }
    }
    
    public pagereference CancelAndRedirect(){
        
        try{
          
            if(FundRelationship.size() > 0){
                
                controller.cancel();  
                acc = [select id from account where id = :FundRelationship[0].GRP_Account1__c];
                PageReference ToAcc = new PageReference('/'+acc.Id);
                return ToAcc;
                
            }else
            {
                controller.cancel();            
                PageReference ToAcc = new PageReference('/'+AccountParentId);
                return ToAcc;
            }
            
        }catch(Exception ex){
            
            system.debug('The following exception has occured in GRP_EditNew_FundRelationshipCon.CancelAndRedirect--> ' + ex.getMessage() + ' || Row Number --> ' + ex.getLineNumber());
            return null;
        }
        
        
    }
    
}

 
I am using a inline visual force page as a related list for Account in lightning. Once I click on edit in visualforce page, it pops up a new window where I can edit. But, once I edit and click on save or cancel option, I don't see my visualforce page in the account detail page.

I am using command link for editing.

<apex:commandLink action="{!URLFOR($Action.Customobject__c .edit, a.id) }" >Edit</apex:commandLink>

Thanks in advance.
I am using inline visualforce page in Lightning account detail page as a related list of custom object. When I click on create a new record from VF page, I wan't to come back to parent page that is Account page once a record is created in custom object. How do I achive this. As of now, once the record is created in custom object, I am still in custom object.
Hi All, I am using an inline visualforce page in account layout to show related list of one of the custom object. When I click on edit and update the related record, changes dont reflect in Account detail page unless I refresh it. How do I refresh the accont detail page after updating records in inline visualforce page.

 <apex:commandLink action="{!URLFOR($Action.<custom object name>.edit, a.id) }">Edit</apex:commandLink>
I have two record types for Event and I need to disable Recurring Events for one of the record types. Can we do it without writing a code?
Hi All, I have a requirement where I need to create many to many relationship between Accounts. I know this can be achieved by using Junction or Intermediate object but I don't want two related list to show up on Account detail page.

For example: If Account A is related to Account B and Account C, Detail page of Account A should have one related list showing details of Account B and Account C. Similarly, Account B and C should have details of Account A on it detail page.

I tried using Intermediate object with two lookups for account but it returns two related list on account detail page but I need only one. 

Is there any way we can achieve this. Also, are there any apps on appexchange which can perform this task?
I am using inline visualforce page in Lightning account detail page as a related list of custom object. When I click on create a new record from VF page, I wan't to come back to parent page that is Account page once a record is created in custom object. How do I achive this. As of now, once the record is created in custom object, I am still in custom object.
Hi All, I have a requirement where I need to create many to many relationship between Accounts. I know this can be achieved by using Junction or Intermediate object but I don't want two related list to show up on Account detail page.

For example: If Account A is related to Account B and Account C, Detail page of Account A should have one related list showing details of Account B and Account C. Similarly, Account B and C should have details of Account A on it detail page.

I tried using Intermediate object with two lookups for account but it returns two related list on account detail page but I need only one. 

Is there any way we can achieve this. Also, are there any apps on appexchange which can perform this task?