+ Start a Discussion
KCLKCL 

I have one Custom Object in that created 2 Custom Fields 1.Related Account 2. Related Opp. After delecting the Opp through lookup in second field how to pull Acount record related to that opportunity in first field.

I have one Custom Object in that created 2 Custom Fields 1.Related Account 2. Related Opp. After delecting the Opp through lookup in  second field how to pull Acount record related to that opportunity in first field.
Raj VakatiRaj Vakati
You can try to do it with URL hacks 
or You can do it with visualforce page override .. 

http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html
https://www.salesforceben.com/salesforce-url-hacking-tutorial/
Akshay_DhimanAkshay_Dhiman
Hi Vra

Here Custom Object name is CopyToAccount__c fields are Opportunity__c and Account__c
 
public class CopyDataOpportunity {
    public static void copyAllDataWithBaseOfOpporunity(){
        List<CopyToAccount__c> copyToAccountList = new List<CopyToAccount__c>();
        List<CopyToAccount__c> copyToAccountListBYMap = new List<CopyToAccount__c>();//use to store map List
        /* Copy all opportunituy id relatated to copyTo Account Object in oppIdSet set */
        Set<Id> oppIdSet = new Set<id>();
        List<CopyToAccount__c> UpdateCopyList = new List<CopyToAccount__c>();
        Map<Id,List<CopyToAccount__c>> OppIdVSCopyListMap  = new Map<Id,  List<CopyToAccount__c>>();
        Map<Id,Id> OppIdVSAccIdMap = new Map<Id,Id>();
        
        List<Opportunity> oppList = new List<Opportunity>();
        copyToAccountList = [SELECT Name,
                             Opportunity__c,
                             Account__c
                             FROM CopyToAccount__c ];
        if(copyToAccountList.size() > 0){
            for(CopyToAccount__c CopyToAccountObj : copyToAccountList)
            {
                if (!OppIdVSCopyListMap.containsKey(CopyToAccountObj.Opportunity__c)) {
                    OppIdVSCopyListMap.put(CopyToAccountObj.Opportunity__c, new List <CopyToAccount__c>());
                }
                OppIdVSCopyListMap.get(CopyToAccountObj.Opportunity__c).add(CopyToAccountObj);
            }
           oppList = [SELECT Account.Id
                       FROM Opportunity
                       WHERE Id =: OppIdVSCopyListMap.keySet() ];
            if(oppList.size() > 0){
                
                for(Opportunity OppObj : oppList)
                {
                    if (!OppIdVSAccIdMap.containsKey(OppObj.Id)) {
                        OppIdVSAccIdMap.put(OppObj.Id, OppObj.Account.Id );
                    }
                }
                for(Id MapOppId : OppIdVSCopyListMap.keySet()){
                    
                    copyToAccountListBYMap = OppIdVSCopyListMap.get(MapOppId);
                    for(CopyToAccount__c ObjForCopyField : copyToAccountListBYMap)
                    {
                        ObjForCopyField.Account__c = OppIdVSAccIdMap.get(MapOppId);
                        UpdateCopyList.add(ObjForCopyField);
                    }
                }
                if(UpdateCopyList.size() > 0 ){
                    UPDATE UpdateCopyList;
                }
            }
        }
    }  
}



Hope this might helps...

Thank you
Akshay