• Alex Bondarenko 1
  • NEWBIE
  • 55 Points
  • Member since 2019

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
Trigger:- 

 trigger CreateAttachment on Attachment (after insert, after update) {
        for(integer i =0; i<= Trigger.new.size();i++){
            try{
                ID refid = id.valueof(trigger.new[i].parentid);
                system.debug('xxxxxxxxxxxxxxxxxxxxxxxxx' + refid);
                Id Opportunity15 = string.valueof(trigger.new[i].parentid).substring(0,15);
                if (string.valueof(trigger.new[i].parentid).substring(0,3) == '006'){
                ID contractid = [SELECT id FROM CMC_Contract__c where OpportunityId__c =:  string.valueof(trigger.new[i].parentid).substring(0,15)].id;        
                    if(contractid != null){
                        Attachment ConAttachment = New Attachment(
                        Body = trigger.new[i].Body,
                        IsPrivate = trigger.new[i].IsPrivate,
                        ContentType = trigger.new[i].ContentType,
                        OwnerId = trigger.new[i].OwnerId,
                        Name = trigger.new[i].name,
                        parentid = contractid);
                        insert ConAttachment;

                    }
                }    
        
            } 
            catch(exception ex){
                system.debug('Exception' + ex);
            }
        }
    }

Test Class:- 

@isTest
public class CreateAttachmentTest {

    public static testMethod void Attachmentcreatemethod(){
        
        Test.startTest();
        Account act = new Account(Name='Test Acc');
        insert act;
        MHC2__Project__c proj = new MHC2__Project__c(Name='Test Project3');
        insert proj;
        List<CMC_Contract__c> conList = new List<CMC_Contract__c>();
        CMC_Contract__c c1 = new CMC_Contract__c();
        conList.add(c1);
        insert conList;       
        
        
        Opportunity op = new Opportunity(Name='My Test Opportunity5');
        op.Bid_Date_Time__c = System.Now().addDays(60);
        op.CloseDate = System.Now().addDays(30).date();
        op.StageName = 'Bidding';
        op.AccountId = act.Id;
        op.Bid_Type__c = 'Lump Sum';
        op.Project__c = proj.Id;
        insert op;
        
        Attachment attach=new Attachment();
        attach.Name='Unit Test Attachmnt';
        Blob bodyBlob1=Blob.valueOf('Unit Test Attachment Body1');
        attach.body=bodyBlob1;
        attach.parentId=op.id;
        insert attach;
        
        Test.stopTest();
        
    }
}

Lines highlighted in bold are not covered. i think i am missing to add some oppty id but not sure where it went wrong. Please comment your suggestions


Thanks,
Chandu
How can i add the CustomObject to the Standard Platform user. The Object is visible in SystemAdministrator. And while creating the App for this Object i have added the  Standard Platform user also to the UserProfiles and Included the Custom Object in the Navigation Item. 
Now i am able to access the App and Custom Object only in Admin Profile , Whereas in Standard Platform user profile i have only access to App but not Custom Object.
Please help me on this.
Thanks ,
AJ
<apex:page standardController="Account" recordSetVar="accounts">
    <apex:pageBlock title="Accounts">
        <apex:repeat value="{!Accounts}" var="a">
            <li>
                <apex:outputLink value="/{!a.id}">{!a.Name}</apex:outputLink>
            </li>
        </apex:repeat>
   </apex:pageBlock> 
</apex:page>

BELOW IS THE OUTPUT OF THE ABOVE PROGRAM

output of VF- standard list controller
 
Hi All,

I want to refresh a lightning component for every second, so I'm trying the below code which will call my apex class which is retrieved in the component for evry second. But somehow it doesn't work and i get an error.

window.setInterval(
   $A.getCallback(function() {                      helper.DisplayBusinessHoursForOpenCases(component,helper);
  }), 1000 ); 

I get an error that Uncaught Error in $A.getCallback() [Cannot read property 'DisplayBusinessHoursForOpenCases' of undefined].
I have tried using this.DisplayBusinessHoursForOpenCases, but that doesn't work either.

But the below links show the same example, but this doesn't work in my case.

http://www.infallibletechie.com/2018/04/agetcallback-usage-for-polling-in.html
https://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/

Can anyone please help.

Regards,
Anketha
Hi,

I am showing the value of a date/time field but the format is off.
This is what I would like it to show (as show on the Page Layout):
Format from Page Layout

However this is what it looks like in my component:
Format from component

My code:
<lightning:formattedDateTime value="{!task.Task_LastModifiedDate__c}" timeZone="{!$Locale.timezone}" year="numeric" month="numeric" day="numeric" hour="2-digit" minute="2-digit" hour12="false"/>
Basically I just want to show the standard date/time format.

Thanks,
Michael
Trigger:- 

 trigger CreateAttachment on Attachment (after insert, after update) {
        for(integer i =0; i<= Trigger.new.size();i++){
            try{
                ID refid = id.valueof(trigger.new[i].parentid);
                system.debug('xxxxxxxxxxxxxxxxxxxxxxxxx' + refid);
                Id Opportunity15 = string.valueof(trigger.new[i].parentid).substring(0,15);
                if (string.valueof(trigger.new[i].parentid).substring(0,3) == '006'){
                ID contractid = [SELECT id FROM CMC_Contract__c where OpportunityId__c =:  string.valueof(trigger.new[i].parentid).substring(0,15)].id;        
                    if(contractid != null){
                        Attachment ConAttachment = New Attachment(
                        Body = trigger.new[i].Body,
                        IsPrivate = trigger.new[i].IsPrivate,
                        ContentType = trigger.new[i].ContentType,
                        OwnerId = trigger.new[i].OwnerId,
                        Name = trigger.new[i].name,
                        parentid = contractid);
                        insert ConAttachment;

                    }
                }    
        
            } 
            catch(exception ex){
                system.debug('Exception' + ex);
            }
        }
    }

Test Class:- 

@isTest
public class CreateAttachmentTest {

    public static testMethod void Attachmentcreatemethod(){
        
        Test.startTest();
        Account act = new Account(Name='Test Acc');
        insert act;
        MHC2__Project__c proj = new MHC2__Project__c(Name='Test Project3');
        insert proj;
        List<CMC_Contract__c> conList = new List<CMC_Contract__c>();
        CMC_Contract__c c1 = new CMC_Contract__c();
        conList.add(c1);
        insert conList;       
        
        
        Opportunity op = new Opportunity(Name='My Test Opportunity5');
        op.Bid_Date_Time__c = System.Now().addDays(60);
        op.CloseDate = System.Now().addDays(30).date();
        op.StageName = 'Bidding';
        op.AccountId = act.Id;
        op.Bid_Type__c = 'Lump Sum';
        op.Project__c = proj.Id;
        insert op;
        
        Attachment attach=new Attachment();
        attach.Name='Unit Test Attachmnt';
        Blob bodyBlob1=Blob.valueOf('Unit Test Attachment Body1');
        attach.body=bodyBlob1;
        attach.parentId=op.id;
        insert attach;
        
        Test.stopTest();
        
    }
}

Lines highlighted in bold are not covered. i think i am missing to add some oppty id but not sure where it went wrong. Please comment your suggestions


Thanks,
Chandu
How can i add the CustomObject to the Standard Platform user. The Object is visible in SystemAdministrator. And while creating the App for this Object i have added the  Standard Platform user also to the UserProfiles and Included the Custom Object in the Navigation Item. 
Now i am able to access the App and Custom Object only in Admin Profile , Whereas in Standard Platform user profile i have only access to App but not Custom Object.
Please help me on this.
Thanks ,
AJ