+ Start a Discussion
I want to populate a parent field value in a chaild field for displaying in a standard visual force page. So, I thought I will create a formula field for the same, but one of my collegue said don't create formula field, create a text field and assign the text field value while creating the child record in trigger.

So, I just want to know, which approach is better and why?

NOTE: The parent child relationship is lookup relationship.
Best Answer chosen by Upendra
Hi Upendra,

Formula field values are NOT stored in the database and are calculated after each time records are being read from database. If you can imagine, this can make things slow down. You see, even if values where not changed, formula calculation has still to be processed.
As your friend suggested, it is better to write/update the value during trigger. Thus saving you a process time.

Hope this can help.
Apex developer 21Apex developer 21 
trigger NoteOnContentDocument on ContentDocument (before delete) {
    for (ContentDocument c : Trigger.old){
        List<ContentDocumentLink> links = [
            SELECT LinkedEntityId 
            FROM ContentDocumentLink 
            WHERE ContentDocumentId= :c.Id
        if (Approval.isLocked(links.get(1).LinkedEntityId)){
            c.addError('Approval pending. You do not have the permission to delete this note, Please contact your administrator.');

Best Answer chosen by Apex developer 21
sachin sabusachin sabu
Ok try This
public class NoteOnContentDocument {
    static testmethod void NoteOnContentDoc(){
   ContentVersion contentVersion = new ContentVersion(
      Title = 'Penguins',
      PathOnClient = 'Penguins.jpg',
      VersionData = Blob.valueOf('Test Content'),
      IsMajorVersion = true
    insert contentVersion;

    List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
            delete documents;
        catch(exception e){}

Hello people,

can someone help me, with the following problem.
I have following code in my Lightning component
<lightning:tabset >
    <aura:iteration items="{!v.Items}" var="item">
        <lightning:tab label="{!item}" onactive="{!c.tabClick}">
            <ui:outputtext value="{!item}" />
The problem is the "onactive" attribute of the lightning:tab, Salesforce says: 
Failed to save undefined: The attribute "onactive" was not found on the COMPONENT markup://lightning:tab: Source

But the sfdc documentation states, that the attribute exists

Is it, because tabs are still beta or have I done something wrong?

The Lightning inspector shows me this when I save without onactive:
<lightning:tab onfocus="null" onblur="null"

Thanks and Regards

Best Answer chosen by CarnVanBeck
Ok, it seems, that this is a version issue.
My Org is running on Winter'17 and the onactive attribute is only available in Spring'17
Jugbeer BholaJugbeer Bhola 
Hello, I have an Object with a list inside of of it. The two values I want to retrieve are 'Label' and 'Link.'  How do I get those values.  The error messages keep telling me I need an SObject.  The Object is not an SObject.  Looks something like this.

I want to get the value of 'Label' and 'Link' 
List<Object> OuterTable = new List<Object>();
OuterTable = response.LTable;
        for (Integer i=0;i<OuterTable.size();i++) { 
            System.debug('OK Until here' + OuterTable.get(i));   
//Don't know how to get the rest
Any help would be appreciated.

Best Answer chosen by Jugbeer Bhola
Hi Jugbeer,

probably like this:
List<Object> OuterTable = new List<Object>();
OuterTable = response.LTable;
        for (Object obj : OuterTable) { 
            for (Link link : obj.Link) {
                for (Label label : link.Label) {

Noah ZakariaNoah Zakaria 
went to finish up visualForce  trails/modules on dev org, noticed account name is blocked. already checked profile, heirarchy perm. sets roles cannot seem to solve issue have gone through basic object field level security as well.

Thanks any advice appreciated.

error msg  -> 
core.apexpages.exceptions.ApexPagesHandledException: Object type not accessible. Please check permissions and make sure the object is not in development mode: Name, Phone FROM Account ORDER BY Name ASC LIMIT 10000 ^ ERROR at Row:1:Column:56 encrypted field 'Name' cannot be ordered in a query call. Original queryString was: 'SELECT Id, Industry, Name, Phone FROM Account ORDER BY Name ASC LIMIT 10000' 
Best Answer chosen by Noah Zakaria
hi Noah,

It is not about security. The error states that do not use Name as Order By.
User-added image

you can try to create a formula-string field that will do in the Order By. 

Hope this will help.
Ajay Kumar 261Ajay Kumar 261 

Can anyone suggest me a better formula? This is working fine, however I wanted to see if I get a better formula as it is lengthy one.

CASE( MS_Score__c ,
"0",Profile_Score__c +MS_Score__c,
"1",Profile_Score__c +MS_Score__c,
"2",Profile_Score__c +MS_Score__c,
"3",Profile_Score__c +MS_Score__c,
"4",Profile_Score__c +MS_Score__c,
"A0",Profile_Score__c +RIGHT(MS_Score__c,1),
"A1",Profile_Score__c +RIGHT(MS_Score__c,1),
"A2",Profile_Score__c +RIGHT(MS_Score__c,1),
"A3",Profile_Score__c +RIGHT(MS_Score__c,1),
"A4",Profile_Score__c +RIGHT(MS_Score__c,1),
"B1",Profile_Score__c +RIGHT(MS_Score__c,1),
"B2",Profile_Score__c +RIGHT(MS_Score__c,1),
"B3",Profile_Score__c +RIGHT(MS_Score__c,1),
"B4",Profile_Score__c +RIGHT(MS_Score__c,1),
"C0",Profile_Score__c +RIGHT(MS_Score__c,1),
"C1",Profile_Score__c +RIGHT(MS_Score__c,1),
"C2",Profile_Score__c +RIGHT(MS_Score__c,1),
"C3",Profile_Score__c +RIGHT(MS_Score__c,1),
"C4",Profile_Score__c +RIGHT(MS_Score__c,1),
"D1",Profile_Score__c +RIGHT(MS_Score__c,1),
"D2",Profile_Score__c +RIGHT(MS_Score__c,1),
"D3",Profile_Score__c +RIGHT(MS_Score__c,1),
"D4",Profile_Score__c +RIGHT(MS_Score__c,1),
"E0",Profile_Score__c +RIGHT(MS_Score__c,1),
"E1",Profile_Score__c +RIGHT(MS_Score__c,1),
"E2",Profile_Score__c +RIGHT(MS_Score__c,1),
"E3",Profile_Score__c +RIGHT(MS_Score__c,1),
"E4",Profile_Score__c +RIGHT(MS_Score__c,1),
"U0",Profile_Score__c +RIGHT(MS_Score__c,1),
"U1",Profile_Score__c +RIGHT(MS_Score__c,1),
"U2",Profile_Score__c +RIGHT(MS_Score__c,1),
"U3",Profile_Score__c +RIGHT(MS_Score__c,1),
"U4",Profile_Score__c +RIGHT(MS_Score__c,1),
Best Answer chosen by Ajay Kumar 261

Hi Ajay,

since it seems there is a pattern with your conditions, perhaps you could use 'LEN':
CASE( LEN(MS_Score__c) ,
  1, Profile_Score__c +MS_Score__c,
  2, Profile_Score__c +RIGHT(MS_Score__c,1),

Irvine DelacroixIrvine Delacroix 


I need help on some calculation for my trigger.

Basically, what I would like to do is to get value like if the Result is 16, then this will round to 30, if it's 24 then it will still be 30, if the value is 32 then it will be 45.

What I did was :

integer x = 32;
double y = doubleValueOf(x - math.mod(x)) + 15;

But this doesn't seem to be consistent. Can I have some other sure approach to achieve this?


Best Answer chosen by Irvine Delacroix
this could be done in a simple math manipulation
 y = x + 14 - (math.mod(x + 14,15));
I have a formula field that calculates the value of 2 date/time fields when subtracted 
TEXT(FLOOR( (Paused_End__c - Paused_Start__c) * 24 )) & " Hours " &
TEXT(ROUND((( (Paused_End__c - Paused_Start__c) * 24 )* 60),0)) & " Minute"

and its result is "23  Hours 20 Minute"

How can i add the days as well, what function formula will I use so it will show "2 Days 23 Hours 20 Minute"
Best Answer chosen by redfield
try this,
TEXT( ROUND(Paused_End__c - Paused_Start__c, 0) ) & " Days " &

that should be working now.
Vamshi krishna 26Vamshi krishna 26 

Can someone please help me in covering the test class for the below code and I have tried a lot to cover it to 100% but I am getting 81% 

public with sharing class COCaseComment
    public String test2 {get;set;}
    public String test1 {get;set;}
    public string status {get;set;}

    public void save() {
        Id caseId = ApexPages.currentPage().getParameters().get('caseid');
        SavePoint sp = Database.setSavePoint();
        status = 'unsaved';
        try {
            Case c = [SELECT Id,status,xyz1__c, xyz2__c FROM Case WHERE Id = :caseId FOR UPDATE];
            c.Status = 'Closed';
            insert new casecomment(ParentId = caseId, commentbody = 'Question:'+ '\n' + test1 + '\n' + 'solution :'+ '\n'+ test2 , IsPublished = true);
            update c;
            status = 'saved';
        } catch(Exception e) {
            Apexpages.addMessage(new ApexPages.message(Apexpages.Severity.Error, e.getMessage()));

Test class 

public class TestCustomerOperationsCaseComment
    @isTest public static void withcaseid() {
        case c = new
        case (status = 'New', Origin = 'Phone', xyz1__c= 'AMR', xyz2__c = 'Charting Issues');
        insert c;
        case ca = [select id, status, xyz1__c ,xyz2__c from case where status = 'New'];
        COCaseComment cs = new COCaseComment();
        cs.Test1 = ('test1');
        cs.Test2 = ('test2');
        apexpages.currentPage().getparameters().put('caseid', ca.id);
        if (ca.id != null) {
        casecomment cm = [select commentbody, isPublished from casecomment where parentid =: ca.Id];
        string str = 'Question:'+ '\n' + test1 + '\n' + 'solution:'+ '\n'+ test2 ;
        system.assertEquals(str, cm.CommentBody);
        system.assert(true, cm.ispublished);
        case g = [select Status from case where ID = :ca.Id ];
        system.assertEquals('Closed', g.status);

    @isTest static void caseWithoutproduct() 
            case c = new
            case (status = 'New', Origin = 'Phone', xyz2__c = 'Charting Issues');
            insert c;
            pagereference pr = page.COcaseComment;
            pr.getParameters().put('caseid', c.Id);
            COCaseComment cc = new COCaseComment();
         System.assertEquals('unsaved', cc.status);

Best Answer chosen by Vamshi krishna 26

assign a ca.id that does not exist in the database.
probably like this...
public class TestCustomerOperationsCaseComment
	case g = [select Status from case where ID = :ca.Id ];
	system.assertEquals('Closed', g.status);
	apexpages.currentPage().getparameters().put('caseid', an ID that does not exist or try NULL );
	List<case> h = [select Status from case where ID = :ca.Id ];
	system.assertEquals(0, h.size());

Linda 98Linda 98 
I am having a VF page and class and test class.I am getting 43% code coverage.How can i increae it?
Below is my aoex class which gets value from user on VF page and creates account.

When i debug the test classs,i am not getting account.name value even though i gave a.name='testaccount' in my test class.
So i am able to cover those lines of code.Please help me what am i missing.
public class new_classforpage {
    Public customobjectt__c pr{get;set;}
    Public string accountname{get;set;}
    public string contactname{get;set;}
    public string contactemail{get;set;}
    public Account account {get;set;}

    public new_classforpage(ApexPages.StandardController sc) {
    pr= (object__c )sc.getRecord();
    account=new account();
    Public pagereference save(){
     upsert pr;

    if(accountname!= '' && accountname!= null){
        upsert account;
        contact c=new contact();
        insert c;
        update Pr;
   return new PageReference('/'+pr.Id+'/e?retURL=%2F'+pr.Id);   

and this is my test class:
Public class test_classforpage{
    static testMethod void test(){
        PageReference pref = Page.mypage;
        Account a =new account();

        if(a.name!= '' && a.name!= null){

        upsert a;
        contact c=new contact();
        c.lastname='test contact';
        insert c;
        Purchase_request__c pr =new Purchase_request__c();
        insert pr;
        update pr;

        // Instantiate standard Controller
        ApexPages.StandardController sc = new ApexPages.StandardController(pr);

        // Instantiate controller extension
        myclass  mc = new myclass (sc);

Best Answer chosen by Linda 98
Linda 98,

but you didn't set a value to new_classforpage.accountname.
try adding this to your test class (or perhaps in the new_classforpage)
        myclass  mc = new myclass (sc);