+ Start a Discussion
Daniel RetaleatoDaniel Retaleato 
I need to get the name of the current app in the controller. So far I'm trying:
public static String getAppName() {
         UserAppInfo userAppInfo = [SELECT Id, AppDefinitionId FROM UserAppInfo WHERE UserId = :UserInfo.getUserId() LIMIT 1];
        AppDefinition appDefinition = [SELECT DurableId, Label FROM AppDefinition Where DurableId = :userAppInfo.AppDefinitionId LIMIT 1];
       return appDefinition.Label;
    }
But Im getting 3 errors:

Line 1: No such column 'AppDefinitionId' on entity 'UserAppInfo'
Line 2: Invalid type: AppDefinition
Line 3: Variable does not exist: appDefinition

Can anyone provide some insight as to what I may be doing wrong? Thanks!
Best Answer chosen by Daniel Retaleato
Khan AnasKhan Anas (Salesforce Developers) 
Hi Daniel,

Greetings to you!

Your code looks good to me. Make sure you are using API version 43.0 or later. As per the Salesforce doc, AppDefinitionId field on UserAppInfo object and AppDefinition object are available in API version 43.0 and later.

Please refer to the below links which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userappinfo.htm

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_appdefinition.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
wenchun zgwenchun zg 
I researched a lot and didn't find any solutions, so far I only can add VF pages to record Detail page. I saw there was a Salesforce idea posted for long time  https://success.salesforce.com/ideaview?id=08730000000Br8CAAS , but it seems Salesforce still doesn't support this.

So is it possible to add visualforce page on record Edit page now?
Best Answer chosen by wenchun zg
Hargobind_SinghHargobind_Singh
Hi,

No, VF page cannot be added to Record Edit Page. If you really need dynamic functionality, you can always create a VF page for editing the records and add the fields you want to edit. THough this would be less flexible as page layout changes would mean updating the VF Page everytime. 


Guilherme TavaresGuilherme Tavares 
I'm trying to test a trigger that updates the Case Status field, but the assert is failing on Test Class, can anyone help me with this? 

Here is the Test Class
@isTest 
private class AtualizaStatusDoChamadoTest {
    
    private static testmethod void testaTrigger(){
        Case novoCaso = new Case();
        novoCaso.Nome__c = 'Teste';
        novoCaso.Status = 'Em aberto';
        novoCaso.Email__c = 'teste@teste.com';
        insert novoCaso;

        Comentario_caso__c novoComentario = new Comentario_caso__c();
        novoComentario.Caso__c = novoCaso.Id;
        novoComentario.Tipo_de_Comentario__c = 'Encerramento';
        insert novoComentario;   
        
        Case caso = [SELECT Id, Status FROM Case WHERE Id =: novoComentario.Caso__c];
        
        Test.startTest();
        System.assertEquals('Encerrado', caso.Status);
        Test.stopTest();
    }
}

Here is the Trigger
trigger AtualizaStatusDoChamado on Comentario_Caso__c (before insert, before update) {
    if(Trigger.isBefore){
        if(Trigger.isInsert || Trigger.isUpdate){
            List<Comentario_Caso__c> listaDeComentarios = trigger.new;
            Comentario_Caso__c novoComentario = listaDeComentarios[0];
            Case casoDoComentario = [SELECT Id, Status FROM Case WHERE Id =: novoComentario.Caso__c];
            if(novoComentario.Tipo_de_Comentario__c == 'Encerramento'){
                casoDoComentario.Status = 'Encerrado';
            }    
            System.debug('caso: ' + casoDoComentario);
        }
    }
}

Log
11:52:42:863 EXCEPTION_THROWN [19]|System.AssertException: Assertion Failed: Expected: Encerrado, Actual: Em aberto

On the Trigger, the debug is showing the correct Status, maybe I'm doing something wrong when trying to get the updated Case on Test Class.
Best Answer chosen by Guilherme Tavares
sachinarorasfsachinarorasf
Hi Guilherme,
As I am seeing your trigger here you are not updating the case record after updating the status of the case. In the test, you are querying the case after inserting the Comentario_Caso__c Record. So you need to update the case record after changing the status. After this, your assert will not fail.
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com
ApolloSApolloS 

This is my first attempt at tweaking an APEX. It is a e-mail template for Invoice which is generated from "Send E-mail" within Opportunity. I am getting: " Error: Unknown property 'core.email.template.EmailTemplateComponentController.Opportunity' " when I am trying to save. What am I missing here?

 

 <messaging:emailTemplate subject="Your invoice" recipientType="Contact"  
relatedToType="Opportunity">
<messaging:htmlEmailBody >
 
<table border="0" cellspacing="0" cellpadding="10" width="700" id="table1" align="center">
<tr>
    <td width="230">
        <img src='{!URLFOR($Resource.PixLogo70pix)}' title=" Logo" />
    </td>
    <td align="right"><font face="Arial" size="2" color="#666666"> One Broadway<br />
    </font>
    </td>  
</tr> 
</table>
<center>
    <p style="font-family:Arial;font-size:22px;font-weight:bold;color:#666666;">INVOICE</p>
</center>
<br/>
 
<table border="0" cellspacing="0" cellpadding="5" width="800" id="table1" align="center">
<tr>    <td valign="top">
    <font face="Arial" size="2" color="#666666">
    Bill To:</font><br />
    <font face="Arial" size="2">
    {!Opportunity.Account.Name}<br/>
    {!Opportunity.Account.BillingStreet}<br/>
    {!Opportunity.Account.BillingCity}, {!Opportunity.Account.BillingState} {!Opportunity.Account.BillingPostalCode}<br/>
    {!Opportunity.Account.BillingCountry}<br/>
  </font>
</td> 
        <td>&nbsp;</td>
   <td valign="top">
     <font face="Arial" size="2">
   <font color="#666666">Account Name:</font> <br/>
   {!Opportunity.Account.Name}<br/>
   <font color="#666666">Invoice Number:</font> <br/>
   {!Opportunity.Project_number__c}<br/>
   <font color="#666666">Invoice Date:</font> <br/>
   {!Opportunity.CloseDate}<br />
   <font color="#666666">Payment Terms:</font> <br/>
   <font color="#FF3300">Due Upon Receipt</font></font></td>    
</tr>
</table>
<br/>
 
<table width="800" border="0" align="center" cellpadding="3" cellspacing="1" id="table4">
<tr bgcolor="#E5E5E5"><font face="Arial" size="2" color="#666666">
       <td>Product</td>
      <td>Description</td>
       <td>Quantity</td>
       <td>Unit Price</td>
       <td>Total Price</td>
       </font>
</tr>
<tr><font face="Arial" size="2" color="#000000">
       <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
          <tr>
             <td>{!line.PricebookEntry.Name}</td>
             <td>{!line.Description}</td>           
             <td>{!line.Quantity}</td>
             <td><apex:OutputField value="{!line.UnitPrice}"/></td>
             <td><apex:OutputField value="{!line.TotalPrice}"/></td>
          </tr>
       </apex:repeat>  
       </font>
</tr>
<tr>
       <td bgcolor="#FFFFFF" align="right" colspan="5">
       <font face="Arial" size="2">Sub-total:&nbsp;<apex:OutputField value="{!Opportunity.Sub_Total__c}"/></font></td>
</tr>
<tr>
       <td bgcolor="#FFFFFF" align="right" colspan="5">
       <font face="Arial" size="2">Discounts:&nbsp;<apex:OutputField value="{!Opportunity.Discount_amount__c}"/></font></td>
</tr>
<tr>
       <td bgcolor="#FFFFFF" align="right" colspan="5">
       <font face="Arial">Tax:&nbsp;<apex:OutputField value="{!Opportunity.Sales_Tax__c}"/></font></td>
</tr>
<tr>
       <td bgcolor="#E5E5E5" align="right" colspan="5">
       <font face="Arial"><b>Total:</b>&nbsp;<apex:OutputField value="{!Opportunity.Amount}"/></font></td>
</tr>
</table>
<br/>
 
<p align="center"><font face="Arial">Thank you very much for you business!<br />
{!Opportunity.CreatedBy.FirstName} {!Opportunity.CreatedBy.LastName}
</font></p>
</messaging:htmlEmailBody>
 
<messaging:attachment renderAs="pdf" filename="{!relatedTo.name}">  
<table border="0" cellspacing="0" cellpadding="10" width="700" id="table1" align="center">
<tr>
    <td width="230">
        <img src='{!URLFOR($Resource.PixLogo70pix)}' title="Pixability Logo" />
    </td>
    <td align="right"><font face="Arial" size="2" color="#666666"> One Broadway<br />
</font>
    </td>  
</tr>
</table>
<center>
    <p style="font-family:Arial;font-size:22px;font-weight:bold;color:#666666;">INVOICE</p>
</center>
<br/>
 
<table border="0" cellspacing="0" cellpadding="5" width="800" id="table1" align="center">
<tr>    <td valign="top">
    <font face="Arial" size="2" color="#666666">
    Bill To:</font><br />
    <font face="Arial" size="2">
    {!Opportunity.Account.Name}<br/>
    {!Opportunity.Account.BillingStreet}<br/>
    {!Opportunity.Account.BillingCity}, {!Opportunity.Account.BillingState} {!Opportunity.Account.BillingPostalCode}<br/>
    {!Opportunity.Account.BillingCountry}<br/>
  </font>
</td> 
        <td>&nbsp;</td>
   <td valign="top">
     <font face="Arial" size="2">
   <font color="#666666">Account Name:</font> <br/>
   {!Opportunity.Account.Name}<br/>
   <font color="#666666">Invoice Number:</font> <br/>
   {!Opportunity.Project_number__c}<br/>
   <font color="#666666">Invoice Date:</font> <br/>
   {!Opportunity.CloseDate}<br />
   <font color="#666666">Payment Terms:</font> <br/>
   <font color="#FF3300">Due Upon Receipt</font></font></td>    
</tr>
</table>
<br/>
 
<table width="800" border="0" align="center" cellpadding="3" cellspacing="1" id="table4">
<tr bgcolor="#E5E5E5"><font face="Arial" size="2" color="#666666">
       <td>Product</td>
      <td>Description</td>
       <td>Quantity</td>
       <td>Unit Price</td>
       <td>Total Price</td>
       </font>
</tr>
<tr><font face="Arial" size="2" color="#000000">
       <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
          <tr>
             <td>{!line.PricebookEntry.Name}</td>
             <td>{!line.Description}</td>           
             <td>{!line.Quantity}</td>
             <td><apex:OutputField value="{!line.UnitPrice}"/></td>
             <td><apex:OutputField value="{!line.TotalPrice}"/></td>
          </tr>
       </apex:repeat>  
       </font>
</tr>
<tr>
       <td bgcolor="#FFFFFF" align="right" colspan="5">
       <font face="Arial" size="2">Sub-total:&nbsp;<apex:OutputField value="{!Opportunity.Sub_Total__c}"/></font></td>
</tr>
<tr>
       <td bgcolor="#FFFFFF" align="right" colspan="5">
       <font face="Arial" size="2">Discounts:&nbsp;<apex:OutputField value="{!Opportunity.Discount_amount__c}"/></font></td>
</tr>
<tr>
       <td bgcolor="#FFFFFF" align="right" colspan="5">
       <font face="Arial">Tax:&nbsp;<apex:OutputField value="{!Opportunity.Sales_Tax__c}"/></font></td>
</tr>
<tr>
       <td bgcolor="#E5E5E5" align="right" colspan="5">
       <font face="Arial"><b>Total:</b>&nbsp;<apex:OutputField value="{!Opportunity.Amount}"/></font></td>
</tr>
</table>
<br/>
 
<p align="center"><font face="Arial">Thank you very much for you business!<br />
{!Opportunity.CreatedBy.FirstName} {!Opportunity.CreatedBy.LastName}
</font></p>
</messaging:attachment>      
</messaging:emailTemplate>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
icemft1976icemft1976

You correctly bound the 'relatedtotype' at the top of your template....but inside the template try replacing "Opportunity" in the email body with {!relatedTo}. Templates use this generic placeholder for whatever Sobject type you choose to associate with them

 

{!Opportunity.Account.Name}  ->  {!relatedTo.Account.Name}

{!Opportunity.OpportunityLineItems}  ->  {!relatedTo.OpportunityLineItems}

  etc...

 

check out the example from the docs, at the bottom it shows how to use 'relatedTo' (and also how child objects are referenced)

 

 

 

Kitty BarnesKitty Barnes 
I am new to writing validation rules and am stuck.  I need to write a rule so that a person can not change a project status to active unless a picklist field called foundation type is filled out. This would only apply to projects that fall within certain departments.

User-added image
 
Best Answer chosen by Kitty Barnes
Maharajan CMaharajan C
Hi Kitty,

You have to write the validation rule like below:
 
AND( 
ISPICKVAL(Project_Status__c, "Active"),
ISBLANK(TEXT(Foundation_Type__c)),
OR(
ISPICKVAL(ProjDept__c, "Custom"), 
ISPICKVAL(ProjDept__c, "Commercial"), 
ISPICKVAL(ProjDept__c, "Addition")
)
)

Thanks,
Maharajan.C
Peter Davids 4Peter Davids 4 

 
Hi all,

We need to implement the following pattern at my org:
  • callout to external data source
  • if that callout takes too long (according to some configurable threshold), log an error (ie do some DML)
  • if that callout timed out on the remote server, try it again
Recognizing the potential for the dreaded "You have uncommitted work pending. Please commit or rollback before calling out." error, I put the error logging code in a future method, thus isolating the DML from the callouts. However, the error is still being thrown. I reduced the issue down to this pattern:
public static void foo() {
    Http http = new Http();
    HttpRequest req = new Httprequest();
    req.setEndpoint('https://test.salesforce.com'); //whatever endpoint
    req.setMethod('GET');
    http.send(req); //works fine
    bar();
    http.send(req); //throws calloutexception
}

@future public static void bar() {

}
Am I correct to assume that calling a future method counts as a DML operation? Is there any documentation I'm missing somewhere?

 
Best Answer chosen by Peter Davids 4
Peter Davids 4Peter Davids 4
svidyansvidyan 

Hi,

 

I am following the book "Developement with the Force.com platform" by JasonOuelette.

When creating the Custom Objects, I did not check the box to be visible in a tab, and so I could not add this object to the Custom App I was creating. Now I have a created fields and relationships in the custom object. How do I add this Object to the Custom App?

 

thanks

Svidya

Best Answer chosen by Admin (Salesforce Developers) 
b-Forceb-Force

It looks you havent create custom Tabs while defining custom objects first you need to create custom Tab for new objects Creating Tab Setup -->App Set up---> Create---> Tabs Click on new Tab [drop down shows all untabed objects ] select your object, set Tab style , click Next select profiles Save Adding To App Setup -->App Set up---> Create---> Apps Click on edit, edit available tab section Save Done Thanks, Bala

Naren9Naren9 
Hi All,
In Salesforce Lightning, do we have any option to remove/disable the Drilldown/View report hyper link on Dashboard?.

Thanks,
Naren
Best Answer chosen by Naren9
NagendraNagendra (Salesforce Developers) 
Hi Naren,

Sorry for this issue you are facing.

Unfortunately, this is not possible as of now. There is an idea which is active on the success community for which you can upvote so that it can be available in the mere future.

You can find the idea at the below link. Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
MedhanieHabteMedhanieHabte 
I seem to be stuck on this trailhead module or write negative tests unit, while I have 93 percent code coverage, I can't seem to get the code coverage to hit 100 percent at the "returnValue" piece doesn't seem to hit.
My code is as follows.

Calculator Class
 
public class Calculator {
 public class CalculatorException extends Exception{}

  public static Integer addition(Integer a, Integer b){
   return a + b;
    }

   public static Integer subtraction(Integer a, Integer b){
    return a - b;
    }

 public static Integer multiply(Integer a, Integer b){
  if(b==0 || a==0){
  throw new CalculatorException('It doesn\'t make sense to multiply by 
   zero');
  }
  return a * b;
  }

 public static Decimal divide(Integer numerator, Integer denominator){
  if(denominator == 0){
  throw new CalculatorException('you still can\'t divide by zero');
   }
 Decimal returnValue = numerator / denominator;
  if(returnValue < 0){
    throw new CalculatorException('Division returned a negative value.' + 
 returnValue);
 }
   return returnValue;
  }


 }

And my test class as follows
 
@isTest
   public class Calculator_Tests {

@isTest
 public static void addition() {
    Calculator.addition(1, 0);
   }
@isTest
  public static void subtraction() {
    Calculator.subtraction(1, 0);
   }

@isTest
 public static void divide_throws_exception_for_division_by_zero() {
 Boolean caught = false;
 try {
    Calculator.divide(1, 0);
  } catch (Calculator.CalculatorException e) {
    System.assertEquals('you still can\'t divide by zero', e.getMessage(), 
  'caught the right exception');
    caught = true;
   }
   System.assert(caught, 'threw expected exception');
   }

  @isTest
 public static void divide_throws_exception_for_division_by_two() {
 Boolean caught = true;
 try {
    Calculator.divide(1, 2);
 } catch (Calculator.CalculatorException e) {
    System.assertEquals('you still can\'t divide by zero', e.getMessage(), 
  'caught the right exception');
    caught = true;
   }
   System.assert(caught, 'threw expected exception');
 }


@isTest
public static void multiply_by_one() {
  Boolean caught = false;
  try {
    Calculator.multiply(1, 0);
    } catch (Calculator.CalculatorException e) {
    System.assertEquals('It doesn\'t make sense to multiply by zero', 
    e.getMessage(), 'caught the right exception');
     caught = true;
    }
    System.assert(caught, 'threw expected exception');
  }

@isTest
 public static void multiply_by_two() {
  Boolean caught = true;
  try {
     Calculator.multiply(1, 2);
   } catch (Calculator.CalculatorException e) {
    System.assertEquals('It doesn\'t make sense to multiply by zero', 
  e.getMessage(), 'caught the right exception');
    caught = true;
   }
   System.assert(caught, 'threw expected exception');
}   
}

 
Best Answer chosen by MedhanieHabte
Abdul KhatriAbdul Khatri
How come a division returned a negative value with positive numbers? I don't think that is the right Scenario. 

Infact you can change that not accepting the negative value like this 
 
public static Decimal divide(Integer numerator, Integer denominator){
        if(denominator == 0){
            throw new CalculatorException('you still can\'t divide by zero');
        }
        if(numerator < 0 || denominator < 0)
        	throw new CalculatorException('negative value(s) not allowed.');
        
        Decimal returnValue = numerator / denominator;

        return returnValue;
    }

and add another test method
@isTest
    public static void divide_throws_exception_for_negative_number() {
        Boolean caught = true;
        try {
            Calculator.divide(-1, 2);
        } catch (Calculator.CalculatorException e) {
            System.assertEquals('negative value(s) not allowed.',e.getMessage());
            caught = true;
        }
        System.assert(caught, 'threw expected exception');
    }

I hope this will help.​
Best Answer chosen by abhishek satpute
AbhishekAbhishek (Salesforce Developers) 
May I request you please check the Salesforce documentation on  "SOQL Relationship Queries" check the below link?

https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html   (https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html  )


Basic Examples of SOQL RELATIONSHIPS:
Child > Parent (Standard Object)


Selectid,Account.Name,Account.Phone,Account.industry,Account.Type,Account.Rating,Account.website,Account.Ownership,Account.AnnualRevenue,Account.NumberOfEmployees,Account.CleanStatus from Contact
Child >Parent(Custom Object)


Selectid,COLLEGE__r.Name,COLLEGE__r.Contact__c,COLLEGE__r.Count__c,COLLEGE__r.Highest_Marks__c,COLLEGE__r.Address__cfrom Studnt__c

Parent >Child(Standard object)
select Name, Industry, (select AssistantName, Email from contacts)from ACCOUNT


Parent >Child (Custom Object)
1select id,Name,(select Studnt__c.name__c from Studnts__r) from College__C


For further reference check this,

https://developer.salesforce.com/forums/?id=906F00000009BgeIAE


If it helps you and closes your query by marking it as solved so that it can help others in the future.

Thanks.