• Roshan Tamrakar
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 8
    Replies
Hi Experts,

I have a custom object SP__c having a checkbox field named 'Apply_To_All__c' and a text field P1__c. The standard object 'Account' has a lookup field to this custom object (Account.SP__c). Only SPs that have 'Apply_To_All' checked can be set as a lookup SP for an Account.

Account
Name        SP__c
Sonixx        Standard
Beltronix     Custom (This is invalid as 'Apply_To_All__c' is false for Custom SP)
Airtel           Standard

SP__c
Name           Apply_To_All__c        P1__c
Standard      True                           Critical
Custom        False                          Normal

To achieve this, I wrote the following validation rule in Account:

Code:
VLOOKUP($ObjectType.ENT_2__SP__c.Fields.ENT_2__Apply_To_All__c, $ObjectType.ENT_2__SP__c.Fields.Name, 'True')=True

(ENT__2 is the namespace prefix)

However, this validation is allowing me to save no matter the lookup SP has 'Apply_To_All__c' checked or unchecked.

I even could not validate for attaching only SPs that have P1__c='Critical' with the following rule:

Code:
VLOOKUP($ObjectType.ENT_2__SP__c.Fields.ENT_2__P1__c, $ObjectType.ENT_2__SP__c.Fields.Name, 'Critical')='Critical'

What is wrong in my validation rule?

Thanks,
-Roshan
Hi experts,

I wanted to have a many-to-many relationship between Asset and a custom object SP__c. For that I created a custom object Program_Asset__c. I added two lookup fields in it, one related to Asset and other related to SP__c. When I checked it in Apex Explorer, the child relationship name in Asset is some odd number and not in readable form (should have been Program_Assets__r). The highlighted item is the one.



Because of this my deployment fails in other org because it is used in my soql query and new package installation creates another random name for the relationship.

Code:
Select Id, (Select SP__c, SP__r.Name From a.R00N30000002NWqzEAG) From Asset a Where a.Id ='02i30000001DcJa'
 
What went wrong?

Also, How do I know from apex class that I am currently in 'Desktop' page (console tab): https://na1.salesforce.com/ui/desktop/DesktopPage

Please help me.

Thanks,
-Roshan
HI All,

I have created a VF Page and added that inside Account Detail page under a separete section.

The properties of the section are:
Name: Contact List
Column: 1
Tab Order: Top-Down
Show Section Heading On Detail Page: checked
Show Section Heading On Edit Page: checked

The properties of VF Page placed inside the section are:
Width: 100%
Height: 200px
Show Scrollbars: checked
Show label: unchecked

The output is as below:




The VF Page source code:
Code:
<apex:page standardController="Account">
<apex:pageBlock >
  {!Account.Name}
  <apex:pageBlockSection >  
  <apex:pageBlockTable value="{!Account.Contacts}" var="cnt">
    <apex:column value="{!cnt.Name}"/>
  </apex:pageBlockTable>
  </apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

My problem is:
I don't want the white space below the page that is being displayed in above picture. If the list is too short the white space will be more. I want the page to cover the whole section.
What tag, attributes or settings help me to avoid the white section and cover the whole section.
Please help.

Thanks,
-Roshan



Hi Experts,

I have a field (first_response__c) of type datetime and I want to find the difference between the value in this field and current date time (system.now()).

Code:
System.debug(first_response__c - system.now()); // first_response__c is greater than system.now() here.

It throws me error like:
"Date/time arithmetic expressions must use Integer and Double arguments"

I also tried to use DATEVALUE() function as found a remedy in other posts, but it does not recognize this method. It returns error like:
"Method does not exist or incorrect signature: DATEVALUE(Datetime)"

I am working in DE org from Eclipse IDE.

What am I doing wrong? Is there any function that differenciates two datetime value and returns me a value in hours?

Thank you,

-Roshan

 

Hi Experts,
 
Though this question has already been asked by other, no definite answer has been made. Please help me.
 
To be straight, I have the following code:
 
Code:
<apex:page showHeader="false" controller="VehicleListControllerClass_2">
 <apex:form>
  <apex:pageBlock title="Vehicle List for {!personname}">
   <apex:pageBlockList value="{!vehicleList}" var="v">
    <apex:column value="{!v.VehicleName}"/>
    <apex:column value="{!v.PersonVehicle.Vehicle__r.Name}"/>
    <apex:column headerValue="Vehicle">
     <apex:outputLink value="/{!v.PersonVehicle.Vehicle__c}" target="_top">{!v.PersonVehicle.Vehicle__r.Name}</apex:outputLink>
    </apex:column>
    <apex:column>
     <apex:commandLink value="Click This Link" action="{!dosomething}" >
      <apex:param name="myparm" value="Link abcd"/>
     </apex:commandLink>
    </apex:column>
    <apex:column>
    <apex:commandButton value="Click This Button" action="{!dosomething}" styleClass="btn">
     <apex:param assignTo="{!MP}" name="myparm1" value="abcd"/>
     <apex:param name="myparm2" value="Button abcd"/>
    </apex:commandButton>
    </apex:column>
   </apex:pageBlockList>
  </apex:pageBlock>
 </apex:form>
</apex:page>


public class VehicleListControllerClass_2{

 public String getPersonName(){
  ID pId = System.currentPageReference().getParameters().get('id');
  String name = [Select Name from Person__c where id=:pId].Name;
  return name;
 }

 public class Vehicles{
  Person_Vehicle__c pv;
  //Constructor
  public Vehicles(Person_Vehicle__c pvin) {pv = pvin;}

  public Person_Vehicle__c getPersonVehicle() {return pv;}

  public String getVehicleName(){

   if(pv.Vehicle__r.Name == 'Maruti 800') return 'It is Maruti 800 yar';
   else return pv.Vehicle__r.Name;
  }

  Integer curYear = system.now().year();
  return (curYear - (Integer)pv.Purchase_Year__c);
  }
 }

 List<Vehicles> pvlist = new List<Vehicles>();

 public List<Vehicles> getVehicleList(){
  ID pId = System.currentPageReference().getParameters().get('id');

  pvlist.clear();
  for(Person_Vehicle__c pvv : [Select p.Person__r.Name, p.Vehicle__c,
  p.Vehicle__r.Name, p.Purchase_Year__c from Person_Vehicle__c p where p.Person__c=:pId]){
   pvlist.add(new Vehicles(pvv));
  }

  return pvlist;
 }

 String p;
 public String getMP(){
  return p;
 }

 public void setMP(String s){
  p=s;
 }
 
 public PageReference dosomething(){
  String s = System.CurrentPageReference().getParameters().get('myparm');
  String s1 = System.CurrentPageReference().getParameters().get('myparm1');
  String s2 = System.CurrentPageReference().getParameters().get('myparm2');
  System.debug(s);
  System.debug(s1);
  System.debug(s2);
  return null;
 }

}

When I click on the link 'Click This Link', String 's' returns 'Link abcd' which is correct.
 
But when I click on the link 'Click This Button', both Strings 's1' and 's2' returns null.
 
How could I get the param value in controller in case of 'commandButton'?
Please note that I Must use commandButton and I need to pass more than one parameters.
 
Also, I would like to be able to create a new Case (in another visualforce page) with few default values by clicking a commandButton. The page should open as if user clicked on 'New' button and ready to Save. Please note that the page will not be associated with 'Case' controller.
 
How could I achieve this functionality?
 
Thanks,
-Roshan

Hi Experts,

 

I have 3 custom objects:

      Person__c

      Vehicle__c

      Person_Vehicle__c

 

The Person_Vehicle__c is child of Person and it has lookup relationship with Vehicle. 

 

I created a VisualForce page and placed it in person tab. The VisualForce page lists all child records for the person whose data is being displayed. The display in person page is something like:

 

Person Name             Vehicle

Tirtha                           Maruti 800

Tirtha                           Zen

 

The ‘Vehicle’ items are commandLink so that if I click ‘Maruti 800’, the page redirects to ‘Maruti 800’ detail page.

 

The following is my page and controller code:

 

Code:
public class VehicleListControllerClass{

 public String getPersonName(){
  ID pId = System.currentPageReference().getParameters().get('id');
  String name = [Select Name from Person__c where id=:pId].Name;
  return name;
 }

 public List<Person_Vehicle__c> getVehicleList(){
  ID pId = System.currentPageReference().getParameters().get('id');
  List<Person_Vehicle__c> data = new List<Person_Vehicle__c>(
   [Select p.Person__r.Name, p.Vehicle__c, p.Vehicle__r.Name from Person_Vehicle__c p where p.Person__c=:pId]);
   return data;
 }

 public PageReference OpenVehicle(){
  PageReference page = System.CurrentPageReference();
  ID vId = page.getParameters().get('vehicleId');
  return new PageReference('/'+vId);
 }
}

<apex:page controller="VehicleListControllerClass">
 <apex:form>
  <apex:pageBlock title="Vehicle List for {!personname}">
   <apex:pageBlockList value="{!vehicleList}" var="v">
    <apex:column value="{!v.Person__r.Name}"/>
    <apex:column>
     <apex:commandLink value="{!v.Vehicle__r.Name}" action="{!OpenVehicle}">
      <apex:param name="vehicleId" value="{!v.Vehicle__c}"/>
     </apex:commandLink>
    </apex:column>
   </apex:pageBlockList>
  </apex:pageBlock>
 </apex:form>
</apex:page>


 

The first issue:

When I click on any vehicle item, it works nicely and respective vehicle detail is displayed on the page. The url becomes:

https://na2.salesforce.com/a0340000004dX5AAAU?inline=1

 

But, if I try to do the same with ‘right-click-->Open link in new tab’, it doesn’t work and instead displays error ‘URL No Longer Exists’. The url, in this case, becomes:

https://na2.salesforce.com/servlet/servlet.Integration?lid=0664000000000JY&ic=1#

 

The second issue:

The second problem is that I do not see the column header for ‘vehicle’ (second column). I also tried to use facet, but it also didn’t work:

Code:
<apex:column>
 <apex:facet name="header">Vehicle</apex:facet>
 <apex:commandLink value="{!v.Vehicle__r.Name}" action="{!OpenVehiclePage}">
  <apex:param name="vehicleId" value="{!v.Vehicle__c}"/>
 </apex:commandLink>
</apex:column>


 
Please suggest.

Thanks,

-Roshan

Hello experts,
 
I want to know the way of using condition in visualforce page. I have a custom object 'Person__c' having few fields. Two of them are:
Name, Active(Checkbox), Birthday, Age(Numberic)
 
What I want to do is list values in these fields in visualforce page. While displaying, I want to display:
 'Minor' if Age<16, otherwise 'Adult'
 
I want to be able to do this in any of the following 3 ways:
 
1. By using If clause in apex page
2. By passing 'Age' as a parameter to my extended controller
3. And using case (or similar) in SOQL
 
Below is my code:
 
Code:
<apex:page standardController="Person__c" extensions="PersonExtension">
 <apex:form>
  <apex:pageblock title="My Persons Infos">
   <apex:pageblockList value="{!PersonList}" var="p">
    <apex:column value="{!p.Name}"/>
    <apex:column value="{!p.Active__c}"/>
    <apex:column value="{!p.Birthday__c}"/>
    <apex:column value="{!p.Age__c}"/>
    <apex:column value="{!anystring}"/>
    <apex:column value="{!IF((p.Age__c>16),'Adult','Minor')}"/>
   </apex:pageblockList>
  </apex:pageblock>
 </apex:form>
</apex:page>


public class PersonExtension{

  private final Person__c person;

  public PersonExtension(ApexPages.StandardController stdController){
    this.person= (Person__c)stdController.getRecord();
  }

  public Person__c[] getPersonList(){
    return [Select p.Id, p.Name, p.Age__c, Birthday__c, p.Active__c from Person__c p];
  }

  public String getAnyString(){
    return 'Anything';
  }
}

The error I get is: Error: Syntax error. Missing ')'
 
If I change the if condition to: <apex:column value="{!IF((p.Age__c<16),'Minor','Adult')}"/>
The error will be: Error: Syntax error. Found 'lt'
 
Even a simple clause is not working:

<apex:column value="{!IF(CONTAINS({!anystring}, 'Anything'),True, False)}"/>
 
1. What is wrong in my code? Can I use IF condition in this way?
2. Can I pass a parameter (Age in above case) to my controller and return a string based on parameter supplied to it? If so, how?
3. Can I use case...when clause (or similar like in sql) in my SOQL? If so, how can I do so?
 
Thanks