• SFDC RJ
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 1
    Questions
  • 19
    Replies
Hi,

Im using apex:select list in VF page, I'm getting values from controller.

values are like below:
Pen
pencil
chart
book
tools
bags
bucks
charts

In the above list for "Charts" when the user select charts in the picklist, another pick list must be enabled. with values chart1, chart 2, chart 3.

Only when the user select charts second pick list must be enabled.

Please help me.
 
During the SSO login , if the user do not have access to salesforce org then different error message should show using visualforce page. How this can be possible ? Any suggestions would be helpful
Hi,
I am attempting to write a trigger on a custom object but it doesn't seem to being updating - my logic must be flawed in some way. The basic premise is that I have 2 checkbox fields that are updated depending on if a date field ( on the same object) falls within the bounds of either THIS_QUARTER or NEXT_QUARTER.  My code looks like this:
 
trigger SM_Ident_Quarter on ScheduleMirror__c (before insert, before update) {
   
   for(ScheduleMirror__c SchedMirr : Trigger.New){
     
     // if the schedule date is in This Quarter then update the this quarter flag
     for( ScheduleMirror__c s: [SELECT ID, Current_Quarter__c, Next_quarter__c, schedule_date__c  from schedulemirror__c where schedule_date__c = THIS_QUARTER]){
         if(s.id != null)
            s.Current_Quarter__c = TRUE;
     }
     // if the schedule date is in Next Quarter then update the next quarter flag
     for( ScheduleMirror__c sm: [SELECT ID, Current_Quarter__c, Next_quarter__c, schedule_date__c  from schedulemirror__c where schedule_date__c = NEXT_QUARTER]){
         if(sm.id != null)
            sm.Next_quarter__c = TRUE;    
     }
 }
}
I feel this should be quite simple but I think I am missing something fundamental.
Any help would be much appreciated,

Thanks
Dave
 
  • October 18, 2016
  • Like
  • 0
Hi All , 

i am having an 2 fields booked value (number data type) and Booked value percentage (Percentage data type) below is my validation 
"SBLANK (Booked_value__c ) && number_fields__c <= 100" i tried with many its not working bascialy my requeitement is when user is trying to create a record it should enforce the record to enter the data for that i am using isblank for the booked value field then in the booked value percentage field the number should be 0 to 100% can anyone let me know where is it going wrong 
Hi, 

I am trying to create a custom picklist on a custom object, this picklist will hold three names (Person A, Person B, and Person C). This field will only show or only be editable if the creator of the record equals User 1.

How can go about creating this?

Thanks !  
  • October 17, 2016
  • Like
  • 0
I have the following code, the last section has fields to add more licenses to the list.  After Save, I'd like the fields to return to blank or None, or whatever they were before the use filled them in.  Right now, if I F5, it adds another license to the list.  If I try to change the values and click save it errors, and then adds the previous options to the list again.
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" showHeader="false" sidebar="false">
<!------------------------------------------------------------------------------------------------------>
<!--Based on option chosen for License Type, will show description of that license type-->
<apex:pageBlock title="License Definitions">
<apex:form id="theForm">
<apex:pageBlockSection columns="1">
<apex:selectList label="Please select a License Type"  value="{!discountScheduleID}" size="1" >
   <apex:actionSupport event="onchange" action="{!displayDescription}" rerender="description"/>
   <apex:selectOptions value="{!schedules}" />
</apex:selectList> 

<apex:outputText label="Description" id="description" value="{!OutPutString}"/>

<br></br><br></br><br></br><br></br>
</apex:pageBlockSection>
</apex:form>
</apex:pageBlock>
<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="Current Licenses">
<apex:pageBlockSection columns="1">

<apex:pageBlockTable value="{!LicenseList}" var="ln">

<apex:outputLink value="{!ln.Id}">{!ln.Name}</apex:outputLink>

<apex:column value="{!ln.Org__c}" />
<apex:column value="{!ln.Business_Unit__c}" />
<apex:column value="{!ln.BMS_Code__c}" />
<apex:column value="{!ln.License_Type__c}" />
<apex:column value="{!ln.Monthly_Unit_Price__c}" />
<apex:column headerValue="2016 Starting Amount" value="{!ln.X2016_Starting_Amount__c}" />
<apex:column headerValue="2016 Running License Total" value="{!ln.Running_License_Total__c}" />
<apex:column headerValue="2016 Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Cost" value="{!ln.X2016_Cost__c}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>



<!--------------------------------------------------------------------------------------------------------->
<apex:form id="theForm">
<apex:pageBlock id="blockId" title="2017 License Needs">
<apex:pageBlockSection columns="1">

<td>
<apex:outputText style="font-weight:800" label="Total 2017 Annualized Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!tTotal}" />
</apex:outputText>
</td>
<td>
<apex:outputText style="font-weight:800" label="Total 2017 Estimated Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!aTotal}" />
</apex:outputText>
</td>
</apex:pageBlockSection>

<!-------------------------------------------------------------------------------------------------->


<apex:pageBlockTable value="{!LicenseList17}" var="ln17">

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<apex:column >
<apex:commandbutton value="Edit" rerender="blockId" rendered="{!!(tobeEdited == ln17.id)}">
    <apex:param assignTo="{!tobeEdited}" value="{!ln17.id}" name="ittobeedited"/>
</apex:commandbutton>
<apex:commandButton value="Save" action="{!saveRecord}" reRender="blockId" rendered="{!tobeEdited == ln17.id}"/>
</apex:column> 

<apex:column value="{!ln17.Org__c}" />

<apex:column headerValue="BMS Code">
    <!--Allows it to be edited-->
    <apex:inputfield value="{!ln17.BMS_Code__c}" rendered="{!tobeEdited == ln17.id}"/>
    <!--After Save-->
    <apex:outputField value="{!ln17.BMS_Code__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column>    

<apex:column value="{!ln17.License_Type__c}"/>

<apex:column headerValue="BU Agrees to Pay">
    <apex:inputfield value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column> 

<apex:column value="{!ln17.Monthly_Unit_Price__c}" />

<apex:column headerValue="2017 Number Needed">
    <apex:inputfield value="{!ln17.X2017_Total_Needed__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.X2017_Total_Needed__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column>    

<apex:column headerValue="2017 Annualized Cost" value="{!ln17.X2017_Subtotal__c}" />

<apex:column headerValue="Estimated 2017 Cost" value="{!ln17.X2017_Cost__c}"/>


</apex:pageBlockTable>

</apex:pageBlock>

<!------------------------------------------------------------------------------------------>
<apex:pageBlock title="New Licenses Needed for 2017" id="newblock">

<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">

<apex:column HeaderValue="Org">
<apex:inputField value="{!wrapper.lic.Org__c}" />
</apex:column>

<apex:column HeaderValue="Business Unit">
<apex:inputField value="{!wrapper.lic.Business_Unit__c}" />
</apex:column>

<apex:column HeaderValue="License Type">
<apex:inputField value="{!wrapper.lic.License_Type__c}"  />
</apex:column>

<apex:column HeaderValue="BU Agrees to Pay">
<apex:inputField value="{!wrapper.lic.BU_Agrees_to_Pay__c}" />
</apex:column>

<apex:column HeaderValue="2017 Number Needed">
<apex:inputField value="{!wrapper.lic.X2017_Total_Needed__c}" onclick=""/>
</apex:column>

</apex:pageBlockTable>


</apex:pageBlock>
<apex:commandButton value="Save" action="{!save}" />

<!--------------------------------------------------------------------------------------------------->

        
</apex:form>

<!--------------------------------------------------------------------------------------------------------->
</apex:page>
public with sharing class LicenseList { 
private final License_Numbers__c ln; 
public user currentuser{get;set;} 
public id tobeEdited{get;set;}
public decimal aTotal{get;set;}
public decimal tTotal{get;set;}
public List<AccountWrapper> wrappers{get;set;}
private Integer nextIdent=0;

public LicenseList(ApexPages.StandardSetController controller) { 
currentuser=new User(); 
currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()]; 
this.ln = (License_Numbers__c)controller.getRecord(); 

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 

//------------------------------------------------------------------------------------

public List<License_Numbers__c> lntypes16 = new List<License_Numbers__c>();

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Running_License_Total__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY Order_Number__c, License_Type__c];
       

return lntypes16; 
} 


//-----------------------------------------------------------------------------
public List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();
 
public List <License_Numbers__c> getLicenseList17(){ 

selectedTypes=[select id, Name, BU_Agrees_to_Pay__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2017' ORDER BY Order_Number__c, License_Type__c]; 
 aTotal = 0.0;
 tTotal = 0.0;       
        for(License_Numbers__c a:selectedTypes){
                aTotal = aTotal + a.X2017_Cost__c; 
                tTotal = tTotal + a.X2017_Subtotal__c;  
        }
return selectedTypes; 
} 
    public void saveRecord(){ 
    License_Numbers__c tobeupdated;
    for(License_Numbers__c temp:selectedTypes){
        if(temp.id==tobeEdited){
            tobeupdated = temp;
            
         }
     }
        update selectedTypes;
        tobeEdited = null;
    } 
//--------------------------------------------------------------------------------------------    

public List<License_Numbers__c> addlic {get; set;} 
  
public PageReference save()
{
    List<License_Numbers__c> addlic=new List<License_Numbers__c>();
    for(AccountWrapper wrap:wrappers)
    {
       License_Numbers__c lic = wrap.lic;
       lic.RecordTypeID = '012Q00000009F7P';
       lic.License_Year__c = '2017';
       addlic.add(wrap.lic);
    }
        
    insert addlic;
    //addlic = null;
    
    return new PageReference('/apex/LicenseSummaryHomePage');
         
}

public class AccountWrapper
{
    public License_Numbers__c lic{get; private set;}
    public Integer ident{get; private set;}
    
    
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        lic=new License_Numbers__c();
            
    }
}  //There's a lot more code here for the Schedules part - doesn't pertain to my problem
}

User-added image
 
  • October 17, 2016
  • Like
  • 0
I get the error "c.cs10.visual.force.com redirected you too many times." when I added the VF page in the home page layout. What can I do to fix this?
I have a quote trigger called Update_Opportunity_Amount. I am getting the following error when i try to deploy it to my production org.


The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
Update_Opportunity_Amount

I do have a test class, but the error states I have no code coverage. I would appreciate if anyone can tell me what is wrong with my test class that it is not testing my trigger.

Trigger

Update_Opportunity_Amount
trigger Update_Opportunity_Amount on Quote (before insert, before update) {

    List<Opportunity> opps = new List<Opportunity>();
    List<Quote> quotes = new List<Quote>();
    Map<Id, Double> quoteNR = new Map<Id, Double>();
    Set<Id> oppIds = new Set<Id>();
    Set<Id> qteIds = new Set<Id>();

    for (Quote q : Trigger.new) {
        if (q.Primary_Quote__c == true) {
            quotes.add(q);
            qteIds.add(q.Id);
            if (!quoteNr.isEmpty() && quoteNr.containsKey(q.OpportunityId)) {
                quoteNR.clear();
                q.addError('You are attempting to create multiple Primary Quotes into the one Opportunity');
            }
            else {
                quoteNR.put(q.OpportunityId, q.Net_Revenue__c);
            }
        }
    }
    
    if (!quoteNR.isEmpty()) {
        
        // Check if any Quotes tied to the same Opportunity as this Quote is listed as a Primary Quote
        for (Quote q : [SELECT Id, Primary_Quote__c, OpportunityId FROM Quote WHERE OpportunityId IN :quoteNR.keySet() AND Primary_Quote__c = true]) {
            if (qteIds.isEmpty() || !qteIds.contains(q.Id)) {
                oppIds.add(q.OpportunityId);
            }
        }

        if (!oppIds.isEmpty()) {
            for (Quote q : quotes) {
                if (oppIds.contains(q.OpportunityId)) {
                    q.addError('The Opportunity tied to this Quote already contains a Primary Quote. This quote cannot be set as a Primary Quote');
                }
            }
        }
            
        // Update the Opportunity with the Net Revenue from the Quote 
        for (Opportunity o : [SELECT Id, Amount FROM Opportunity WHERE Id IN :quoteNR.keySet()]) {
            o.Amount = quoteNR.get(o.Id);
            opps.add(o);
        }
    }
    
    if (!opps.isEmpty()) {
        update(opps);
    }
}

Test Class
@isTest
private class Update_Opportunity_Amount_TestClass {

    static testMethod void myUnitTest() {
        
        RecordType naOppType = [SELECT Id FROM RecordType WHERE Name = 'NA Opportunity Record Type' LIMIT 1];
        RecordType naAccTypeCustomer = [SELECT Id FROM RecordType WHERE Name = 'NA Customer Account Record Type - Active Customer - BW' LIMIT 1];
        RecordType naAccTypeProspect = [SELECT Id FROM RecordType WHERE Name = 'NA Customer Account Record Type - Prospect - BW' LIMIT 1];
        List<Account> accs = new List<Account>();
        List<Opportunity> opps = new List<Opportunity>();
        List<Quote> quotes = new List<Quote>();

        // Insert the Accounts to be used for the testing
        Integer j = 0;
        for (Integer i = 0; i < 41; i++) {
            Account a = new Account();
            a.Name = 'Account Test ' + i;
            a.Sales_Channel__c = '160 SPECIAL FORCES';
            a.Marketing_Level__c = 'Developer';
            a.Billing_Region__c = '1';
            a.BillingCity = '1';
            a.BillingCountry = '1';
            a.BillingPostalCode = '1';
            a.BillingState = '1';
            a.BillingStreet = '1';
            a.Shipping_Region__c = '1';
            a.ShippingCity = '1';
            a.ShippingCountry = '1';
            a.ShippingPostalCode = '1';
            a.ShippingState = '1';
            a.ShippingStreet = '1';
            if (j == 0) {
                a.RecordTypeId = naAccTypeProspect.Id;
                j = 1;
            }
            else {
                a.RecordTypeId = naAccTypeCustomer.Id;
                j = 0;          
            }
            accs.add(a);
        }
        insert(accs);
        
        // Insert the Opportunities to be used for the testing
        for (Integer i = 0; i < 41; i++) {
            Opportunity o = new Opportunity();
            o.Name = 'Opportunity Test ' + i;
            o.Amount = 111.11;
            o.StageName = 'H - Hot Prospect';
            o.CloseDate = Date.today() + 365;
            o.AccountId = accs[i].Id;
            o.RecordTypeId = naOppType.Id;
            if (j == 0) {
                o.Interface_Status_del__c = 'D';
                j = 1;
            }
            else {
                j = 0;          
            }           
            opps.add(o);
        }
        insert(opps);
        
        // Create Quoets that are NOT Primary Quotes. Each Quote for its own Opportunity
        for (Integer i = 0; i < 40; i++) {
            Quote q = new Quote();
            q.Name = 'Quote Test ' + i;
            q.Net_Revenue__c = 222.22;
            q.Primary_Quote__c = false;
            q.OpportunityId = opps[i].Id;
            quotes.add(q);
        }
        insert(quotes);
        
        // Validate that the Amount on the Opportunities still equals 111.11
        for (Opportunity o : [SELECT Id, Amount FROM Opportunity WHERE Id IN :opps AND Id != :opps[40].Id]) {
            System.assertEquals(o.Amount, 111.11);
        }
        
        // Create Quoets that are Primary Quotes. Each Quote for its own Opportunity
        quotes.clear(); 
        for (Integer i = 0; i < 40; i++) {
            Quote q = new Quote();
            q.Name = 'Quote Test ' + i;
            q.Net_Revenue__c = 999.99;
            q.Primary_Quote__c = true;
            q.OpportunityId = opps[i].Id;
            quotes.add(q);
        }
        insert(quotes);
        
        // Validate that the Amount on the Opportunities now equals 999.99
        for (Opportunity o : [SELECT Id, Amount FROM Opportunity WHERE Id IN :opps AND Id != :opps[40].Id]) {
            System.assertEquals(o.Amount, 999.99);
        }       
        
        // Update the Quotes with a new Net Revenue
        for (Quote q : quotes) {
            q.Net_Revenue__c = 555.55;
        }
        update(quotes);     
        
        // Validate that the Amount on the Opportunities now equals 555.55
        for (Opportunity o : [SELECT Id, Amount FROM Opportunity WHERE Id IN :opps AND Id != :opps[40].Id]) {
            System.assertEquals(o.Amount, 555.55);
        }       
        
        
        // Insert new Quotes that are also Primary Quotes to the same Opportunities as above. An error should be thrown
        quotes.clear();     
        for (Integer i = 0; i < 40; i++) {
            Quote q = new Quote();
            q.Name = 'Quote Test ' + i;
            q.Net_Revenue__c = 333.33;
            q.Primary_Quote__c = true;
            q.OpportunityId = opps[i].Id;
            quotes.add(q);
        }
        try {
            insert(quotes);
            System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getDmlMessage(0).indexOf('The Opportunity tied to this Quote already contains a Primary Quote. This quote cannot be set as a Primary Quote') > -1);
        }       
        
        // Validate that the Amount on the Opportunities still equals 555.55 and not 333.33 
        for (Opportunity o : [SELECT Id, Amount FROM Opportunity WHERE Id IN :opps AND Id != :opps[40].Id]) {
            System.assertEquals(o.Amount, 555.55);
        }
        
        // Create multiple Quotes for the one Opportunity all quotes being a Primary Quote. An error should be thrown
        quotes.clear();
        for (Integer i = 0; i < 40; i++) {
            Quote q = new Quote();
            q.Name = 'Quote Test ' + i;
            q.Net_Revenue__c = 888.88;
            q.Primary_Quote__c = true;
            q.OpportunityId = opps[40].Id;
            quotes.add(q);
        }
        try {
            insert(quotes);
            System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getDmlMessage(0).indexOf('You are attempting to create multiple Primary Quotes into the one Opportunity') > -1);
        }
        
        // Check that the last Opportunity (used for above test) still has the Amount 111.11
        for (Opportunity o : [SELECT Id, Amount FROM Opportunity WHERE Id = :opps[40].Id]) {
            System.assertEquals(o.Amount, 111.11);
        }
    }
}

 
  • October 17, 2016
  • Like
  • 0
Hi,

Im using apex:select list in VF page, I'm getting values from controller.

values are like below:
Pen
pencil
chart
book
tools
bags
bucks
charts

In the above list for "Charts" when the user select charts in the picklist, another pick list must be enabled. with values chart1, chart 2, chart 3.

Only when the user select charts second pick list must be enabled.

Please help me.
 
Hi guys,
 
i created this custom controller for a visualforce page.  It shows all leads of the user with high priority.  The user is able to filter Leads by the Industry. The new variable industryPickvalue is just to select "all" Leads. It works fine for me in the sandbox, but i am not able to deploy it.  I am not a developer but it would be great to hear some solutions or ideas.

public class LeadPageControllerFilter {
    public string industryPickvalue{get; set;}
    public list<lead> leadList{get; set;}
     
    public void getLeads() {
        
        if (industryPickvalue == 'All'){

        leadList = new list<lead>([SELECT Id, Name, Company, Owner.name , Status, Industry, Lead_ScoreFinal__c from Lead  
        WHERE 
            OwnerId = :UserInfo.getUserId() 
            AND Time_LastModified__c != TODAY 
            AND Status != 'TEST'
            
        ORDER BY 
            Lead_ScoreFinal__c DESC       
        LIMIT 10]);
        
        } else {
        
        leadList = new list<lead>([SELECT Id, Name, Company, Owner.name , Status, Industry, Lead_ScoreFinal__c from Lead 
        WHERE 
              OwnerId = :UserInfo.getUserId() 
              AND Industry = :industryPickvalue 
              AND Time_LastModified__c != TODAY  
              AND Status != '40 - Demo Termin vereinbart'
                  
        ORDER BY 
            Lead_ScoreFinal__c DESC       
        LIMIT 10]);
        }      
    }
}


Testclass : 
@isTest 
public class LeadPageControllerFilterTest
{
    static testMethod void testMethod1() 
    {
        // create a Lead
        Lead lead=new Lead(
        LastName='Doe', 
        FirstName='John', 
        Company = 'Test', 
        Status = 'test' ,
        Country = 'Deutschland', 
        LeadSource = 'Import',
        PostalCode = '83024',
        Phone = '0300340340',
        Industry = 'Sonstige Branche' );
        
        insert lead;   

        Test.StartTest();

            LeadPageControllerFilter obj = new LeadPageControllerFilter();
           
            obj.industryPickvalue ='All';
            obj.getLeads();        
            obj.industryPickvalue ='Sonstige Branche';
            obj.getLeads();
           
        Test.StopTest();        
        
    }
}

The problem is the variable "industryPickvalue". I need the testclass for this controller, but i can't deploy it, because the variable "industryPickvalue" doesen't exist in the production. Maybe i have to deploy the varibale separately ?  Or maybe i can create the filter "all" with the visualforce page ?  Thanks for your help and your time ! 

 

User-added image

I am trying to update these numbers (sorting). If i see the repeated number it should give me an error only when i click the update button. Please find my APEX Code as below

public PageReference UpdateAction(){
        Savepoint sp = Database.setSavepoint();
        try{
            if (strType=='AP'){
            List<Company_Priorities__c> actPList = [select Field1__c, Name from Company_Priorities__c];
            integer i = 0; 
            integer j = 0;
            integer k = 0;
            for(i = 0; j< actPList.length–1; j ++);
               {
                    for(k=(i+1); j< actPList.length; j ++)
                    {
                       if(actPList[i].number == actPList[j].number)
                        {
                            Raise Error
                            Break;
                        }
                    }
                }
                update actPList;
I am getting error. Can anyone help.
Hi Team,

We have created Two batch classes using different objects(Account and Opportunity) for updating the Teammembrs which are working fine.But my problem is i want to include onebatch class instead of two batch class.Can any one please help on this.

Thanks