• shan raz
  • NEWBIE
  • 25 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies
Hi,
Need Help writing test class for attachments when cloning I tried and only get to 54%... the clone() is what I need help with.. Please see below:
Trigger:
trigger ZCQAttachment on Attachment (after insert) {
    Set<Id> Parents = new Set<Id>();

    List<Attachment> newFiles = new List<Attachment>();


    for (attachment a : Trigger.New) {
        Parents.add(a.parentId);
    }
System.Debug('NewTriggerParentID+++++' + Parents);

    for (EmailMessage e : [SELECT Id, ParentId,Community_Quote__c FROM EmailMessage WHERE Id in :Parents]) { //loop through unique parents
    System.Debug('NewTriggere+++++' + e);
        for (Attachment a : Trigger.New) {
            if (e.Id == a.ParentId) {
                Attachment newFile = a.clone();
                newFile.ParentId = e.Community_Quote__c;
                newFiles.add(newFile);
            }
        }
    }

    Insert newFiles;
    System.Debug('++++++newFiles' +newFiles);
}

Part of TestClass in regards to that part:
Quote quoterec = [Select Case__c, Id, OpportunityId,AccountId,Case_Thread__c,QuoteNumber From Quote where id=:qt];
        //Insert emailmessage for case
        EmailMessage email = new EmailMessage();
            email.FromAddress = 'test@abc.org';
            email.Incoming = True;
            email.ToAddress= 'test@xyz.org';
            email.Subject = 'Test email';
            email.HtmlBody = 'Test email body';
            email.ParentId = quoterec.Case__c; 
        insert email;
        Attachment attach = new Attachment();

        attach.Name='Unit Test Attachment';
            Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
            attach.body=bodyBlob;
            attach.parentId=quoterec.Case__c;
        insert attach;

                   Community_Quote__c ins = new Community_Quote__c ( 
                        Case__c = quoteRec.Case__c, 
                        Quote__c = quoteRec.Id, 
                        Opportunity__c = quoteRec.OpportunityId, 
                        Account__c = quoteRec.AccountId,
                        ThreadID__c = quoteRec.Case_Thread__c,
                        Name = quoteRec.QuoteNumber,
                        Related_Email_Message__c = email.id );
                insert ins;

                EmailMessage emg = [Select Community_Quote__c from EmailMessage Where Id=:email.id];
                    emg.Community_Quote__c=ins.Id;
                update emg;
        
        Attachment newFile = new Attachment();

        newFile.Name='Unit Test Attachment';
            Blob bodyBlob2=Blob.valueOf('Unit Test Attachment Body');
            newFile.body=bodyBlob;
            newFile.parentId=emg.Community_Quote__c;
        insert newFile;

Code Coverage
Please help thank you
Z​​​​​​​
So I am writing test class for QuoteLineItems and I keep recieving the following error when Quantity is clearly there:

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Quantity]: [Quantity]
QuoteLineItem qliliner = new QuoteLineItem(QuoteId=quoteObj.id,
                                                    Quantity = 1,
                                                    UnitPrice = 5.00,
                                                    Product2Id=producto.id,
                                                    PriceBookEntryID=pbe.Id,
                                                    Tax_Code__c=taxcode);
insert qliliner;

 
Hi,
I like to render the Submit button on VF page only when Status is not equal to null... Or have it grey out and not grey out on disable. 
I tried this but no luck... Please help. Thank you 
<apex:commandButton value="Submit" action="{!saveChanges}" reRender="errormsg" id="add" status="status" rendered="{!If('{!$Component.status}'==null,false,true)}" />

 
Hi,
Hope all is well, need to know how to display message stating "Processing please wait" when user clicks save button on VF page?
Please help
thanks
Z
Hi 
Hope everyone is healthy and safe.
I have 2 checkboxes, Accept or Reject
1 comment box
If user selects Reject checkbox and its true then Comments need to be Required. 
I place this code in 
<apex:inputTextarea value="{!accWrap.comments}" id="cmmts" required="{!IF(!accWrap.rejected==true, true, false)}" />

but it makes it required for everything, even when user selects accept and for all records.
Please see my code below and assist. thank you
<apex:page controller="ZCQController" sidebar="false" docType="html-5.0" lightningStylesheets="true">
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");                  
            for(var i=0; i<inputCheckBox.length; i++){          
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){                                     
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <script>
        function confirmDisbaled(ifchecked, id1 ,id2) {
            document.getElementById(id1).disabled = ifchecked;
            document.getElementById(id2).disabled = ifchecked;
        }
    </script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="All Pending Quotes" collapsible="false" columns="2">
                <apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Quotes" >
                    <apex:column value="{!accWrap.acc.Name}" />
                    <apex:column value="{!accWrap.acc.Quote_Status__c}" />
                    <apex:column value="{!accWrap.acc.Quote_Number__c}" />
                    <apex:column headerValue="Approve">
                        <apex:inputCheckbox value="{!accWrap.approved}" id="inputId2" onchange="return confirmDisbaled(this.checked, '{!$Component.inputId3}');"/>
                    </apex:column>                      
                    <apex:column headerValue="Reject">
                        <apex:inputCheckbox value="{!accWrap.rejected}" id="inputId3" onchange="return confirmDisbaled(this.checked, '{!$Component.inputId2}');"/>
                    </apex:column>
                    <apex:column headerValue="Comments">
                        <apex:inputTextarea value="{!accWrap.comments}" id="cmmts" required="{!IF(!accWrap.rejected==true, true, false)}" />
                    </apex:column>
                </apex:pageBlockTable>          
                <apex:pageBlockTable value="{!att}" var="a" id="table2" title="All Associated Attachments">
                    <apex:column headerValue="Download">
                        <apex:outputLink value="{!URLFOR($Action.Attachment.Download, a.Id)}" target="_blank">View</apex:outputLink>
                    </apex:column>
                    <apex:column value="{!a.Parent.Name}" headerValue="Quote Number"/>
                    <apex:column value="{!a.Name}" headerValue="File Name"/>
                    <apex:column value="{!a.LastModifiedDate}"/>  
                </apex:pageBlockTable>
            </apex:pageblockSection>
        <apex:pageblockSection >
            <apex:commandButton value="Save" action="{!save}" />
        </apex:pageblockSection>  
    </apex:pageBlock>
</apex:form>
</apex:page>

 
Hi everyone,
Hope everyone is safe and healthy...
I have a scenario where clients from community portal will go in and approve or reject there quotes. 
I got the page up and everything but updating the selected record i am having an issue with, especially the picklist value of the selected record.
Record 1 Status selected is Approved
Record 2 Status selected is Declined
They hit Save button
Both Records 1 & 2 will be saved with Declined.
Please Help
VisualForce Page
<apex:page controller="ZAttachmentViewer" showHeader="false" docType="html-5.0" lightningStylesheets="true">
<!--Outputpanel rendered in "acct" not equal to null-->
<!--<apex:outputPanel rendered="{!IF(account != null, true, false)}"> -->
<apex:form >
<apex:pageblock id="acct">

    <apex:pageblockTable value="{!acct}" var="ac">

        <apex:column value="{!ac.Quote_Status__c}" headerValue="Quote Status"/>
        
        <apex:column value="{!ac.Quote_Number__c}" headerValue="Quote Number"/>
        <apex:column value="{!ac.Id}" headerValue="Id"/>
        <apex:column value="{!ac.Status__c}" headerValue="Id"/>
        
        <apex:column headerValue="Approve or Reject here">
            <apex:selectList value="{!details}" size="1">
                <apex:selectOptions value="{!Items}" />
            </apex:selectList>        
        </apex:column>
        
        <apex:column headerValue="Comments">
            <apex:inputTextarea value="{!comments}" id="txtusername"/>     
        </apex:column>
        

        
        <apex:column headerValue="Approve/Reject Here">
            <apex:commandButton value="Approve/Reject " action="{!Submit}"/>  
        </apex:column>        

</apex:pageblockTable>
<apex:pageblockSection >
<apex:commandButton value="Approve/Reject " action="{!Submit}"/> 
</apex:pageblockSection>
                       
</apex:pageblock>

<apex:pageblock id="attachment" title="Attachments" >

    <apex:pageblockTable value="{!att}" var="a">
    
        <apex:column headerValue="Download">
            <apex:outputLink value="{!URLFOR($Action.Attachment.Download, a.Id)}" target="_blank">View</apex:outputLink>
        </apex:column>
        <apex:column value="{!a.Parent.Name}" headerValue="Quote Number"/>
        <apex:column value="{!a.Name}" headerValue="File Name"/>
        <apex:column value="{!a.LastModifiedDate}"/>  
   
   </apex:pageblockTable>
   
   
</apex:pageblock>   

</apex:form>
<!-- </apex:outputPanel>-->
</apex:page>
Apex Code:
public with sharing class ZAttachmentViewer{


    //private ApexPages.StandardController controller {get; set;}
    public List<Attachment> att{get;set;}
    public List<Community_Quote__c> acct{get;set;}  
    public List<Community_Quote__c> qqq = new List<Community_Quote__c>();
    public String StatusInput {get;set;}
    public String errorMessage { get; set; }
    public String details{get; set;}
    public String comments{get;set;}

    // standard controller - could also just use custom controller
    public ZAttachmentViewer(ApexPages.StandardController controller) {}

    public ZAttachmentViewer() {

        //Get UserId of the current user
        String usrid = UserInfo.getUserId();
        System.Debug('+++++++++UserID++++' + usrid);    
        
        //Run the Userid that we recieved and get the Account Id associated with it         
        User recordId = [SELECT AccountId__c FROM User Where ID=:usrid];
        System.Debug('+++++++++recordId++++' + recordId);
        
        account = recordId.AccountId__c;
        
        //Check to see if we get the Account ID
        System.Debug('+++++++++AccountId++++' + recordId.AccountId__c);
        
            
        //Use the AccountId into query to get results
        acct = [Select Id, Name,Account__c,Case__c,Quote_Status__c,
                Quote_Number__c,Comment__c, Status__c 
                from Community_Quote__c 
                where 
                Account__c=:recordId.AccountId__c 
                and 
                Quote_Status__c='Proposed to Client'];
        
        att = [select Id,ContentType,ParentId,Parent.Type,Parent.Name,OwnerId,Owner.Name, Name, LastModifiedDate, BodyLength from Attachment where ParentId = :acct];
        
        
    }
  
    public String options { get; set; }

     public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new selectOption('None', ' None '));
        options.add(new SelectOption('Accepted by Client','Accepted by Client'));
        options.add(new SelectOption('Rejected','Rejected'));
        return options;

    }
    

    public PageReference Submit() {
    
    List<Community_Quote__c> cpqlist = [select Id,Status__c,Comment__c,Quote__c from Community_Quote__c where Id=:acct];
        
        if(!cpqlist.isEmpty()) {
            for(Community_Quote__c ccc: accountIds){
                ccc.Status__c = details;
                ccc.Comment__c = comments;
                qqq.add(ccc);   

            }

        update qqq;
        }

    return null;
    }
}


 
Hi 
Hope everyone is healthy and safe.
I have 2 checkboxes, Accept or Reject
1 comment box
If user selects Reject checkbox and its true then Comments need to be Required. 
I place this code in 
<apex:inputTextarea value="{!accWrap.comments}" id="cmmts" required="{!IF(!accWrap.rejected==true, true, false)}" />

but it makes it required for everything, even when user selects accept and for all records.
Please see my code below and assist. thank you
<apex:page controller="ZCQController" sidebar="false" docType="html-5.0" lightningStylesheets="true">
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");                  
            for(var i=0; i<inputCheckBox.length; i++){          
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){                                     
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <script>
        function confirmDisbaled(ifchecked, id1 ,id2) {
            document.getElementById(id1).disabled = ifchecked;
            document.getElementById(id2).disabled = ifchecked;
        }
    </script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="All Pending Quotes" collapsible="false" columns="2">
                <apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Quotes" >
                    <apex:column value="{!accWrap.acc.Name}" />
                    <apex:column value="{!accWrap.acc.Quote_Status__c}" />
                    <apex:column value="{!accWrap.acc.Quote_Number__c}" />
                    <apex:column headerValue="Approve">
                        <apex:inputCheckbox value="{!accWrap.approved}" id="inputId2" onchange="return confirmDisbaled(this.checked, '{!$Component.inputId3}');"/>
                    </apex:column>                      
                    <apex:column headerValue="Reject">
                        <apex:inputCheckbox value="{!accWrap.rejected}" id="inputId3" onchange="return confirmDisbaled(this.checked, '{!$Component.inputId2}');"/>
                    </apex:column>
                    <apex:column headerValue="Comments">
                        <apex:inputTextarea value="{!accWrap.comments}" id="cmmts" required="{!IF(!accWrap.rejected==true, true, false)}" />
                    </apex:column>
                </apex:pageBlockTable>          
                <apex:pageBlockTable value="{!att}" var="a" id="table2" title="All Associated Attachments">
                    <apex:column headerValue="Download">
                        <apex:outputLink value="{!URLFOR($Action.Attachment.Download, a.Id)}" target="_blank">View</apex:outputLink>
                    </apex:column>
                    <apex:column value="{!a.Parent.Name}" headerValue="Quote Number"/>
                    <apex:column value="{!a.Name}" headerValue="File Name"/>
                    <apex:column value="{!a.LastModifiedDate}"/>  
                </apex:pageBlockTable>
            </apex:pageblockSection>
        <apex:pageblockSection >
            <apex:commandButton value="Save" action="{!save}" />
        </apex:pageblockSection>  
    </apex:pageBlock>
</apex:form>
</apex:page>

 
So I am writing test class for QuoteLineItems and I keep recieving the following error when Quantity is clearly there:

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Quantity]: [Quantity]
QuoteLineItem qliliner = new QuoteLineItem(QuoteId=quoteObj.id,
                                                    Quantity = 1,
                                                    UnitPrice = 5.00,
                                                    Product2Id=producto.id,
                                                    PriceBookEntryID=pbe.Id,
                                                    Tax_Code__c=taxcode);
insert qliliner;

 
Hi,
I like to render the Submit button on VF page only when Status is not equal to null... Or have it grey out and not grey out on disable. 
I tried this but no luck... Please help. Thank you 
<apex:commandButton value="Submit" action="{!saveChanges}" reRender="errormsg" id="add" status="status" rendered="{!If('{!$Component.status}'==null,false,true)}" />

 
Hi,
Hope all is well, need to know how to display message stating "Processing please wait" when user clicks save button on VF page?
Please help
thanks
Z
Hi everyone,
Hope everyone is safe and healthy...
I have a scenario where clients from community portal will go in and approve or reject there quotes. 
I got the page up and everything but updating the selected record i am having an issue with, especially the picklist value of the selected record.
Record 1 Status selected is Approved
Record 2 Status selected is Declined
They hit Save button
Both Records 1 & 2 will be saved with Declined.
Please Help
VisualForce Page
<apex:page controller="ZAttachmentViewer" showHeader="false" docType="html-5.0" lightningStylesheets="true">
<!--Outputpanel rendered in "acct" not equal to null-->
<!--<apex:outputPanel rendered="{!IF(account != null, true, false)}"> -->
<apex:form >
<apex:pageblock id="acct">

    <apex:pageblockTable value="{!acct}" var="ac">

        <apex:column value="{!ac.Quote_Status__c}" headerValue="Quote Status"/>
        
        <apex:column value="{!ac.Quote_Number__c}" headerValue="Quote Number"/>
        <apex:column value="{!ac.Id}" headerValue="Id"/>
        <apex:column value="{!ac.Status__c}" headerValue="Id"/>
        
        <apex:column headerValue="Approve or Reject here">
            <apex:selectList value="{!details}" size="1">
                <apex:selectOptions value="{!Items}" />
            </apex:selectList>        
        </apex:column>
        
        <apex:column headerValue="Comments">
            <apex:inputTextarea value="{!comments}" id="txtusername"/>     
        </apex:column>
        

        
        <apex:column headerValue="Approve/Reject Here">
            <apex:commandButton value="Approve/Reject " action="{!Submit}"/>  
        </apex:column>        

</apex:pageblockTable>
<apex:pageblockSection >
<apex:commandButton value="Approve/Reject " action="{!Submit}"/> 
</apex:pageblockSection>
                       
</apex:pageblock>

<apex:pageblock id="attachment" title="Attachments" >

    <apex:pageblockTable value="{!att}" var="a">
    
        <apex:column headerValue="Download">
            <apex:outputLink value="{!URLFOR($Action.Attachment.Download, a.Id)}" target="_blank">View</apex:outputLink>
        </apex:column>
        <apex:column value="{!a.Parent.Name}" headerValue="Quote Number"/>
        <apex:column value="{!a.Name}" headerValue="File Name"/>
        <apex:column value="{!a.LastModifiedDate}"/>  
   
   </apex:pageblockTable>
   
   
</apex:pageblock>   

</apex:form>
<!-- </apex:outputPanel>-->
</apex:page>
Apex Code:
public with sharing class ZAttachmentViewer{


    //private ApexPages.StandardController controller {get; set;}
    public List<Attachment> att{get;set;}
    public List<Community_Quote__c> acct{get;set;}  
    public List<Community_Quote__c> qqq = new List<Community_Quote__c>();
    public String StatusInput {get;set;}
    public String errorMessage { get; set; }
    public String details{get; set;}
    public String comments{get;set;}

    // standard controller - could also just use custom controller
    public ZAttachmentViewer(ApexPages.StandardController controller) {}

    public ZAttachmentViewer() {

        //Get UserId of the current user
        String usrid = UserInfo.getUserId();
        System.Debug('+++++++++UserID++++' + usrid);    
        
        //Run the Userid that we recieved and get the Account Id associated with it         
        User recordId = [SELECT AccountId__c FROM User Where ID=:usrid];
        System.Debug('+++++++++recordId++++' + recordId);
        
        account = recordId.AccountId__c;
        
        //Check to see if we get the Account ID
        System.Debug('+++++++++AccountId++++' + recordId.AccountId__c);
        
            
        //Use the AccountId into query to get results
        acct = [Select Id, Name,Account__c,Case__c,Quote_Status__c,
                Quote_Number__c,Comment__c, Status__c 
                from Community_Quote__c 
                where 
                Account__c=:recordId.AccountId__c 
                and 
                Quote_Status__c='Proposed to Client'];
        
        att = [select Id,ContentType,ParentId,Parent.Type,Parent.Name,OwnerId,Owner.Name, Name, LastModifiedDate, BodyLength from Attachment where ParentId = :acct];
        
        
    }
  
    public String options { get; set; }

     public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new selectOption('None', ' None '));
        options.add(new SelectOption('Accepted by Client','Accepted by Client'));
        options.add(new SelectOption('Rejected','Rejected'));
        return options;

    }
    

    public PageReference Submit() {
    
    List<Community_Quote__c> cpqlist = [select Id,Status__c,Comment__c,Quote__c from Community_Quote__c where Id=:acct];
        
        if(!cpqlist.isEmpty()) {
            for(Community_Quote__c ccc: accountIds){
                ccc.Status__c = details;
                ccc.Comment__c = comments;
                qqq.add(ccc);   

            }

        update qqq;
        }

    return null;
    }
}