• Ben Morch
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 6
    Questions
  • 4
    Replies
Hi all,

I am reveiwing some code in our instance that I did not write.  It appears to be a simple if-then statement but I want to make sure I understand the syntax.
cqr = acc.Credit_Quality_Rating__c == null ? 0 : acc.Credit_Quality_Rating__c;

I believe this is saying:
If acc.Credit_Quality_Rating__c is null, then set cqr = 0, else set it to acc.Credit_Quality_Rating__c.

I also have this is in the code that is confusing me:
ReviewDate = ReviewDate || oldAcc.Credit_Review_Date__c != acc.Credit_Review_Date__c ? true : false;

I was having a hard time figuring this one out.  I am just looking for an explanation of the syntax.

Thanks for any help
Hello All,

I am creating a couple of lists so that I can display values of a custom object onto the Account layout through a VF page.  It is basically a rollup or sum of data that is associated with that account.  One of the fields that I want to show is a formula field.  I am doing this sum per month of data and comparing Current Year vs Prior Year.

My issue comes in with the Current Year data when the month has no data yet.  For example, we are currently in the month of April which means that May has no data.  In the Apex Class I am adding the missing months data to the list that is being displayed.  When I look at the VF page though, the data associate with the formula field is blank.  Obviously I can't force a value into that field since it is ready only.  Is there another way to force the formula field to have a value before the VF page grabs it?

VF Page results

Partial code from Apex Class
integer missingMonths = 12-maxMonth;
        for (integer i=1; i<=missingMonths; i++){
            zeroMonth = new Order_Summary__c();
            If (i+maxMonth > 9){
                zeroMonth.Account__c = AccountId;
                zeroMonth.Delivery_Month__c = string.valueOf(i+maxMonth);
                zeroMonth.Delivery_Year__c = String.valueOf(thisYear);
                zeroMonth.Revenue__c = 0;
                zeroMonth.Paid__c = 0;
                zeroMonth.Load_Count__c = 0;
            } else {
                zeroMonth.Account__c = AccountId;
                zeroMonth.Delivery_Month__c = string.valueOf('0' + (i+maxMonth));
                zeroMonth.Delivery_Year__c = String.ValueOf(thisYear);
                zeroMonth.Revenue__c = 0;
                zeroMonth.Paid__c = 0;
                zeroMonth.Load_Count__c = 0;
            }
            currentYear.add(zeroMonth);

Partial VF Page code
<table border="1" >
    <tr>
    <td colspan="4" align="center"><h1> 
        Current Year</h1></td> 
    </tr>
    
    <tr bgcolor="#0f5e9d">
    <td align="center"><headerTxt>Month</headerTxt></td>
    <td align="center"><headerTxt>Rev $</headerTxt></td>    
    <td align="center"><headerTxt>GM $</headerTxt></td>
    <td align="center"><headerTxt>Loads</headerTxt></td>
    </tr>
      <apex:repeat value="{!currentYear}" var="cy"> 
   
          <tr onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">        
              
        <td width="75"><monthTxt>{!cy['Month_Name__c']}</monthTxt></td>
        <td width="75" align="center"><apex:outputText value="{0,number,$#,###}"> <apex:param value="{!cy['Revenue__c']}"/></apex:outputText></td>
        <td width="75" align="center"><apex:outputText value="{0,number,$#,###}"> <apex:param value="{!cy['GM__c']}"/></apex:outputText></td>
        <td width="75" align="center"><apex:outputText value="{0,number,###}"> <apex:param value="{!cy['Load_Count__c']}"/></apex:outputText></td>

        

           </tr>
     
         </apex:repeat>        
        <apex:repeat value="{!currentYearTotal}" var="cyt"> 
         <tr bgcolor="#0f5e9d">
             <td align="center"><headerTxt>Total</headerTxt></td>
             <td align="center"><headerTxt><apex:outputText value="{0,number,$#,###}"> <apex:param value="{!cyt['Revenue']}"/></apex:outputText></headerTxt></td>
             <td  align="center"><headerTxt><apex:outputText value="{0,number,$#,###}"> <apex:param value="{!cyt['GM']}"/></apex:outputText></headerTxt></td>
             <td  align="center"><headerTxt><apex:outputText value="{0,number,###}"> <apex:param value="{!cyt['LoadCount']}"/></apex:outputText></headerTxt></td>
         </tr>
         </apex:repeat> 
   
    </table>

 
Hello All,

I want to be able to create a Case after selecting records from a list view on a custom object (Collections__c).  I have already tried a few things to get this done, but can't get all the way through it.  I wanted to see if the community had any suggestions on the best way to acheive this process.

Here is a break down of what is required for our process:
  • Be able to select 1 or more records from a list view on Collections__c
  • Open a VF page to select a Collection Issue (this is an object with 12 records in it) and apply it to a field in all of the selected Collections__c records
  • Create a Case
  • Apply the Case ID to the selected Collections__c records so that they show in the related list on the Case

Of course, as with any process there will be more happening inbetween, but that is the main logical process.  I was able to get the list of Collections__c records, open the VF page, and display a pick list of the Collection Issue records on the VF page.  I was not able to grab the selected Collection Issue, apply it to the Collections__c records, or create a Case.

To get the list of Collections__c from a list view I followed this site:
http://sfdcsrini.blogspot.com/2014/11/custom-salesforce-button-to-execute.html

The link example shows that after the records are selected it simply does an update to a single field on the records.  My purpose is to open a VF page that displays a picklist of Collection Issues (the Name from each record in that object) so that one can be chosen.  Because of this I called a Global class to get and display the Collection Issues.  This is about the point that i begin to have trouble getting things done as I *think* that they should happen.  The Collection Issues picklist displays on the VF page that opens from the same button as getting the list of Collections__c.  When I select one of the options in the picklist, I can't get the selection to be applied to the list<Collections__c> and create a new Case.  This, in turn, means that I can't apply the Case ID to the list<Collections__c> either.

Hoping that someone can give me some guidance on this one.

Hello All,

I am trying to call a custom class from a link on the Account object using Execute JavaScript.  Ultimately I want to call the SecurityCheck class with a parameter of the account Id to instantiate the "sec" variable.  Then set the "show" variable to the results of sec.showPage().  I am doing something wrong here as I am not very good with JavaScript.  Once I have show = true || false then I will direct to one of two URLs.

My questions are:
1) How do I properly instantiate a variable in JavaScript by calling a class constructor with a parameter?
2) How do I then call a method of that class (class.showPage)?
3) Is there a better way to do this?  Like JS on the VF page that I am directing to?
 
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")}

try{
    var acct = '{!Account.Id}';
    var sec = sforce.apex.execute("SecurityCheck","SecurityCheck",{acct:acct});

    var show = sforce.apex.execute("SecurityCheck","sec.showPage",{});  

    //alert(show);
}
catch(err){
    var txt = "Error: ";
    txt+=err.description+" 11";
    alert(txt);
}

If (show == true) {
    window.open('ThisURL');
} else {
    window.open('ThatURL');
}

Thanks all for taking a look.

Hello,

I am trying to create a test class for a security check class.  I am using a SOQL query to get an account and pass that along to the class.  When I do a Run Test in the sandbox, it give me the following error:

System.QueryException: List has no rows for assignment to SObject
Class.SecurityCheckTest.securityCheckTest: line 32, column 1

I believe this is telling me that the query is not returning any data to put into the "acct" attribute.  But I have put a "where id != NULL" on the query.  Can anyone give me a suggestion as to why I would still be getting this error?

Line 32 -  

acct = [select id,name,ownerId,BillingAddress,ShippingAddress,Billing_Address__c,Shipping_Address__c,BillingStreet ,BillingCity,BillingState,BillingPostalCode,BillingCountry,
                                    ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry,CreatedBy.name,lastModifiedBy.name ,CreatedDate,createdby.id,lastmodifiedby.id,
                                    lastmodifieddate,Ultimate_Parent_Owner_ID__c,lastActivityDate,account_availability__c,Account_Link__c,Account_Hierarchy_Link__c
                                    from account where id != NULL limit 1];
Test Class -
@isTest
private class SecurityCheckTest {

    static testMethod void securityCheckTest() {
      
      boolean showing;
      User runThis = [Select id, alias, email, username, userRoleId, ProfileId From User Where userRoleId != NULL limit 1];
      system.debug('runThis user ==> ' + runThis);
      
      Account acct = new Account();
      acct = [select id,name,ownerId,BillingAddress,ShippingAddress,Billing_Address__c,Shipping_Address__c,BillingStreet ,BillingCity,BillingState,BillingPostalCode,BillingCountry,
                                    ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry,CreatedBy.name,lastModifiedBy.name ,CreatedDate,createdby.id,lastmodifiedby.id,
                                    lastmodifieddate,Ultimate_Parent_Owner_ID__c,lastActivityDate,account_availability__c,Account_Link__c,Account_Hierarchy_Link__c
                                    from account where id != NULL limit 1];
    insert acct;  // is this necessary?
        
        system.debug('acct id ==> ' + acct.id);
        system.debug('Name ==> '+ acct.Name);
        system.debug('UPO ID ==> ' + acct.Ultimate_Parent_Owner_ID__c);
        if(acct!=NULL){
      SecurityCheck sec = new SecurityCheck(acct);
      system.debug('acct ==> ' + acct);
      system.debug('currRecord ==> ' + sec.currRecord);
      system.RunAs(runThis){
        showing = sec.showPage();
      }
        } else { system.debug('==> Account is empty'); }
    
    
    system.debug('showing ==> ' + showing);
    }
}
Thanks for any help that you can give.
Hello,

I am trying to deploy some classes that I have updated, but when I deploy them I get an error from a test class that has nothing to do with the classes that I am deploying.  The purpose of the OverrideAccount class is to check to see if the current user should have access to the account or not.  If they should, then give them the standard account page, otherwise show them a VF page with limited data.

Error message from the deployment validation:
System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.OverrideAccount.<init>: line 17, column 1 Class.OverRideAccount_Test.OverRideAccount_test: line 56, column 1

Test Class code:
@isTest
public class OverRideAccount_Test {

    private static testmethod void OverRideAccount_test(){
        user[] u = [select id,name from user where isactive =:true and profile.name!=: 'System Administrator' limit 5];  
  
        // Create account with current logged in user (admin) as owner
        account a = new account() ;
        a.name = 'testName' ;
        a.ownerId = userinfo.getuserid() ;
        system.debug('a ==> '+ A) ;
        insert a ;

        // Create account with general user as owner
        account a1 = new account() ;
        a1.name = 'testName' ;
        a1.ownerId = u[0].id ;
        system.debug('a ==> '+ A1) ;
        insert a1 ;
        
     ...
     ...
    
        //test Override method as the admin
        Apexpages.Standardcontroller std = new ApexPages.StandardController( a) ;
        Apexpages.CurrentPage().getParameters().put( 'id',a.id ) ;
        overRideAccount oa = new overRideAccount(std) ;
        oa.redirect();
        getdomain.DomainURL() ;      
        
        //test Override method as a general user (not the a1 account owner)
        Apexpages.Standardcontroller std1 = new ApexPages.StandardController( a1) ;
        Apexpages.CurrentPage().getParameters().put( 'id',a1.id ) ;
        system.runas(u[2]){
line 56    overRideAccount oa1 = new overRideAccount(std1) ;
                oa1.redirect();
        }
     }
           
}

OverrideAccount Class code:
public account acct {get;set;}
    public account ContRecord {get;set;}
    public profile profile ;  
    public boolean showpage = true;
    Public userRole UserRole ;
    Public userRole loggedInUserRole ;
    Public user user ;
    Public User LoggedinUser ;
    public Id id ;       
    public string domainURL {get;set;}

    public OverrideAccount(apexPages.standardController controller){
          acct = (account)controller.getrecord() ;
          this.id = controller.getid() ;
line 17    ContRecord = [select id,name,ownerId,BillingAddress,ShippingAddress,Billing_Address__c,Shipping_Address__c,BillingStreet ,BillingCity,BillingState,BillingPostalCode,BillingCountry,
                                    ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry,CreatedBy.name,lastModifiedBy.name ,CreatedDate,createdby.id,lastmodifiedby.id,
                                    lastmodifieddate,Ultimate_Parent_Owner_ID__c,lastActivityDate,account_availability__c,Account_Link__c 
                                    from account where id = : acct.Id limit 1] ;     
        //domain URL for View hierarchy link on visualforce limited view page
        domainURL =  url.getSalesforceBaseUrl().toExternalForm(); 
        domainURL = getDomain.SfdchostName(); 
        system.debug('Domain URL ==>' + domainURL);
        user = [select id,name,UserRoleId,profileId from user where id =:ContRecord.OwnerId limit 1];
       
        Profile = [select id,name from profile where id = :userinfo.getprofileId() ];                 
        
        if(user!=null){
        UserRole = [select id,parentRoleId,DeveloperName,Name from UserRole where Id=:user.UserRoleId limit 1] ;
            if(UserRole != nuLL){
            LoggedinUser = [select id,name,UserRoleId,profileId from user where id =:userInfo.getUserId() limit 1];  
                if(LoggedinUser.UserRoleId != null){
                loggedInUserRole =  [select id,parentRoleId,DeveloperName,Name from UserRole where Id=:LoggedinUser.userroleId limit 1] ;
                }
            }
        }            
    }
Thanks for any help on this one and let me know if you need further information.

-Ben
 
So I have created flows before where the flow is started from a record using a custom button, and that record's ID is passed into the flow as a variable, which is great!

However, I now want to do this but starting from a list view, where I would select (check) a bunch of records and then click a custom button to start the flow, and have the record IDs of all the checked records pass into the flow as a list of variables (I think it would be an sObject variable?)

Is this possible? 
Thanks
  • February 20, 2015
  • Like
  • 3

Hello,

I am trying to create a test class for a security check class.  I am using a SOQL query to get an account and pass that along to the class.  When I do a Run Test in the sandbox, it give me the following error:

System.QueryException: List has no rows for assignment to SObject
Class.SecurityCheckTest.securityCheckTest: line 32, column 1

I believe this is telling me that the query is not returning any data to put into the "acct" attribute.  But I have put a "where id != NULL" on the query.  Can anyone give me a suggestion as to why I would still be getting this error?

Line 32 -  

acct = [select id,name,ownerId,BillingAddress,ShippingAddress,Billing_Address__c,Shipping_Address__c,BillingStreet ,BillingCity,BillingState,BillingPostalCode,BillingCountry,
                                    ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry,CreatedBy.name,lastModifiedBy.name ,CreatedDate,createdby.id,lastmodifiedby.id,
                                    lastmodifieddate,Ultimate_Parent_Owner_ID__c,lastActivityDate,account_availability__c,Account_Link__c,Account_Hierarchy_Link__c
                                    from account where id != NULL limit 1];
Test Class -
@isTest
private class SecurityCheckTest {

    static testMethod void securityCheckTest() {
      
      boolean showing;
      User runThis = [Select id, alias, email, username, userRoleId, ProfileId From User Where userRoleId != NULL limit 1];
      system.debug('runThis user ==> ' + runThis);
      
      Account acct = new Account();
      acct = [select id,name,ownerId,BillingAddress,ShippingAddress,Billing_Address__c,Shipping_Address__c,BillingStreet ,BillingCity,BillingState,BillingPostalCode,BillingCountry,
                                    ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry,CreatedBy.name,lastModifiedBy.name ,CreatedDate,createdby.id,lastmodifiedby.id,
                                    lastmodifieddate,Ultimate_Parent_Owner_ID__c,lastActivityDate,account_availability__c,Account_Link__c,Account_Hierarchy_Link__c
                                    from account where id != NULL limit 1];
    insert acct;  // is this necessary?
        
        system.debug('acct id ==> ' + acct.id);
        system.debug('Name ==> '+ acct.Name);
        system.debug('UPO ID ==> ' + acct.Ultimate_Parent_Owner_ID__c);
        if(acct!=NULL){
      SecurityCheck sec = new SecurityCheck(acct);
      system.debug('acct ==> ' + acct);
      system.debug('currRecord ==> ' + sec.currRecord);
      system.RunAs(runThis){
        showing = sec.showPage();
      }
        } else { system.debug('==> Account is empty'); }
    
    
    system.debug('showing ==> ' + showing);
    }
}
Thanks for any help that you can give.
Hello,

I am trying to deploy some classes that I have updated, but when I deploy them I get an error from a test class that has nothing to do with the classes that I am deploying.  The purpose of the OverrideAccount class is to check to see if the current user should have access to the account or not.  If they should, then give them the standard account page, otherwise show them a VF page with limited data.

Error message from the deployment validation:
System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.OverrideAccount.<init>: line 17, column 1 Class.OverRideAccount_Test.OverRideAccount_test: line 56, column 1

Test Class code:
@isTest
public class OverRideAccount_Test {

    private static testmethod void OverRideAccount_test(){
        user[] u = [select id,name from user where isactive =:true and profile.name!=: 'System Administrator' limit 5];  
  
        // Create account with current logged in user (admin) as owner
        account a = new account() ;
        a.name = 'testName' ;
        a.ownerId = userinfo.getuserid() ;
        system.debug('a ==> '+ A) ;
        insert a ;

        // Create account with general user as owner
        account a1 = new account() ;
        a1.name = 'testName' ;
        a1.ownerId = u[0].id ;
        system.debug('a ==> '+ A1) ;
        insert a1 ;
        
     ...
     ...
    
        //test Override method as the admin
        Apexpages.Standardcontroller std = new ApexPages.StandardController( a) ;
        Apexpages.CurrentPage().getParameters().put( 'id',a.id ) ;
        overRideAccount oa = new overRideAccount(std) ;
        oa.redirect();
        getdomain.DomainURL() ;      
        
        //test Override method as a general user (not the a1 account owner)
        Apexpages.Standardcontroller std1 = new ApexPages.StandardController( a1) ;
        Apexpages.CurrentPage().getParameters().put( 'id',a1.id ) ;
        system.runas(u[2]){
line 56    overRideAccount oa1 = new overRideAccount(std1) ;
                oa1.redirect();
        }
     }
           
}

OverrideAccount Class code:
public account acct {get;set;}
    public account ContRecord {get;set;}
    public profile profile ;  
    public boolean showpage = true;
    Public userRole UserRole ;
    Public userRole loggedInUserRole ;
    Public user user ;
    Public User LoggedinUser ;
    public Id id ;       
    public string domainURL {get;set;}

    public OverrideAccount(apexPages.standardController controller){
          acct = (account)controller.getrecord() ;
          this.id = controller.getid() ;
line 17    ContRecord = [select id,name,ownerId,BillingAddress,ShippingAddress,Billing_Address__c,Shipping_Address__c,BillingStreet ,BillingCity,BillingState,BillingPostalCode,BillingCountry,
                                    ShippingStreet,ShippingCity,ShippingState,ShippingPostalCode,ShippingCountry,CreatedBy.name,lastModifiedBy.name ,CreatedDate,createdby.id,lastmodifiedby.id,
                                    lastmodifieddate,Ultimate_Parent_Owner_ID__c,lastActivityDate,account_availability__c,Account_Link__c 
                                    from account where id = : acct.Id limit 1] ;     
        //domain URL for View hierarchy link on visualforce limited view page
        domainURL =  url.getSalesforceBaseUrl().toExternalForm(); 
        domainURL = getDomain.SfdchostName(); 
        system.debug('Domain URL ==>' + domainURL);
        user = [select id,name,UserRoleId,profileId from user where id =:ContRecord.OwnerId limit 1];
       
        Profile = [select id,name from profile where id = :userinfo.getprofileId() ];                 
        
        if(user!=null){
        UserRole = [select id,parentRoleId,DeveloperName,Name from UserRole where Id=:user.UserRoleId limit 1] ;
            if(UserRole != nuLL){
            LoggedinUser = [select id,name,UserRoleId,profileId from user where id =:userInfo.getUserId() limit 1];  
                if(LoggedinUser.UserRoleId != null){
                loggedInUserRole =  [select id,parentRoleId,DeveloperName,Name from UserRole where Id=:LoggedinUser.userroleId limit 1] ;
                }
            }
        }            
    }
Thanks for any help on this one and let me know if you need further information.

-Ben
 
So I have created flows before where the flow is started from a record using a custom button, and that record's ID is passed into the flow as a variable, which is great!

However, I now want to do this but starting from a list view, where I would select (check) a bunch of records and then click a custom button to start the flow, and have the record IDs of all the checked records pass into the flow as a list of variables (I think it would be an sObject variable?)

Is this possible? 
Thanks
  • February 20, 2015
  • Like
  • 3