• Cristian Trif
  • NEWBIE
  • 55 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 22
    Replies

Hi,

I have the following code:
 

//Get Language values
        Schema.DescribeSObjectResult contactObjResult = Contact.sObjectType.getDescribe();
        Schema.DescribeFieldResult languageFieldResult = Schema.SObjectType.Contact.fields.Language__c;
        languageFieldResult = languageFieldResult.getSObjectField().getDescribe();

        List <Schema.PicklistEntry> lstLanguageValues = languageFieldResult.getPickListValues();
        this.Languages = new List<SelectOption>();
        for (Schema.PicklistEntry entry : lstLanguageValues) {
            this.Languages.add(new SelectOption(entry.getValue(), entry.getLabel()));
            System.debug('AllPicklistValues--'+this.Languages);
        }

This code only is fetching all the values from the Language__c field. The requirement is to fetch the value of the User Language and set it as default, so for example if my User language is 'English' in my list should be the value, by default english. The  thing is we have translates and I'm not sure how to fetch the value, translate and then make it as default.

So I have the inputField:

<apex:inputField id="timeLimiter" value="{!pageForm.currentContract.ContractingVehicleRegistrationDate__c}" rendered="{!NOT(contractFieldReadOnlyRegistrationDate)}"/>


This is my inputField with the id='timeLimiter'  and I want to use my function only for this field.

My function is:

<script type="text/javascript">
	$j(document).ready(function () {
	    var today = new Date();
        var startYear=today.getFullYear()-19;
        var endYear=today.getFullYear();
        var optionsString='';
         if(startYear<endYear){
           for(var startCounter = startYear;startCounter<endYear; startCounter++){
			 optionsString += "<option value=\""+startCounter+"\">"+startCounter+"</option>";
	       }
		  $j('#calYearPicker').html(optionsString);}
    });
	</script>

The thing is I want my function to only apply to this field because in my form I have multiple fields of the same type(Date) and this function applies to all my fields(which I don't want ).

How can I pass my id from my field to my function?

Hi,

I need to create a custom button on Opportunity Layout then when this button is pressed I need to create a new Quote and redirect to a VF page that I will create afterward. Someone can help me with this, please? I wrote some code but I don't know if it's good or bad.

Just need to create a new Quote on the current Opportunity which I'm in.

 

public class MyController {

    public String currentRecordId {get;set;}
    public String parameterValue {get;set;}
    public Opportunity opp {get;set;}
    
    public MyController(ApexPages.StandardController controller){
        currentRecordId = ApexPages.currentPage().getparameters().get('id');
        opp = [Select id From Opportunity where id =: currentRecordId];
		parameterValue = ApexPages.currentPage().getparameters().get('nameParam');
        
        Quote qo = new Quote();
        insert qo;
    }
    
}

Hello,
So the requirement is to reduce the button clicks so I need to create a button on the Opportunity Layout and when pressed should automatically create a Quote and a Contract related to the that opportunity and also redirect to a visualforce page that contains the Price, Model and the Brand of a vehicle. We have an custom object called, Vehicle so all the fields are in this object.
This is the page layout of Opportunities of where i want my button to be.
User-added image

and also the related lists where are Quotes and Contracts.

User-added image

Hi, I want to create a custom button that creates a new task in my visualforce page. It's identical with this 'New' Button from Home Object - My Tasks.

User-added image

I implemented my button in VF like this:
 
<apex:pageBlockButtons location="top">
 <apex:commandLink value="New Task"   styleClass="btn" style = "text-decoration:none" />
</apex:pageBlockButtons>

And now the only thing to do is when i press this New Task button to redirect me to this page. Which is for creating New Task basically.

User-added image

Hi. I want to create a selectlist exactly like this.

User-added image

I created the logic for this but I really don't know how to make it with Visualforce.

Controller:

 

public class TaskController {
    public List<Task> lstTasksForUser {get;set;}
    public TaskController(){
        lstTasksForUser = [Select id, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task WHERE Status!= 'Completed' AND OwnerId =: UserInfo.getUserId()];
    }
    
    public List<Task> tasksToday {get;set;}
    public List<Task> getTodayTasks(){
        tasksToday = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = TODAY AND Status!= 'Completed'];
        return tasksToday;
    }
    
    public List<Task> tasksThisMonth {get;set;}
    public List<Task> getThisMonthTasks(){
        tasksThisMonth = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = THIS_MONTH AND Status!= 'Completed'];
        return tasksThisMonth;
    }
    
    public List<Task> tasksCloseTomorow {get;set;}
    public List<Task> getTomorowCloseTasks(){
        tasksCloseTomorow = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = TOMORROW AND Status!= 'Completed'];
        return tasksCloseTomorow;
    }
    
    public List<Task> tasksOverdue {get;set;}
    public List<Task> getOverdueTasks(){
        tasksOverdue = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate < TODAY AND Status!= 'Completed' ];
        return tasksOverdue;
    }
    
    
}

This is my VF page and I'm stuck on this selectList part. I want when I select Today in the selectListOptions my pageBlockTable to change and fetch the records for Today.

 

<apex:page controller="TaskController" tabStyle="Task">
    <apex:form >
        <apex:pageBlock title="My Tasks" id="tasks_list">
            <apex:pageBlockTable value="{!lstTasksForUser}" var="tsk">
                <apex:selectList size="5" onchange>
                	<apex:selectOptions value="{!TodayTasks}" >
                        
                    </apex:selectOptions>
                </apex:selectList>
                <apex:column headerValue="Complete" >
                    <a href="https://eu12.salesforce.com/{!tsk.id}/e?close=1&retURL=%2Fhome%2Fhome.jsp" rendered="{!if(tsk.status!='Completed',true,false)}" > 
                        X 
                    </a>
                </apex:column>
                <apex:column value="{!tsk.ActivityDate}"/>
                <apex:column value="{!tsk.Status}"/>
                <apex:column value="{!tsk.Subject}"/>
                <apex:column value="{!tsk.WhoId}"/>
                <apex:column value="{!tsk.WhatId}"/>
                <apex:column value="{!tsk.CompanyName__c}"/>
                <apex:column value="{!tsk.AccountId}"/>
            </apex:pageBlockTable>
        </apex:pageBlock> 
    </apex:form>
</apex:page>
 

 

Hi,

Are there any examples on how to re-create these filters in APEX/Visualforce(Picture above with the filters)? I want to create my custom VF component and I want to add filters on it.

User-added image
 

I need to update/change my Customer Type picklist field with the value of Detail Customer before I insert the Account. So the process is like this:
1) I press the new button for creating new account
2) Those 2 fields appear on the screen
3) When I select Customer Main Type picklist field with the value of Organization the Customer Type default value should be Detail Customer, and it should change instantly before I inserting my account. Remember, these two picklists are dependent and not controlling picklists.

 

I tried to write a trigger but I'm stuck here.. I'm not a programmer so I don't know how to continue this.

trigger ChangeValue on Account (before insert) {
    
    for (Account a : Trigger.new){
        if(a.CustomerMainType__c =='Organization'){
            a.CustomerType__c == 'Detail Customer';
        }
    }
}
I have 2 errors: Variable does not exist: CustomerMainType__c ; Variable does not exist: CustomerType__c.

And the fields should be like this when i select the Organization value.

User-added image

Hello all,

I need to create a formula field, in the Task Object and if it finds a  BusinessAccount behind the contact of the activity, it shows it as a link, if it finds no BusinessAccount then it will be null.

Is there any way to do this with formula field?

It should look something like this:

User-added image
 
Hello, I have a small code snippet here and i really don't know why i have this output:

User-added image
Hi guys, yes I know there is a similar topic to this but my question is a little bit different as I want to know what is the advantages of using the Batchable Interface(with Stateful) over future methods?

So i have my test class which i wrote:

@isTest 
public class Controller2TestClass 
{
   static testMethod void testMethod1() 
   {
        Account acc = new Account();
        showAccount showAcc = new showAccount();
        acc.Name='Test';
        acc.Phone='0644204232';
        showAcc.save();
        
          PageReference pageRef = Page.screen2 ;
          Test.setCurrentPage(pageRef);
       
        String checkIdAccount = ApexPages.currentPage().getParameters().get('id');
       
        System.assertEquals(checkIdAccount, acc.id);
       
     }
}

VF Page:

<apex:page controller="showAccount" >
 <apex:form >
     <apex:pageBlock >
         <apex:pageBlockSection >
             <apex:outputField value="{!account.name}"/>
             <apex:inputField value="{!account.phone}"/>
             <apex:commandButton value="update" action="{!save}"/>
         </apex:pageBlockSection>
     </apex:pageBlock>
 </apex:form>
</apex:page>

And this is the class that I'm testing. I'm only covering 33% and I wonder how can I cover 100%? What I've missed? 
 
public class showAccount 
{
  public Account account{get;set;}
  
    public showAccount()
    {
        Id idAccount = apexpages.currentPage().getParameters().get('id'); 
        account=[Select ID, Name, Phone from Account where id = : idAccount];
    }
    
    public pageReference save(){
        update account;
        PageReference pageRef = new PageReference('/apex/screen3');
        pageRef.getParameters().put('id', account.Id);
        return pageRef;
    }
}

So i created my test class for a controller. And I have coverage 100% but i need to make some assertions using the System.assert(), System.assertEquals(), System.assertNotEquals(), I wrote a simple assert but it's way to simple. 

@isTest 
public class ControllerTestClass 
{
   static testMethod void testMethod1() 
   {

        screen1 sc = new screen1();
        Account acc = sc.getAccount();
        acc.name = 'TestAcc';
        sc.save();
       
        System.assertEquals('TestAcc', acc.name);

          PageReference pageRef = Page.screen1VSF ;
          pageRef.getParameters().put('id',acc.Id);
          Test.setCurrentPage(pageRef);

     }
}


And the class which I'm testing.
public class screen1 
{
  
    public Account myAccount;
    public Account callAccMethod; 
    
    public Account getAccount()
    {
        if(myAccount == null)
        {
            myAccount = new account();
        }
        return myAccount;
    }

    public PageReference save()
    {
       
       callAccMethod = getAccount();
       if(callAccMethod != null)
       {
           insert myAccount;
       }
       
       PageReference pageRef = new PageReference('/apex/screen2');
       pageRef.getParameters().put('id', myAccount.Id);
       return pageRef;
       
    }
    
}
Hello guys, I have the following Visualforce page, name is screen1VSF with a controller.

<apex:page controller="screen1">
   <apex:form >
       <apex:pageBlock >
           <apex:pageBlockSection >
               <apex:inputField value="{!account.name}"/>
               <apex:commandButton value="Save" action="{!save}"/>
           </apex:pageBlockSection>
       </apex:pageBlock>
   </apex:form>
</apex:page>

public class screen1 
{
    public Account myAccount;
    public Account callAccMethod; 
    
    public Account getAccount()
    {
        if(myAccount == null)
        {
            myAccount = new account();
        }
        return myAccount;
    }

    public PageReference save()
    {
       callAccMethod = getAccount();
       if(callAccMethod != null)
       {
           insert myAccount;
       }
       
       PageReference pageRef = new PageReference('/apex/screen2');
       pageRef.getParameters().put('id', myAccount.Id);
       return pageRef;
     }
}

I read some documentation from here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm but I'm still confused how this testing with VF works. Any ideas how can I test my visualforce page and explain how you did it, i want to learn.

So I have the inputField:

<apex:inputField id="timeLimiter" value="{!pageForm.currentContract.ContractingVehicleRegistrationDate__c}" rendered="{!NOT(contractFieldReadOnlyRegistrationDate)}"/>


This is my inputField with the id='timeLimiter'  and I want to use my function only for this field.

My function is:

<script type="text/javascript">
	$j(document).ready(function () {
	    var today = new Date();
        var startYear=today.getFullYear()-19;
        var endYear=today.getFullYear();
        var optionsString='';
         if(startYear<endYear){
           for(var startCounter = startYear;startCounter<endYear; startCounter++){
			 optionsString += "<option value=\""+startCounter+"\">"+startCounter+"</option>";
	       }
		  $j('#calYearPicker').html(optionsString);}
    });
	</script>

The thing is I want my function to only apply to this field because in my form I have multiple fields of the same type(Date) and this function applies to all my fields(which I don't want ).

How can I pass my id from my field to my function?

Hi,

I need to create a custom button on Opportunity Layout then when this button is pressed I need to create a new Quote and redirect to a VF page that I will create afterward. Someone can help me with this, please? I wrote some code but I don't know if it's good or bad.

Just need to create a new Quote on the current Opportunity which I'm in.

 

public class MyController {

    public String currentRecordId {get;set;}
    public String parameterValue {get;set;}
    public Opportunity opp {get;set;}
    
    public MyController(ApexPages.StandardController controller){
        currentRecordId = ApexPages.currentPage().getparameters().get('id');
        opp = [Select id From Opportunity where id =: currentRecordId];
		parameterValue = ApexPages.currentPage().getparameters().get('nameParam');
        
        Quote qo = new Quote();
        insert qo;
    }
    
}

Hello,
So the requirement is to reduce the button clicks so I need to create a button on the Opportunity Layout and when pressed should automatically create a Quote and a Contract related to the that opportunity and also redirect to a visualforce page that contains the Price, Model and the Brand of a vehicle. We have an custom object called, Vehicle so all the fields are in this object.
This is the page layout of Opportunities of where i want my button to be.
User-added image

and also the related lists where are Quotes and Contracts.

User-added image

Hi, I want to create a custom button that creates a new task in my visualforce page. It's identical with this 'New' Button from Home Object - My Tasks.

User-added image

I implemented my button in VF like this:
 
<apex:pageBlockButtons location="top">
 <apex:commandLink value="New Task"   styleClass="btn" style = "text-decoration:none" />
</apex:pageBlockButtons>

And now the only thing to do is when i press this New Task button to redirect me to this page. Which is for creating New Task basically.

User-added image

Hi. I want to create a selectlist exactly like this.

User-added image

I created the logic for this but I really don't know how to make it with Visualforce.

Controller:

 

public class TaskController {
    public List<Task> lstTasksForUser {get;set;}
    public TaskController(){
        lstTasksForUser = [Select id, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task WHERE Status!= 'Completed' AND OwnerId =: UserInfo.getUserId()];
    }
    
    public List<Task> tasksToday {get;set;}
    public List<Task> getTodayTasks(){
        tasksToday = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = TODAY AND Status!= 'Completed'];
        return tasksToday;
    }
    
    public List<Task> tasksThisMonth {get;set;}
    public List<Task> getThisMonthTasks(){
        tasksThisMonth = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = THIS_MONTH AND Status!= 'Completed'];
        return tasksThisMonth;
    }
    
    public List<Task> tasksCloseTomorow {get;set;}
    public List<Task> getTomorowCloseTasks(){
        tasksCloseTomorow = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = TOMORROW AND Status!= 'Completed'];
        return tasksCloseTomorow;
    }
    
    public List<Task> tasksOverdue {get;set;}
    public List<Task> getOverdueTasks(){
        tasksOverdue = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate < TODAY AND Status!= 'Completed' ];
        return tasksOverdue;
    }
    
    
}

This is my VF page and I'm stuck on this selectList part. I want when I select Today in the selectListOptions my pageBlockTable to change and fetch the records for Today.

 

<apex:page controller="TaskController" tabStyle="Task">
    <apex:form >
        <apex:pageBlock title="My Tasks" id="tasks_list">
            <apex:pageBlockTable value="{!lstTasksForUser}" var="tsk">
                <apex:selectList size="5" onchange>
                	<apex:selectOptions value="{!TodayTasks}" >
                        
                    </apex:selectOptions>
                </apex:selectList>
                <apex:column headerValue="Complete" >
                    <a href="https://eu12.salesforce.com/{!tsk.id}/e?close=1&retURL=%2Fhome%2Fhome.jsp" rendered="{!if(tsk.status!='Completed',true,false)}" > 
                        X 
                    </a>
                </apex:column>
                <apex:column value="{!tsk.ActivityDate}"/>
                <apex:column value="{!tsk.Status}"/>
                <apex:column value="{!tsk.Subject}"/>
                <apex:column value="{!tsk.WhoId}"/>
                <apex:column value="{!tsk.WhatId}"/>
                <apex:column value="{!tsk.CompanyName__c}"/>
                <apex:column value="{!tsk.AccountId}"/>
            </apex:pageBlockTable>
        </apex:pageBlock> 
    </apex:form>
</apex:page>
 

 

Hello all,

I need to create a formula field, in the Task Object and if it finds a  BusinessAccount behind the contact of the activity, it shows it as a link, if it finds no BusinessAccount then it will be null.

Is there any way to do this with formula field?

It should look something like this:

User-added image
 

So i have my test class which i wrote:

@isTest 
public class Controller2TestClass 
{
   static testMethod void testMethod1() 
   {
        Account acc = new Account();
        showAccount showAcc = new showAccount();
        acc.Name='Test';
        acc.Phone='0644204232';
        showAcc.save();
        
          PageReference pageRef = Page.screen2 ;
          Test.setCurrentPage(pageRef);
       
        String checkIdAccount = ApexPages.currentPage().getParameters().get('id');
       
        System.assertEquals(checkIdAccount, acc.id);
       
     }
}

VF Page:

<apex:page controller="showAccount" >
 <apex:form >
     <apex:pageBlock >
         <apex:pageBlockSection >
             <apex:outputField value="{!account.name}"/>
             <apex:inputField value="{!account.phone}"/>
             <apex:commandButton value="update" action="{!save}"/>
         </apex:pageBlockSection>
     </apex:pageBlock>
 </apex:form>
</apex:page>

And this is the class that I'm testing. I'm only covering 33% and I wonder how can I cover 100%? What I've missed? 
 
public class showAccount 
{
  public Account account{get;set;}
  
    public showAccount()
    {
        Id idAccount = apexpages.currentPage().getParameters().get('id'); 
        account=[Select ID, Name, Phone from Account where id = : idAccount];
    }
    
    public pageReference save(){
        update account;
        PageReference pageRef = new PageReference('/apex/screen3');
        pageRef.getParameters().put('id', account.Id);
        return pageRef;
    }
}

Hello guys, I have the following Visualforce page, name is screen1VSF with a controller.

<apex:page controller="screen1">
   <apex:form >
       <apex:pageBlock >
           <apex:pageBlockSection >
               <apex:inputField value="{!account.name}"/>
               <apex:commandButton value="Save" action="{!save}"/>
           </apex:pageBlockSection>
       </apex:pageBlock>
   </apex:form>
</apex:page>

public class screen1 
{
    public Account myAccount;
    public Account callAccMethod; 
    
    public Account getAccount()
    {
        if(myAccount == null)
        {
            myAccount = new account();
        }
        return myAccount;
    }

    public PageReference save()
    {
       callAccMethod = getAccount();
       if(callAccMethod != null)
       {
           insert myAccount;
       }
       
       PageReference pageRef = new PageReference('/apex/screen2');
       pageRef.getParameters().put('id', myAccount.Id);
       return pageRef;
     }
}

I read some documentation from here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm but I'm still confused how this testing with VF works. Any ideas how can I test my visualforce page and explain how you did it, i want to learn.