• Олег Савинков
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
Help, please!
I have VF page
<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospInsert" id="CallsHospInsert">
 <apex:form id="myForm">
  

<script>
                        function getV() {

                            var AccValue = document.getElementById("CallsHospInsert:myForm:pblock:pBS:pBSI:organisation").value;
                            document.getElementById("CallsHospInsert:myForm:pblock:theHiddenInput").value=AccValue;
                            console.log('getv '+AccValue);
                            myFun();        
                                                                       
                        }
                    </script>

<script>     
 function openLookup(BaseUrl,width,modified,searchstr)
        {
           var receivedUrl=BaseUrl;
           var receivedwidth=width;
           var receivedmodified=modified;
           var receivedsearchstr=searchstr;
           var lookuptype=receivedUrl.substr(receivedUrl.length-3,3);
           if(receivedmodified=='1')
           {
               BaseUrl=BaseUrl+searchstr;
           }
           var urlArr=BaseUrl.split("&");
               //----If you are using this in inline editing then it would be var NxtSpltArr=urlArr[0].split("="); -----------
               var NxtSpltArr=urlArr[1].split("=");
               var txtfrmarr=NxtSpltArr[1];
           if(lookuptype=='001')
           {
             
           if(txtfrmarr.indexOf('organisation')> -1)
               {

                   BaseUrl="/apex/AccountsListforHosp?context=pharma_chain&list=noList&txt="+txtfrmarr;
                   BaseUrl=BaseUrl + "&frm=" + escapeUTF("{!$Component.myForm}");
                   BaseUrl=BaseUrl + "&lksearch=" + searchstr;
               }
           
               
           }
            if(lookuptype=='003')
           {
              
           
           if(txtfrmarr.indexOf('contact')> -1)
               {   
                   var orgid = document.getElementById("CallsHospInsert:myForm:pblock:theHiddenInput").value;
                   BaseUrl="/apex/ContactsListforHosp?context=pharma_chain&list=noList&org="+orgid+"&txt="+txtfrmarr;
                   BaseUrl=BaseUrl + "&frm=" + escapeUTF("{!$Component.myForm}");
                   BaseUrl=BaseUrl + "&lksearch=" + searchstr;
               }               
           }
           openPopup(BaseUrl,"lookup",950,480,"width=1420,height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no",true);   

        }
</script>

            
<apex:actionfunction name="myFun" action="{!SelectServiceIns}" onComplete="alert('After apex method') ;">
<!--  <apex:param name="AccIns" value="" assignTo="{!AccIns}"/>-->
  
</apex:actionFunction>            
            
            
        <apex:pageBlock mode="edit" id="pblock" >
            <apex:pageMessages id="message" />
            <apex:pageBlockButtons location="top">                                
                <apex:actionStatus id="mySaveStatus1">
                <apex:facet name="stop">
                <apex:commandButton value="Save" action="{!save}" rerender="pblock" status="mySaveStatus1"/>
                </apex:facet>
                <apex:facet name="start">
                <apex:commandButton value="Save" status="mySaveStatus1" disabled="true"/>
                </apex:facet>
                </apex:actionStatus>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
   <apex:inputHidden value="{!AccIns}" id="theHiddenInput"/>    
   <apex:actionSupport action="{!SelectServiceIns}"/>     

             
<!--            <apex:outputPanel rendered="{!IF($CurrentPage.parameters.theType = 'app', false, true)}" >-->
            <apex:pageBlockSection columns="2" id="pBS">
                <apex:pageBlockSectionItem id="pBSI">                
                    <apex:outputLabel value="Organisation" for="organisation"/>
                    <apex:inputfield value="{!rep.AccountID__c}" id="organisation" required="true" >
                        <apex:actionSupport event="onchange" action="{!SelectServiceIns}" reRender="contactPanel" status="status" oncomplete="getV(); return true;"  />
                    </apex:inputfield>
                </apex:pageBlockSectionItem>
                
                
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Date" for="datetime"/>
                    <apex:inputfield value="{!rep.Date__c}" id="theDate"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Address"/>
                    <apex:outputText value="{!rep.AccountID__r.BillingCity},{!rep.AccountID__r.BillingStreet}" id="address" >
                    </apex:outputText>
and i have controller:
public class CtrlCallHospInsert {


public CallReportHosp__c rep {get; set;}

public String AccIns{get;set;}

private Account rep2;



private ApexPages.StandardController controller { get; set; }

    public CtrlCallHospInsert(ApexPages.StandardController controller) {
         this.controller = controller; 
         this.rep = new CallReportHosp__c();
         this.rep.AccountID__c=NULL;
         this.rep.ContactID__c=NULL;
         this.rep.Duration__c='30 min';
         AccIns='';
    }



public PageReference save(){
        
        try {
            insert rep;
        }catch (Exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '"Something went wrong !"'));
        }
        PageReference pageRef = Page.CallsHospList;
        pageRef.setRedirect(true);
        return pageRef;
    }
    
    
public PageReference SelectServiceIns(){ 
System.debug('select ');
 System.debug('acc = '+AccIns);
 this.rep.AccountID__c=AccIns;
 this.rep.put('AccountID__c',AccIns);
 System.debug('new value= '+this.rep.get('AccountID__c'));
 System.debug('accvalue= '+AccIns);
 rep2=[Select id, BillingCity, BillingStreet  FROM Account where id=:AccIns];
 this.rep.AccountID__r.BillingCity=rep2.BillingCity;
 this.rep.AccountID__r.BillingStreet=rep2.BillingStreet;  
// this.Acc = rep2.Id;
 this.rep.AccountID__c=AccIns;
 this.rep.put('AccountID__c',AccIns);
 System.debug('new value= '+this.rep.get('AccountID__c'));
 System.debug('accvalue= '+AccIns);
return null;
}

    
 public PageReference cancel() {
        PageReference pageRef = Page.CallsHospList;
        pageRef.setRedirect(true);
        return pageRef;        
    }
    
}
I tried to call controller method SelectServiceIns from actionfunction. I see that function working ( console.log('getv '+AccValue) - returned true value), i see that actionfunction started ( alert('After apex method') ; - returned on page), but my method not calling!!!I can't see System.debug('select ') in system journal. And  i  Inserting new object with my lookup window so i cant't use standard controller and onchage event don't work on field AccountID__c (what's weird)

 
Hello!
I have VF page.
Some code:
<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospEdit" id="CallsHospEditt">
<apex:sectionHeader title="Calls" subtitle="{!rep.Name}"/>
<apex:form id="myForm">
<script type="text/javascript">

function ConvertTofact() {  openPopup("/apex/ConvertHosp?id={!rep.Id}" ); }

window.addSelectedOrganisations = function(Organisations) {
            applyFilterByOrganisations(Organisations);}
</script>
<script>     
 function openLookup(BaseUrl,width,modified,searchstr)
        {
         console.log("{!Acc}");  console.log("{!rep.AccountID__r.BillingCity},{!rep.AccountID__r.BillingStreet}");  
           var receivedUrl=BaseUrl;
           var receivedwidth=width;
           var receivedmodified=modified;
           var receivedsearchstr=searchstr;
           
           var lookuptype=receivedUrl.substr(receivedUrl.length-3,3);
           if(receivedmodified=='1')
           {
               BaseUrl=BaseUrl+searchstr;
           }
           var urlArr=BaseUrl.split("&");
               //----If you are using this in inline editing then it would be var NxtSpltArr=urlArr[0].split("="); -----------
               var NxtSpltArr=urlArr[1].split("=");
               var txtfrmarr=NxtSpltArr[1];
           if(lookuptype=='001')
           {
             
           if(txtfrmarr.indexOf('organisation')> -1)
               {
               
                   BaseUrl="/apex/AccountsListforHosp?context=pharma_chain&list=noList&txt="+txtfrmarr;
                   BaseUrl=BaseUrl + "&frm=" + escapeUTF("{!$Component.myForm}");
                   BaseUrl=BaseUrl + "&lksearch=" + searchstr;

               }
           
               
           }
            if(lookuptype=='003')
           {
              
           
           if(txtfrmarr.indexOf('contact')> -1)
               {
                   BaseUrl="/apex/ContactsListforHosp?context=pharma_chain&list=noList&org="+"{!Acc}"+"&txt="+txtfrmarr;
                   BaseUrl=BaseUrl + "&frm=" + escapeUTF("{!$Component.myForm}");
                   BaseUrl=BaseUrl + "&lksearch=" + searchstr;
               }
               
           }
           openPopup(BaseUrl,"lookup",950,480,"width=1420,height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no",true);
           
        }
</script>




   
    <apex:actionfunction name="applyFilterByOrganisations" action="{!applyFilterByOrganisations}" rerender="organisation" status="asLoadingSelectedOrganisations">
            <apex:param name="selectedOrganisationsStr" value="" assignto="{!selectedOrganisationsStr}" />
        </apex:actionfunction>
        
<apex:outputLink title="" value="/apex/ConvertHosp?id={!rep.Id}" style="font-weight:bold">Convert to fact</apex:outputLink>
        <apex:pageBlock mode="edit" id="pblock" >
            <apex:pageMessages id="message" />
            <apex:pageBlockButtons location="top">                                
                <apex:actionStatus id="mySaveStatus1">
                <apex:facet name="stop">
                <apex:commandButton value="Save" action="{!save}" rerender="pblock" status="mySaveStatus1"/>
                </apex:facet>
                <apex:facet name="start">
                <apex:commandButton value="Save" status="mySaveStatus1" disabled="true"/>
                </apex:facet>
                </apex:actionStatus>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            
<apex:outputText value="{!rep.Id}"/>
             
<!--            <apex:outputPanel rendered="{!IF($CurrentPage.parameters.theType = 'app', false, true)}" >-->
            <apex:pageBlockSection columns="2">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Organisation" for="organisation"/>
                    <apex:inputfield value="{!rep.AccountID__c}" id="organisation"  required="true">
                         <apex:actionSupport event="onchange"  reRender="pblock" status="status" action="{!SelectService}" />
                    </apex:inputfield>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Address"/>
                    <apex:outputText value="{!rep.AccountID__r.BillingCity},{!rep.AccountID__r.BillingStreet}" id="address" >
                    </apex:outputText>
                    
                </apex:pageBlockSectionItem>
 
                <apex:pageBlockSectionItem >


                <apex:outputLabel value="Contact" for="contacts"/>
                <apex:inputfield value="{!rep.ContactId__c}" id="contact" required="true" /> 



                </apex:pageBlockSectionItem>

               
                
.......              some code here .......
         
            
            
 </apex:pageBlockTable>
 </apex:outputPanel>
 </apex:pageBlockSection>          

        </apex:pageBlock>
        
        
    </apex:form>
    
</apex:page>
This page open from other page and i editing in this page field 'organisation'. Then I must pass new value of this field to javascript to have contacts from this organizations. And this is code of controller:
public with sharing class CtrlCallHospEdit implements ICallReportCtrl {
   public Boolean booleanValue {get;set;}
   public Boolean HaveAssCalls {get;set;}

    public  CallReportHosp__c rep{get;set;}
    public  Id Acc{get;set;}

    public List<CallReportHosp__c> AssCalls{get; set;}

    public Boolean isChina {get;set;}
    public Account rep2;
    private final User userInfoCheck;    
    
    public Set<Id> selectedOrganisationsIds  { get; set; }
    public String selectedOrganisationsStr { get; set; }



    private String userCountry;             // contains the country from the suer record to control visibility of sample management fields
    private Integer numberOfPromotedProducts;   // set in custom settings
      
    
    public Id singleDoctorId;
    public Id CallHospId;
    public Id userId;
    public Id CompanyId;
    public Id ContactId;
    public Id Parent;

    public String PlannedC;
    public String parameterValue;


    public CtrlCallHospEdit(ApexPages.StandardController controller) {
       isChina = UserInfo.getDefaultCurrency() == 'RUB' ? true : false;
       parameterValue = ApexPages.currentPage().getParameters().get('id');
       rep = [Select Id, Name, OwnerID, Date__c, ContactId__r.Name, CallTime__c, CallType__c, AccountID__r.BillingCity, AccountID__r.BillingStreet, ContactId__c, Field1_del__c, Duration__c, AccountID__c, AccountID__r.Name, Planned__c, ParentCallHOSP__c, Speciality_Hosp__c FROM CallReportHosp__c where id=:parameterValue];
       PlannedC=rep.Planned__c;   
       Parent=rep.ParentCallHOSP__c;   
       this.Acc=rep.AccountID__c; 
       getAssCalls();
//        userInfoCheck = [Select Id, Custom_Object_Country__c, CurrencyIsoCode, Is_Exempted_in_Call_Report_Validation__c from User where Id = :userId];
    }


some code here

public void SelectService(){ 
 this.Acc=rep.AccountID__c; System.debug('accvalue= '+Acc);
 rep2=[Select BillingCity, BillingStreet  FROM Account where id=:Acc];
 rep.AccountID__r.BillingCity=rep2.BillingCity;
 rep.AccountID__r.BillingStreet=rep2.BillingStreet;  
    }   

public PageReference save(){
        
        try {
            update rep;
        }catch (Exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '"Something went wrong !"'));
        }
        PageReference pageRef = Page.CallsHospList;
        pageRef.setRedirect(true);
        return pageRef;
    }
    
 public PageReference cancel() {
        PageReference pageRef = Page.CallsHospList;
        pageRef.setRedirect(true);
        return pageRef;        
    }


}
I had old value in VF page, i see new value in field 'organisation', my method SelectService() working, i see new address ( address for new value of field 'organisaton'). But when i pass variable 'Acc' to js, i get old value of organization!
How i can pass NEW value to js ( but i can't do save() metod, because user may be not saving new values) to see contacts for new organizatin?
 
Hello!
I have some page named CallsHospInsert. It have some code:
<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospInsert" id="CallsHospEditt">
<script type="text/javascript">
function openOrganisationDialog() {
        openPopup("/apex/AccountsListforHosp?context=pharma_chain&list=noList", "lookup", 900, 600, "width=900,height=600,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
        }
        window.addSelectedOrganisationsIns = function(Organisations) {
            applyFilterByOrganisationsIns(Organisations);}
</script>
    <apex:form >


 <apex:actionfunction name="applyFilterByOrganisationsIns" action="{!applyFilterByOrganisationsIns}" rerender="isorganisation,organisation" status="asLoadingSelectedOrganisations">
            <apex:param name="selectedOrganisationsStr" value="" assignto="{!selectedOrganisationsStr}" />
        </apex:actionfunction>

<apex:pageBlockSectionItem >
                
                    <apex:outputLabel value="Organisation" for="organisation"/>
                    <apex:actionRegion id="isorganisation" >
                    <apex:inputfield value="{!rep.AccountID__c}" id="organisation" required="true" onclick="openOrganisationDialog()">

                    </apex:inputfield>
                    </apex:actionRegion>
                
                </apex:pageBlockSectionItem>

Controller:
public class CtrlCallHospInsert {

public Boolean booleanValue {get;set;}
public CallReportHosp__c rep {get; set;}

public Set<Id> selectedOrganisationsIds  { get; set; }
public String selectedOrganisationsStr { get; set; }

private ApexPages.StandardController controller { get; set; }

    public CtrlCallHospInsert(ApexPages.StandardController controller) {
         this.controller = controller; 
         this.rep = (CallReportHosp__c)controller.getRecord();   
         this.booleanValue=false;       
         System.debug(' bool= '+booleanValue);
         SelectService(); 
    }

public void applyFilterByOrganisationsIns() {
system.debug('apply filter by org');
        this.selectedOrganisationsIds = new Set<Id>();
        if(String.isBlank(this.selectedOrganisationsStr) || this.selectedOrganisationsStr == '[]') {
            return;
        }
        String[] OrganisationsIds = this.selectedOrganisationsStr.remove('[').remove(']').remove(' ').split(',');
        for(String s : OrganisationsIds) {
            if(!String.isBlank(s)) {
                System.debug(' org= '+s );
                rep.AccountID__c=s;
            }
        }
        this.selectedOrganisationsStr = null;
    }

public List<Account> getSelectedOrganisations() {
        Account[] Organisations = [SELECT Name FROM Account WHERE Id IN :this.selectedOrganisationsIds ORDER BY Name];
        return Organisations;
    }

public PageReference save(){
        
        try {
            insert rep;
        }catch (Exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '"Something went wrong !"'));
        }
        PageReference pageRef = Page.CallsHospList;
        pageRef.setRedirect(true);
        return pageRef;
    }
    
 public void ChangeField()
 {
 }   
    
 public PageReference cancel() {
        PageReference pageRef = Page.CallsHospList;
        pageRef.setRedirect(true);
        return pageRef;        
    }
    
}
So, when i click on field rep.AccountID__c the page named AccountsListforHosp open. Then I  select organisation name and page AccountsListforHosp  closed. After that I waiting page CallsHospInsert is updating by using method applyFilterByOrganisationsIns(), but method doesn't work.
That code of page AccountsListforHosp :
<apex:column rendered="{!Not(ListCalls)}">
                            <apex:commandLink action="{!updateSelectedAccountsSet}"  onclick="updateSelectedAccountsIns(); return false;"  value="{!res.record.Name}" />
                        </apex:column>
.......


<apex:actionfunction name="updateSelectedAccountsIns" action="{!updateSelectedAccountsSet}" oncomplete="addSelectedOrganisationsIns();" rerender="pnlSearchResults"> 
                                                <apex:param name="bParam" value="{!record.id}" assignTo="{!ArecordId}"/>
                    </apex:actionfunction>
                    <script type="text/javascript">
                        function addSelectedOrganisations() {
                            var searchContext = "{!searchContext}";
                            var parentWindow = top.parent.window;
                            if(searchContext === "brick") {
                                parentWindow.opener.addSelectedBricks("{!selectedRecords}");
                            } else { if (searchContext === "pharma_chain") {
                                parentWindow.opener.addSelectedOrganisations("{!selectedRecords}");}
                                else {parentWindow.opener.addSelectedParents("{!selectedRecords}");}
                            } 
                            parentWindow.close();
                        }
                         function addSelectedOrganisationsIns() {
                            var searchContext = "{!searchContext}";                            
                            var parentWindow = top.parent.window;                            
                            if (searchContext === "pharma_chain") {
                                parentWindow.opener.addSelectedOrganisationsIns("{!selectedRecords}");}                               
                            parentWindow.close();
                        }
                    </script>
And I caused this page with context noList ( Not(ListCalls) = true).
So, why method applyFilterByOrganisationsIns() doesn't starting?
P.S.
Please sorry for my bad English.


 
I'm going to override the standard controller for my object .  Do insertion a new record  ( record in base still there is no).  Page

<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospEdit" >
<apex:outputPanel rendered="{!IF($CurrentPage.parameters.theType = 'app', false, true)}" >
            <apex:pageBlockSection columns="2">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="{!$ObjectType.CallReportHosp__c.fields.AccountID__c.label}" for="organisation"/>
                    <apex:inputField value="{!CallReportHosp__c.AccountID__c}" id="organisation" >
                         <apex:actionSupport event="onchange"  reRender="pblock" status="status" action="{!SelectService}" />
                    </apex:inputField>
                </apex:pageBlockSectionItem>
Controller
public with sharing class CtrlCallHospEdit {


public Boolean booleanValue {get;set;}
pablic CallReportHosp__c rep;

 public CtrlCallHospEdit(ApexPages.StandardController controller)
    {
       this.booleanValue=false;
       rep = (CallReportHosp__c)controller.getRecord();

       System.debug(' bool= '+booleanValue);
       SelectService();      
    }
 
 
    
public void SelectService(){
system.debug('selectservice=');
        if(rep.AccountID__c !=null)
           { booleanValue = true; System.debug('acc= '+rep.AccountID__c); }
           else {booleanValue=false; System.debug('acc= '+rep.AccountID__c); }
    }     
}
I changed value in field AccountID__c in page, but i don't have its value in controller ( i have rep.AccountID__c = null).
I remind you that I need to get the value of the field BEFORE saving the record in the database (before the call Save).
Tell me what I'm doing wrong
 
I'm going to override the standard controller for my object .  Do insertion a new record  ( record in base still there is no).  Page

<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospEdit" >
<apex:outputPanel rendered="{!IF($CurrentPage.parameters.theType = 'app', false, true)}" >
            <apex:pageBlockSection columns="2">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="{!$ObjectType.CallReportHosp__c.fields.AccountID__c.label}" for="organisation"/>
                    <apex:inputField value="{!CallReportHosp__c.AccountID__c}" id="organisation" >
                         <apex:actionSupport event="onchange"  reRender="pblock" status="status" action="{!SelectService}" />
                    </apex:inputField>
                </apex:pageBlockSectionItem>
Controller
public with sharing class CtrlCallHospEdit {


public Boolean booleanValue {get;set;}
pablic CallReportHosp__c rep;

 public CtrlCallHospEdit(ApexPages.StandardController controller)
    {
       this.booleanValue=false;
       rep = (CallReportHosp__c)controller.getRecord();

       System.debug(' bool= '+booleanValue);
       SelectService();      
    }
 
 
    
public void SelectService(){
system.debug('selectservice=');
        if(rep.AccountID__c !=null)
           { booleanValue = true; System.debug('acc= '+rep.AccountID__c); }
           else {booleanValue=false; System.debug('acc= '+rep.AccountID__c); }
    }     
}
I changed value in field AccountID__c in page, but i don't have its value in controller ( i have rep.AccountID__c = null).
I remind you that I need to get the value of the field BEFORE saving the record in the database (before the call Save).
Tell me what I'm doing wrong
 
I follwoed the instructions found here:  http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/  which are pretty straight forward to try to override the standard lookup functionality.  I implemented this within my apex component and it is never getting inside the function openLookup that I have defined within my component.  Is there anything that would need ot be done differently when called from a component vs a VF page?