• Rahul Khilwani
  • NEWBIE
  • 70 Points
  • Member since 2014
  • Senior Associate
  • Axtria India Pvt. Ltd.


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 16
    Replies
Hello,

I am working with javascript. I need to select A field. My javascript is out side the blocks. so With $component  id have to usw hierarchical id (or Dom tree id). structure like {!component.mypage.mypageblock.myfield}. 
I Can't use something {!component.mypage.mypageblock.myfield} as only id fixed is myfield.
 what is the alternative how can i select field directly?
Hi All,
I want to add JSENCODE to my visualforce page where I have a javascript function and it is used in one of my statements in the code. Below is my code:
<a style="padding-left:5px;color:black;" id="link" href="javascript:void(0);" onclick = "changeStage('{!Values.Stage_Value__c}');">{!Values.Stage_Value__c}</a>
And the javascript function is: 
function changeStage(changeStageName) {
        
        stagename(changeStageName);
     }
Can Somebody help me in solving this!! Any help or suggestion is appreciable.
Thanks in advnce

 
Hello,

I am working with javascript. I need to select A field. My javascript is out side the blocks. so With $component  id have to usw hierarchical id (or Dom tree id). structure like {!component.mypage.mypageblock.myfield}. 
I Can't use something {!component.mypage.mypageblock.myfield} as only id fixed is myfield.
 what is the alternative how can i select field directly?

Hey all,

I'm building a wrapper class and the argument need to include a record and its share records. via e.g.

Custom_Object__c c = [select id, Contact__c, Status__c, (select id, rowCause, ParentId, userOrGroupId, AccessLevel from Shares) from Custom_Object__c  where Contact__c IN :ContactIds]

ExampleWrapper e = new ExampleWrapper(c);

I'd like to throw a custom exception if the passed in record doesn't have the share records included. Is there a way to do that? There may be times where there are genuinely no Shares, so I can't just check for zero shares, I really need to check whether they were included in the SOQL query.

Additionally (just to make it more difficult), I can't enforce the SOQL by putting it in the Wrapper class. I'd like to avoid SOQL in the wrapper class, so it's bulk compatible.

I know that if a SOQL doesn't include a field that is needed later on, that produces an error, but the same thing doesn't appear to happen with child relationships. Does anybody know how?

Andy

This is my current setup:
- I have a managed package that creates a custom field on the User object (User.MyApp__MyApp_API_token__c). It stores the users API token to connect to an external system via REST.
- The Apex class I have written requests the API key from the current user, and if it does not exist, it contacts the external system to retrieve one and save it to the custom field listed above. 

This workflow works fine in my developer edition account, but when I install the app in my colleague's developer edition account, the custom field is not appearing in the UI (user profile page or user detail page) and the Apex code is not saving the retrieved API token to the User object. What is peculiar is that the custom field is created when the managed app is installed, and I can see it when I access the User object through Setup --> Object Manager.

Any help or suggestions would be much appreciated.

--Bhavik
Hi
I have writen a trigger for two custom objects like registration and rumexpenses and i given lookup relation between these two objects i have an requirement when the record created in registration object with field rum name then automatically new record is created in rumexpenses object also. to achive this i have writen a after insert trigger but it not working it fires error. please check my code

Apex class:

public class Rumapex {
    public String rumname{set;get;}
    public String password{set;get;}
    public String email{set;get;}
    public list<Registartion__c> result{set;get;}
    public pagereference register(){
        pageReference p=new pageReference('/apex/RegistrationPage_Rum');
        return p;
    }
    public pageReference go(){
        pageReference p=new pageReference('/apex/Home');
        return p;
    }
    public PageReference login(){
        pageReference p=new pageReference('/apex/loginpage_Rum');
        return p;
    }
    public pageReference forgetpwd(){
        pageReference p=new pageReference('/apex/forgetpwd_Rum');
        return p;
        }
    public pageReference search(){
        Integer regcount=[select count() from Registartion__c where Rum_Name__c=:rumname];
            if(regcount==0){
               return create(); 
            }else{
              Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.WARNING,'Records are already existed'));
                return null;
            }
        }
   public PageReference create(){
        Registartion__c r=new Registartion__c();
        r.Rum_Name__c=rumname;
        r.Password__c=password;
       r.E_Mail__c=email;
        insert r;
       PageReference p=new PageReference('/apex/loginpage_Rum');
       ApexPages.Message msg=new ApexPages.message(ApexPages.Severity.CONFIRM,'Registration completed successfully');
       ApexPages.addMessage(msg);
        return p;
    }
    public void clear(){
        rumname=null;
        password=null;
       email=null;
    }
    public pageReference getdetails(){
       result=[select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rumname and Password__c=:password];
          if(result.size()>0){
           return go(); 
        }
        else{
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please Enter valid credentials'));
            return null;
        }
        }
    public void getpwd(){
        result=[select Rum_Name__c,Password__c,E_Mail__c from Registartion__c where E_Mail__c=:email];
        if(result.size()>0){
            rumname=result[0].Rum_Name__c;
            password=result[0].Password__c;
            email=result[0].E_Mail__c;
        }    
        else{
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Enter registred E-mail'));   
        }
      } 
    }

Trigger:

trigger RumnameTrigger on Registartion__c (after insert) {
    list<Rum_Expenses__c>exp=new list<Rum_Expenses__c>();
    for(Registartion__c reg:Trigger.new){
        Rum_Expenses__c ru=new Rum_Expenses__c();
        ru.Id=reg.Id;
        ru.Rum_Name__c=reg.Rum_Name__c;
        exp.add(ru);
     }
    insert exp;
}

when records are inserted through vf page it shoes error like this
User-added image
When records are inserted in sobject
User-added image

Thanks in Advance
I have created a visualforce page with two charts on the same page.  What I would like to do is be able to use the "var options" on each chart.  The representation options would be different for each.  I would like to have a different green area. for each.   I have also included my code here as well to try to figure this out.  

User-added image
 var data = google.visualization.arrayToDataTable([
          ['Label', 'Value'],
          ['Open Rate', {!campaign.Avg_Open_Rate__c}],
          ['Click Rate', {!campaign.Avg_Click_Rate__c}],
         
     
        
        ]);

        var options = {
          
          width: 400, height: 300,
          greenFrom: -6, greenTo: 6,
          min: -50,
          max: 50,
          majorTicks: [-40, -30, -20, -10, 0, 10, 20, 30, 40]
        };

        var chart = new google.visualization.Gauge(document.getElementById('chart_div'));

        chart.draw(data, options);

        setInterval(function() {
          data.setValue({!campaign.Avg_Open_Rate__c});
          chart.draw(data, options);
        }, 13000);
     
I am having issues getting all of my code covered or at least 75% of it.

I have tested my class manually and everything seems to work properly, but when I run my test class it does not cover the code I expected it to.  I am creating a contact con1 and retrieving the Individual_Auto_ID__c is an auto generated unique custom field.  When passed to the function it should find the newly created con and return exactly 1 result since I just created that contact.  This works perfect when testing manually but not when the Test function runs it.  Am I missing something?

Test Class:
@isTest
private class myController_Test {

    static testMethod void myTestController_Test() {
        //----------------------------------------
        //TEST CLASS FOR myController
        //----------------------------------------
    
        Contact con1 = new Contact(firstname='Test', lastname='Test', email='test@aei.org');
        
        insert con1;

        string con_id = con1.Individual_Auto_ID__c;
        string field_name = 'test';
         
        //unsubscribe - good and bad values
        boolean valid = myController.unsubscribe(con_id, field_name);
}

My Controller:
global with sharing class myController {
    public static List<Contact> contacts {get; set;}

    @RemoteAction    
    global static boolean unsubscribe(string user_id, string newsletterField) {
        Boolean valid = true;
         
        contacts = [SELECT FirstName
        FROM Contact
        WHERE Individual_Auto_ID__c = :user_id];
        
        if(contacts.size() < 1) {
            valid = false;
        } else {
            //This is not being covered 
        }
            
        return valid;
    }
}

 
Hi All,
I want to add JSENCODE to my visualforce page where I have a javascript function and it is used in one of my statements in the code. Below is my code:
<a style="padding-left:5px;color:black;" id="link" href="javascript:void(0);" onclick = "changeStage('{!Values.Stage_Value__c}');">{!Values.Stage_Value__c}</a>
And the javascript function is: 
function changeStage(changeStageName) {
        
        stagename(changeStageName);
     }
Can Somebody help me in solving this!! Any help or suggestion is appreciable.
Thanks in advnce

 
Hello All,

I am new to visualforce programming and here I am stuck with something that looked pretty simple to me earlier(Well its not now obviously).
I am trying to use the inputs entered in two inputfields in my visualforce page, do some string operations(trim)/Concatenate, and use the resulting string as a value in a third inputbox. The auto-population of the field will happen when the third textbox gets the focus.

I thought this would be pretty simple to capture the values using javascript but unfortunatey, could not get away with a solution.

Appreciate any pointers towards a solution.

Regards,
Sudip
Hi,

I have a visulaforce page that displays a table of records from a related list.
I have used the rendered attribute to only display certain records (rows)
This all works fine however the column headers are not showing, Would anybody be able to see why?
<apex:pageBlock title="Delegates">
    <apex:dataTable value="{!Courses__c.Delegates__r}" var="item" border="1" cellpadding="5" cellspacing="1">
       <apex:column style="width:20%" rendered="{!item.Status__c == 'Booked'}">
          <apex:facet name="header">Name</apex:facet>
                {!item.Name}
       </apex:column>
       <apex:column style="width:30%" rendered="{!item.Status__c == 'Booked'}">
          <apex:facet name="header">Signature</apex:facet>
       </apex:column>
       <apex:column style="width:20%" rendered="{!item.Status__c == 'Booked'}">
          <apex:facet name="header">Company Name</apex:facet>
                {!item.Contact__r.Account.Name}
       </apex:column>       
       <apex:column style="width:30%" rendered="{!item.Status__c == 'Booked'}">
          <apex:facet name="header">Email Address</apex:facet>
       </apex:column>       
       <apex:column rendered="{!item.Status__c == 'Booked'}">
          <apex:facet name="header">Exam Board</apex:facet>
                {!item.Exam_Board__c}
       </apex:column>
        <apex:column rendered="{!item.Status__c == 'Booked'}">
          <apex:facet name="header">Number of Days</apex:facet>
                <table border="1" cellpadding="5" cellspacing="0">
                <td>1</td>
                <td>2</td>
                <td>3</td>
                <td>4</td>
                <td>5</td>
                </table>
       </apex:column>
    </apex:dataTable>
    </apex:pageBlock>

Thanks
Joe
 
Hi all,
I have a requirement to display all the accounts present on a vf page along with the checkboxes beside them so that user can select any no of accounts on the page.What is the code for this?

Please help.

Thanks inadvance.
Hi Guys,
I am using one custom button in detail page. When click that one vf page will open and in that i am opening another popup. In first popup, after clicking the save the page is redirecting to detail page in popup itself. But i want popup should be closed and redirect to detail page. Pls help me out very urgent. I used everything window.close() and location.href but its not working.
 
hi everyone
             Actually i have an issue like i have two objects 1)position(master),and 2)job applications(detail).I have fileds in both the objects as

position-------------status(pick list data type(open,new,closed))
job applications-----------------status(picklist(open,new,closed))
                      ------------------ position(master detail relationship field)

             now i have need to write a trigger on job apllication object such that  whenever the job applications status has been changed to closed,the trigger should chage the status of position to closed automatically.i have written the code as following ,but it is showing the following error

code    
trigger jobApplicationAssociatePositionClose on Job_Application__c (after insert,after update) {
    for(Job_Application__c jobApp:trigger.new){
   if(jobApp.Status__c=='closed')
      jobApp.position__c.Status__c='closed';
}
}      

error:invalid foreign key relationship :job_application__c.position__c

        anybody  please help me on this issue