• Huy Nguyen
  • NEWBIE
  • 80 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 28
    Questions
  • 26
    Replies
Hi all,

I have attach the custom button in the contact object . But it does not show in contact object at target organization. I need manually add it to the contact page layout. Is there any way to add it auto when the package is installed successfully ?

Thanks and regards
Hi all,

I override delete button in contact object but I can not find that button when package the apps. Can any one help me ?
User-added imageUser-added image
 
Hi expert, I have controller below but i got the error from the title. Could any one to take a look that issue ?

public class demo {
    
    private ApexPages.standardcontroller stdCtrl;
    private final String serviceEndpoint= 'http://md5.jsontest123.com/';
    public Contact contact;
    public boolean displayPopup {get; set;}     
    public String Response { get; set;}
    public String Headers { get; set; }
    public demo(ApexPages.standardController controller)
    {    
        stdCtrl = controller;
        this.contact = (Contact)controller.getRecord();
        contact  = [Select name,email from Contact where id=:contact.id limit 1];
        sendEmail();
    }
    
    public PageReference doDelete()
    { 
        PageReference ref = stdCtrl.delete(); 
        ref.getParameters().put('nooverride','1');
        return ref;
    }
    
    public boolean sendReq() 
    {
        //String conName = contact.Name;
        boolean validated= true;
        String ERR_503 = 'Service Unavailable. Can not access webservice at the moment';
        String errorMessage = '';
        Integer httpStatusCode = 0;
        String httpStatus = '';
        String resBody = '';
        
        // Get the XML document from the external server
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(serviceEndpoint+'?text='+contact.Name);
        
        req.setMethod('GET');
        HttpResponse res = http.send(req);
        httpStatusCode = res.getStatusCode();
        httpStatus = res.getStatus();
        resBody = res.getBody();
        System.debug(httpStatusCode);
        System.debug(httpStatus);
        System.debug(resBody);
        if (httpStatusCode == 200)
        {
            validated= true;
            system.debug('validated'+validated);
            
            //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info,'1'));
            //showPopup();
            
        }
        
        else if(httpStatusCode == 503)
        {
            validated= false;
            errorMessage +=ERR_503;
            throw new errorException(errorMessage);
        }
        return true;
    }
    
    public void closePopup() {        
        displayPopup = false;    
    }
    
    public void showPopup() {        
        displayPopup = true;    
    }
    public void sendEmail()
    {
        system.debug('sendReq'+sendReq());
        if(sendReq())
        {
            displayPopup = true; 
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();        
            String[] toAddress = new String[] {contact.Email};
            email.setToAddresses(toAddress);
            email.setSubject('Deleted Contact Alert');
            email.setPlainTextBody('This message is to alert you that the contact named ' + contact.Name + ' has been deleted.');
            emails.add(email);
            Messaging.sendEmail(emails);         
        }
        
    }   
}
test class :

@isTest(SeeAllData=false)
public class testdemoController {
    static Contact cont;    
      @isTest static void testNormalCase(){
        Init();
        System.Test.setMock(HttpCalloutMock.class, new ExampleCalloutMock());
        demo controller = new demo(new ApexPages.StandardController(cont));
        controller.doDelete();
    }
    static void Init()
    {
        System.Test.startTest();
        Account acct = new Account(Name='test');
        insert acct;
        cont = new Contact(Email='nlhuy@tma.com.vn',LastName='TestCont');
        insert cont;
        System.Test.stopTest();
    }
    
}
Hi expert,

I am new in web service region. can any one help me to give an example apex class how to send data from salesforce to external system ?

Thanks
Hi expert .

Can anyone show me an example code for that ? Thank a lot
Hi all,

I want to overide the delete button from the contact object. when i click del . it will appear different message ? Can anyone help me to handle it ?
Hi all,

I have requirement with add 1 & 5 row. it is ok with attachment in there. but it is not worked with the delete function.It show the error apex input file with conjuntion. Can any one help. This is my VF page :

<apex:page controller="LobbyEditRelatedContactController" tabStyle="Clients_Employees__tab" title="Clients & Employees">
    
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"/>
    
    <script>
        
        $(document).ready(function() {
        $("#GvCHX").click(function() {
            $("#GvCHXDetails").toggle(this.checked);
        }).triggerHandler('click');
    });
    
    </script>
    
    <apex:form >
        <apex:pageBlock title="Client"  rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Client']}">
            <apex:pageBlockTable value="{!lstContactWrappers}" var="wrapper" id="wtable">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!wrapper.contact.Lobbyists_Appointment__c}"/>
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!wrapper.contact.Client_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="ABN">
                    <apex:inputField value="{!wrapper.contact.ABNUSER__c}"/>
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Delete" action="{!delRow}" rerender="wtable" immediate="true">
                        <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelrow}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlock>
        <apex:pageBlock title="Employee" rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Employee']}">
            <apex:pageBlockTable value="{!lstContactWrappers}" var="wrapper" id="wtable1">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!wrapper.contact.Lobbyists_Appointment__c}" />
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!wrapper.contact.Employee_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="Position">
                    <apex:inputField value="{!wrapper.contact.Position__c}"/>
                </apex:column>
                <apex:column headerValue="NSW Gov board ?">
                    <apex:inputCheckbox id="GvCHX" value="{!wrapper.contact.Government_Board_or_Committee_Member__c}" immediate="true"/>
                </apex:column>
                <apex:column headerValue="Details">
                    <apex:inputField id="GvCHXDetails" label="details" value="{!wrapper.contact.Details__c}"/>
                </apex:column>
                <apex:column headerValue="Add Declaration" >
                    <apex:inputFile value="{!wrapper.att.body}" filename="{!wrapper.att.name}"/>                    
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:actionRegion >
                        <apex:commandButton value="Delete" action="{!delRow}" reRender="wtable1">
                            <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelrow}"/>
                        </apex:commandButton>
                    </apex:actionRegion>
                </apex:column>
            </apex:pageBlockTable>
            <!-- apex:actionregion tag is required in case using apex:inputFile with any apex tag with 'rerender' attribute within the same apex:form -->
            <apex:actionregion >
                <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable1" immediate="true">
                    <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
                </apex:commandButton>
                <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable1" immediate="true">
                    <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
                </apex:commandButton>
            </apex:actionregion>
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Hi all,

I have a page below with the field the file to be attached when save record. Can anyone help me ?

<apex:page controller="LobbyEditRelatedContactController" tabStyle="Clients_Employees__tab" title="Clients & Employees">
    
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"/>
    
    <script>
        
        $(document).ready(function() {
        $("#GvCHX").click(function() {
            $("#GvCHXDetails").toggle(this.checked);
        }).triggerHandler('click');
    });
    
    </script>
    
    <div id="GvCHXDetails">test</div>
    
    <apex:form >
        <apex:pageBlock title="Client"  rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Client']}">
            <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!Contacts.contact.Lobbyists_Appointment__c}"/>
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!Contacts.contact.Client_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="ABN">
                    <apex:inputField value="{!Contacts.contact.ABNUSER__c}"/>
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Delete" action="{!delRow}" rerender="wtable" immediate="true">
                        <apex:param name="toDelIdent" value="{!Contacts.ident}" assignTo="{!toDelrow}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlock>
        <apex:pageBlock title="Employee" rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Employee']}">
            <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable1">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!Contacts.contact.Lobbyists_Appointment__c}" />
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!Contacts.contact.Employee_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="Position">
                    <apex:inputField value="{!Contacts.contact.Position__c}"/>
                </apex:column>
                <apex:column headerValue="NSW Gov board ?">
                    <apex:inputCheckbox id="GvCHX" value="{!Contacts.contact.Government_Board_or_Committee_Member__c}" immediate="true"/>
                </apex:column>
                <apex:column headerValue="Details">
                    <apex:inputField id="GvCHXDetails" label="details" value="{!Contacts.contact.Details__c}"/>
                </apex:column>
                <!--<apex:column headerValue="Active">
<apex:inputCheckbox value="{!Contacts.cont.Active__c}" />
</apex:column>--> <!--this will be defaulted to TRUE on any new entry-->
                <apex:column headerValue="Add Declaration">
                    <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Delete" action="{!delRow}" rerender="wtable1" immediate="true">
                        <apex:param name="toDelIdent" value="{!Contacts.ident}" assignTo="{!toDelrow}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable1" immediate="true">
                <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable1" immediate="true">
                <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}"/>
     
        </apex:pageBlock>
    </apex:form>
</apex:page>
Hi all,

I VF page below and have 2 URL
lobbyEditrelatedcontact?RecordType=01290000000iHY6
lobbyEditrelatedcontact?RecordType=01290000000iHYB

the first one for employee and second for the client . How can i assign VF page with record type and URL above

<apex:page controller="LobbyEditRelatedContactController" tabstyle="Account">
 <apex:form >
   <apex:pageBlock title="Client">
      <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable">
         <apex:column headerValue="Appointment">
            <apex:inputField value="{!Contacts.cont.Lobbyists_Appointment__c}"/>
         </apex:column>
         <apex:column headerValue="Name">
              <apex:inputField value="{!Contacts.cont.Client_NameUSER__c}"/>
         </apex:column>
         <apex:column headerValue="ABN">
         <apex:inputField value="{!Contacts.cont.ABNUSER__c}"/>
         </apex:column>
         <apex:column headerValue="Action">
             <!--<apex:commandButton value="Remove Row" action="{!delWrapper}" rerender="wtable">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/>-->
         </apex:column>
      </apex:pageBlockTable>
      <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable" immediate="true">
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" immediate="true">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlock>
   <apex:pageBlock title="Employee">
      <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable1">
         <apex:column headerValue="Appointment">
            <apex:inputField value="{!Contacts.cont.Lobbyists_Appointment__c}"/>
         </apex:column>
         <apex:column headerValue="Name">
            <apex:inputField value="{!Contacts.cont.Employee_NameUSER__c}"/>
         </apex:column>
         <apex:column headerValue="Position">
            <apex:inputField value="{!Contacts.cont.Position__c}"/>
         </apex:column>
         <apex:column headerValue="NSW Gov board ?">
            <apex:inputCheckbox id="GvCHX" onchange="slideToggle" value="{!Contacts.cont.Government_Board_or_Committee_Member__c}"/>
         </apex:column>
         <apex:column headerValue="Details">
         
            <div id="GvCHXDetails" style="display:none">Age is something</div>
            
            <!--<apex:inputField id="GvCHXDetails" label="details" value="{!Contacts.cont.Details__c}"/>-->
         </apex:column>
         <!--<apex:column headerValue="Active">
              <apex:inputCheckbox value="{!Contacts.cont.Active__c}" />
         </apex:column>--> <!--this will be defaulted to TRUE on any new entry-->
             <apex:column headerValue="Add Declaration">
             <apex:inputCheckbox value="{!Contacts.cont.Declaration_Attached__c}" />
         </apex:column>
         <apex:column headerValue="Action">
             <!--<apex:commandButton value="Remove Row" action="{!delWrapper}" rerender="wtable">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/>-->
         </apex:column>
      </apex:pageBlockTable>
      <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlock>
 </apex:form>
</apex:page>
Hi all,

I have a page below :I have 2 record type :Client and Employee when we click add new it will redirect to according function. In here I create a page with 2 section appear together. How can I handle this requirement. The below page only appear with 1 section
<apex:page controller="LobbyEditRelatedContactController" tabstyle="Account">
 <apex:form >
   <apex:pageBlock title="Client">
      <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable">
         <apex:column headerValue="Appointment">
            <apex:inputField value="{!Contacts.cont.Lobbyists_Appointment__c}"/>
         </apex:column>
         <apex:column headerValue="Name">
              <apex:inputField value="{!Contacts.cont.Client_NameUSER__c}"/>
         </apex:column>
         <apex:column headerValue="ABN">
         <apex:inputField value="{!Contacts.cont.ABNUSER__c}"/>
         </apex:column>
      </apex:pageBlockTable>
      <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable" immediate="true">
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" immediate="true">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlock>
   <apex:pageBlock title="Employee">
      <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable1">
         <apex:column headerValue="Appointment">
            <apex:inputField value="{!Contacts.cont.Lobbyists_Appointment__c}"/>
         </apex:column>
         <apex:column headerValue="Name">
            <apex:inputField value="{!Contacts.cont.Employee_NameUSER__c}"/>
         </apex:column>
         <apex:column headerValue="Position">
            <apex:inputField value="{!Contacts.cont.Position__c}"/>
         </apex:column>
            <apex:column headerValue="NSW Gov board ?">
            <apex:inputCheckbox value="{!Contacts.cont.Government_Board_or_Committee_Member__c}"/>
         </apex:column>
            <apex:column headerValue="Details">
            <apex:inputField value="{!Contacts.cont.Details__c}"/>
         </apex:column>
             <apex:column headerValue="Active">
              <apex:inputCheckbox value="{!Contacts.cont.Active__c}" />
         </apex:column>
             <apex:column headerValue="Add Declaration">
             <apex:inputCheckbox value="{!Contacts.cont.Declaration_Attached__c}" />
         </apex:column>
      </apex:pageBlockTable>
      <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlock>
 </apex:form>
</apex:page>

 
Hi expert,

I have requirement in the subject . I have 2 record type :client and employee . When we choose each record it will display the VF page base on record type with different field. How can i handle it ?
Hi all,

For example . I have 2 recordtype :client and employee and the current page we select View list for each record type it will display the different layout. Is there any way to display 2 view in 1 VF page ? get the ID of view list and display on VF page
Hi all,

I have requirement to display 2 recordtype in one page. 2 section for example :client and employee. when I click new button it will display 2 page layout base on the recordtype . Could any one sugggest how to solve this requirement ?

 
Hi all,

I got that error in this code. Can anyone advise  ?

  Map<String,Line_Item_Type__c> newLineItemMap = new Map<String, Line_Item_Type__c>();
                for(Line_Item_Type__c lineItem : [SELECT Id,Line_Item_Category_Text__c,Line_Item_Type_Aggregated_Category__c,Name FROM Line_Item_Type__c where id =: trigger.new] )       
                {
                     newLineItemMap.put(lineItem.Line_Item_Type_Aggregated_Category__c, lineItem);
                }
Hi expert,

I have trigger below and it got soql exception. I just join project few days so I do not understand the logic of the flow. Can any one advise to improve the code. I see SOQL in for loop:
     if (Trigger.isInsert) {
                
                LineItemFormController.isInsertTrigger = true;
                for(Line_Item__c item :Trigger.New){
                if ((lineItemRecordType != '') && (item.Cloned_Line_Item__c == null) && (item.RecordTypeId == lineItemRecordType)) {
                    lineItemIds.add(item.Id);
                    if (lineItemMaps.get(item.Id) == null) {
                        lineItemMaps.put(item.Id, new List<Line_Item__c>());
                    }
                    }
                }
                
                List<Line_Item__c> oldAuditLineItems = [SELECT Id,Line_Item__c, Active__c, Line_Item_Status__c
                                                    FROM Line_Item__c
                                                    WHERE RecordTypeId =:auditRecordType
                                                    AND Active__c = true
                                                    //US5105
                                                    AND Line_Item_Status__c != 'Audited'
                                                    AND Line_Item__c IN :lineItemIds
                                                   ];
                for (Line_Item__c auditItem : oldAuditLineItems) {
                    lineItemMaps.get(auditItem.Line_Item__c).add(auditItem);
                }
                System.Debug('nghiatran: Insert ' + isUpdate);
                System.Debug('vinhvinh: Come to Insert Audit trigger');
                for(Line_Item__c item :Trigger.New){
                    Line_Item_Type__c lineItemType  = [SELECT Id,Line_Item_Category_Text__c,Line_Item_Type_Aggregated_Category__c,Name FROM Line_Item_Type__c where id =: item.Line_Item_Type__c limit 1];
                    if ((item.Cloned_Line_Item__c == null) && (item.RecordTypeId == lineItemRecordType)) {
                        // US6137 insert start
                        system.debug('nghiatran lineItemType.Line_Item_Type_Aggregated_Category__c ' + lineItemType.Line_Item_Type_Aggregated_Category__c);
                        if(lineItemType.Line_Item_Type_Aggregated_Category__c == 'Electoral Expenditure' ||
                            lineItemType.Line_Item_Type_Aggregated_Category__c == 'Small Donations Made' ||
                            lineItemType.Line_Item_Type_Aggregated_Category__c == 'Small Donations Received')
                            return;
                        // US6137 insert end
                       if (lineItemMaps.get(item.Id).size() == 0 ) {
                           system.debug('nghiatran access insert after ' + lineItemType.Line_Item_Type_Aggregated_Category__c);
                            Line_Item__c temp = item.Clone(false,true);
                            temp.Line_Item__c = item.Id;
                            temp.Line_Item_Type__c = item.Line_Item_Type__c;
                            temp.RecordTypeId = auditRecordType;
                            temp.Active__c = true;
                            temp.Line_Item_Status__c = 'Not Audited';
                            newAuditLineItems.add(temp);
                        }
                    }
                }
            }
Hi Expert. I have a code below. Can anyone help to fix to avoid SOQL exception :

List<RecordType> recordTypes = [SELECT Id, Name FROM RecordType Where Name='Non-Compliance' Limit 1];
        String recordTypeId=recordTypes[0].Id;
        
        for(Task item : taskUpsertList){
            List<Non_Compliance__c> newNonComplianceList = mapNonCompliance.get(item.Subject.substring(0,4));
            for(Non_Compliance__c nc : newNonComplianceList){
                item.Subject = nc.Name;
                item.Legislative_Reference__c = nc.Legislative_Reference__c;
                item.Compliance_Issue__c = nc.Compliance_Issue__c;
                item.Offence_Reference__c = nc.Offence_Reference__c;
                item.Offender__c = nc.Offender__c;
                item.Offence_Penalty__c = nc.Offence_Penalty__c;
                item.Penalty_Notice_Penalty__c = nc.Penalty_Notice_Penalty__c;
                item.Outcome__c = nc.Outcome__c;
                item.Type = nc.RecordType.Name;
                item.Description = nc.Comments__c;
                item.Priority = nc.Priority__c;
                if(nc.RecordType.Name == 'Line Item Non-Compliance'){
                    item.Line_Item_Category_Id__c  = nc.Line_Item_Category__r.Id;
                }
                item.Non_Compliance_Id__c = nc.Id;
                item.Non_Compliance_Number__c = nc.Non_Compliance_Number__c;
                item.RecordTypeId = recordTypeId;
            }
        }
Hi Expert,

I have test class and trigger below. when I run test class it thrown too many SOQL in the trigger. Could any one help to fix it ?
Test class
@isTest(SeeAllData=true)
public with sharing class TestNonComplianceCreateController{
    static Disclosure_Claim_for_Payment__c dcp;
    
    static Non_Compliance__c nci;
    static testMethod void newTest() {
        InitialData();
        Test.SetCurrentPage(Page.NonComplianceCreate);
        
        List<RecordType> recordTypes = [SELECT Id, Name FROM RecordType Where Name='Non-Compliance' Limit 1];       
        String recordTypeId=recordTypes[0].Id;
        ApexPages.CurrentPage().GetParameters().Put('retURL', '/' + dcp.Id);
        ApexPages.CurrentPage().GetParameters().Put('what_id', dcp.Id);
              
        //System.Debug('aaa ' + str);
        //ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, '/' + dcp.Id));
        
        ApexPages.StandardController sc = new ApexPages.StandardController(new Task());          
        NonComplianceCreateController controller = new NonComplianceCreateController(sc);
        controller.GetAllTaskFieldSet();
        controller.Entity.Non_Compliance_Id__c = nci.Id;
        controller.Save();
        
        //For Exception => not set retURL
        Test.SetCurrentPage(Page.NonComplianceCreate);
        ApexPages.CurrentPage().GetParameters().Put('RecordType', recordTypeId);
        ApexPages.StandardController sc1 = new ApexPages.StandardController(new Task());          
        NonComplianceCreateController controller1 = new NonComplianceCreateController(sc1);
        controller1.Entity.Non_Compliance_Id__c = nci.Id;
        controller1.Save();
        
        //For Test NonComplianceTrigger
        nci.Name='Updated Test';
        upsert nci;
    }
    static void InitialData()
    {
        Map<String, String> listRecordType = new Map<String,String>();
        for (RecordType r : [SELECT Id, Name FROM RecordType]) {
            listRecordType.put (r.Name, r.Id);
        }
        Account accountPerson = new Account(LastName = 'Test', FirstName='Name',RecordTypeId=listRecordType.get('Person') );
        upsert accountPerson;
        
        dcp = new Disclosure_Claim_for_Payment__c(isTemplate__c=false,RecordTypeId=listRecordType.get('Disclosure (Major Political Donor)'), Stakeholder__c = accountPerson.Id);
        upsert dcp;
        
        List<Line_Item_Category__c> listLIC = new List<Line_Item_Category__c>();
        List<Line_Item_Category__c> listlic1 = [SELECT Id, Add_Row__c, Reference_Number__c FROM Line_Item_Category__c WHERE Reference_Number__c = '1009'];
        Line_Item_Category__c lic1;
        if(listlic1.size() > 0){
             lic1 = listlic1[0];
            listLIC.add(lic1);
        }else{
            lic1 = new Line_Item_Category__c(Add_Row__c=true,Reference_Number__c='1009');
            listLIC.add(lic1);        
        }
        List<Line_Item_Category__c> listlic2 = [SELECT Id, Add_Row__c, Reference_Number__c FROM Line_Item_Category__c WHERE Reference_Number__c = '1010'];
        Line_Item_Category__c lic2;
        if(listlic2.size() > 0){
             lic2 = listlic2[0];
            listLIC.add(lic2);
        }else{
            lic2 = new Line_Item_Category__c(Add_Row__c=true,Reference_Number__c='1010');
            listLIC.add(lic2);        
        }
        //Line_Item_Category__c lic1 = new Line_Item_Category__c(Add_Row__c=true,Reference_Number__c='1009');
        //upsert lic1;
        //Line_Item_Category__c lic2 = new Line_Item_Category__c(Add_Row__c=true,Reference_Number__c='1010');
        //upsert lic2;
        system.debug('Huy test: ' + Limits.getLimitQueries());
        Line_Item_Type__c lit1 = new Line_Item_Type__c(Line_Item_Category__c=lic1.Id,Disclosure_Claim_for_Payment__c=dcp.Id);
        upsert lit1;
        system.debug('Huy test: ' + Limits.getLimitQueries());
        Line_Item_Type__c lit2 = new Line_Item_Type__c(Line_Item_Category__c=lic2.Id,Disclosure_Claim_for_Payment__c=dcp.Id);
        upsert lit2;
        system.debug('Huy test: ' + Limits.getLimitQueries());
        Line_Item__c li = new Line_Item__c(Line_Item_Type__c = lit1.Id);
        upsert li; // it thrown exception here
        
        system.debug('Huy test: ' + Limits.getLimitQueries());
        nci = new Non_Compliance__c(Name='test',Legislative_Reference__c='test',Compliance_Issue__c='test',
                                    RecordTypeId=listRecordType.get('Disclosure Non-Compliance'));
        upsert nci;
        system.debug('Huy test: ' + Limits.getLimitQueries());
    }
}

and the trigger .I just paste a part of the trigger and the bold line is thrown exception
trigger LineItemTrigger on Line_Item__c (after insert, after update, before delete, after delete, before insert, before update) {

// QC 940 update
    set<id> LineItemTypeId = new set<id>();
    for(Line_Item__c lineItem: trigger.new ){
        LineItemTypeId.add(lineItem.line_Item_Type__c );    
    }
    
    map<id, Line_Item_Type__c> lineItemcategory = new map<id,Line_Item_Type__c>( [select id,line_Item_category_text__c from Line_Item_Type__c where id in :LineItemTypeId] );
    
    Id AuditlineItemRecordTypeId = [SELECT Id FROM RecordType WHERE Name='Audit Line Item' LIMIT 1].Id;
    
    for(Line_Item__c lineItem: trigger.new ){
    string categoryText = lineItemcategory.get( lineItem.line_Item_Type__c ).line_Item_category_text__c ;
    if( trigger.isBefore && ( trigger.isinsert || trigger.isupdate )) {
            if( lineItem.RecordTypeId== AuditlineItemRecordTypeId){                            
                if( categoryText.startsWith('ECE')
                && ( categoryText.Contains('Stationery and Postage')
                || categoryText.Contains('Distribution of Election Material') )  ){
                    
                    LineItem.vouching_Advertising_material_provided__c = 'NA' ;
                    
                }
            }
        
        }
    
    }
It is used only 1 time . but it thrown exception
 
Hi all,

I have below code . Can I update anything to avoid governor limit ?



trigger PenaltyNoticeReviewTrigger on Penalty_Notice_Review__c (before insert) {
    try
    {
        if (Trigger.isInsert) {
            if(trigger.isBefore){
                for(Penalty_Notice_Review__c item :Trigger.New){
                    // get list of Penalty_Notice_Review__c
                    List<Penalty_Notice_Review__c> penaltyNotices = [SELECT Id,Name,Penalty_Notice__c,Review_Number__c FROM Penalty_Notice_Review__c where Penalty_Notice__c =: item.Penalty_Notice__c];
                    if(penaltyNotices.size()==0)
                        item.Review_Number__c = 1;
                    else
                        item.Review_Number__c = penaltyNotices.size() + 1;
                }
            }
        }
    }
    catch (Exception ex)
    {
        System.debug('Error Occurred:' + '[' + ex.getMessage() +' ]');
        throw new FADMSException(ex.getMessage());
    }
   
Can anyone help me ? I create an entitlement and try create a case using that entitlement but i got the error in the subject 

User-added imageUser-added image
Hi all,

I create a auto respose rule but it is not fire. Can anyone help me ?User-added image

I create two case with status escalated and not esccalated but nothing happen

 
Hi expert, I have controller below but i got the error from the title. Could any one to take a look that issue ?

public class demo {
    
    private ApexPages.standardcontroller stdCtrl;
    private final String serviceEndpoint= 'http://md5.jsontest123.com/';
    public Contact contact;
    public boolean displayPopup {get; set;}     
    public String Response { get; set;}
    public String Headers { get; set; }
    public demo(ApexPages.standardController controller)
    {    
        stdCtrl = controller;
        this.contact = (Contact)controller.getRecord();
        contact  = [Select name,email from Contact where id=:contact.id limit 1];
        sendEmail();
    }
    
    public PageReference doDelete()
    { 
        PageReference ref = stdCtrl.delete(); 
        ref.getParameters().put('nooverride','1');
        return ref;
    }
    
    public boolean sendReq() 
    {
        //String conName = contact.Name;
        boolean validated= true;
        String ERR_503 = 'Service Unavailable. Can not access webservice at the moment';
        String errorMessage = '';
        Integer httpStatusCode = 0;
        String httpStatus = '';
        String resBody = '';
        
        // Get the XML document from the external server
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(serviceEndpoint+'?text='+contact.Name);
        
        req.setMethod('GET');
        HttpResponse res = http.send(req);
        httpStatusCode = res.getStatusCode();
        httpStatus = res.getStatus();
        resBody = res.getBody();
        System.debug(httpStatusCode);
        System.debug(httpStatus);
        System.debug(resBody);
        if (httpStatusCode == 200)
        {
            validated= true;
            system.debug('validated'+validated);
            
            //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info,'1'));
            //showPopup();
            
        }
        
        else if(httpStatusCode == 503)
        {
            validated= false;
            errorMessage +=ERR_503;
            throw new errorException(errorMessage);
        }
        return true;
    }
    
    public void closePopup() {        
        displayPopup = false;    
    }
    
    public void showPopup() {        
        displayPopup = true;    
    }
    public void sendEmail()
    {
        system.debug('sendReq'+sendReq());
        if(sendReq())
        {
            displayPopup = true; 
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();        
            String[] toAddress = new String[] {contact.Email};
            email.setToAddresses(toAddress);
            email.setSubject('Deleted Contact Alert');
            email.setPlainTextBody('This message is to alert you that the contact named ' + contact.Name + ' has been deleted.');
            emails.add(email);
            Messaging.sendEmail(emails);         
        }
        
    }   
}
test class :

@isTest(SeeAllData=false)
public class testdemoController {
    static Contact cont;    
      @isTest static void testNormalCase(){
        Init();
        System.Test.setMock(HttpCalloutMock.class, new ExampleCalloutMock());
        demo controller = new demo(new ApexPages.StandardController(cont));
        controller.doDelete();
    }
    static void Init()
    {
        System.Test.startTest();
        Account acct = new Account(Name='test');
        insert acct;
        cont = new Contact(Email='nlhuy@tma.com.vn',LastName='TestCont');
        insert cont;
        System.Test.stopTest();
    }
    
}
Hi all,

I want to overide the delete button from the contact object. when i click del . it will appear different message ? Can anyone help me to handle it ?
Hi all,

I have requirement with add 1 & 5 row. it is ok with attachment in there. but it is not worked with the delete function.It show the error apex input file with conjuntion. Can any one help. This is my VF page :

<apex:page controller="LobbyEditRelatedContactController" tabStyle="Clients_Employees__tab" title="Clients & Employees">
    
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"/>
    
    <script>
        
        $(document).ready(function() {
        $("#GvCHX").click(function() {
            $("#GvCHXDetails").toggle(this.checked);
        }).triggerHandler('click');
    });
    
    </script>
    
    <apex:form >
        <apex:pageBlock title="Client"  rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Client']}">
            <apex:pageBlockTable value="{!lstContactWrappers}" var="wrapper" id="wtable">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!wrapper.contact.Lobbyists_Appointment__c}"/>
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!wrapper.contact.Client_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="ABN">
                    <apex:inputField value="{!wrapper.contact.ABNUSER__c}"/>
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Delete" action="{!delRow}" rerender="wtable" immediate="true">
                        <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelrow}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlock>
        <apex:pageBlock title="Employee" rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Employee']}">
            <apex:pageBlockTable value="{!lstContactWrappers}" var="wrapper" id="wtable1">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!wrapper.contact.Lobbyists_Appointment__c}" />
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!wrapper.contact.Employee_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="Position">
                    <apex:inputField value="{!wrapper.contact.Position__c}"/>
                </apex:column>
                <apex:column headerValue="NSW Gov board ?">
                    <apex:inputCheckbox id="GvCHX" value="{!wrapper.contact.Government_Board_or_Committee_Member__c}" immediate="true"/>
                </apex:column>
                <apex:column headerValue="Details">
                    <apex:inputField id="GvCHXDetails" label="details" value="{!wrapper.contact.Details__c}"/>
                </apex:column>
                <apex:column headerValue="Add Declaration" >
                    <apex:inputFile value="{!wrapper.att.body}" filename="{!wrapper.att.name}"/>                    
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:actionRegion >
                        <apex:commandButton value="Delete" action="{!delRow}" reRender="wtable1">
                            <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelrow}"/>
                        </apex:commandButton>
                    </apex:actionRegion>
                </apex:column>
            </apex:pageBlockTable>
            <!-- apex:actionregion tag is required in case using apex:inputFile with any apex tag with 'rerender' attribute within the same apex:form -->
            <apex:actionregion >
                <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable1" immediate="true">
                    <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
                </apex:commandButton>
                <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable1" immediate="true">
                    <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
                </apex:commandButton>
            </apex:actionregion>
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Hi all,

I have a page below with the field the file to be attached when save record. Can anyone help me ?

<apex:page controller="LobbyEditRelatedContactController" tabStyle="Clients_Employees__tab" title="Clients & Employees">
    
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"/>
    
    <script>
        
        $(document).ready(function() {
        $("#GvCHX").click(function() {
            $("#GvCHXDetails").toggle(this.checked);
        }).triggerHandler('click');
    });
    
    </script>
    
    <div id="GvCHXDetails">test</div>
    
    <apex:form >
        <apex:pageBlock title="Client"  rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Client']}">
            <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!Contacts.contact.Lobbyists_Appointment__c}"/>
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!Contacts.contact.Client_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="ABN">
                    <apex:inputField value="{!Contacts.contact.ABNUSER__c}"/>
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Delete" action="{!delRow}" rerender="wtable" immediate="true">
                        <apex:param name="toDelIdent" value="{!Contacts.ident}" assignTo="{!toDelrow}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlock>
        <apex:pageBlock title="Employee" rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Employee']}">
            <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable1">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!Contacts.contact.Lobbyists_Appointment__c}" />
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!Contacts.contact.Employee_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="Position">
                    <apex:inputField value="{!Contacts.contact.Position__c}"/>
                </apex:column>
                <apex:column headerValue="NSW Gov board ?">
                    <apex:inputCheckbox id="GvCHX" value="{!Contacts.contact.Government_Board_or_Committee_Member__c}" immediate="true"/>
                </apex:column>
                <apex:column headerValue="Details">
                    <apex:inputField id="GvCHXDetails" label="details" value="{!Contacts.contact.Details__c}"/>
                </apex:column>
                <!--<apex:column headerValue="Active">
<apex:inputCheckbox value="{!Contacts.cont.Active__c}" />
</apex:column>--> <!--this will be defaulted to TRUE on any new entry-->
                <apex:column headerValue="Add Declaration">
                    <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Delete" action="{!delRow}" rerender="wtable1" immediate="true">
                        <apex:param name="toDelIdent" value="{!Contacts.ident}" assignTo="{!toDelrow}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable1" immediate="true">
                <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable1" immediate="true">
                <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}"/>
     
        </apex:pageBlock>
    </apex:form>
</apex:page>
Hi all,

I VF page below and have 2 URL
lobbyEditrelatedcontact?RecordType=01290000000iHY6
lobbyEditrelatedcontact?RecordType=01290000000iHYB

the first one for employee and second for the client . How can i assign VF page with record type and URL above

<apex:page controller="LobbyEditRelatedContactController" tabstyle="Account">
 <apex:form >
   <apex:pageBlock title="Client">
      <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable">
         <apex:column headerValue="Appointment">
            <apex:inputField value="{!Contacts.cont.Lobbyists_Appointment__c}"/>
         </apex:column>
         <apex:column headerValue="Name">
              <apex:inputField value="{!Contacts.cont.Client_NameUSER__c}"/>
         </apex:column>
         <apex:column headerValue="ABN">
         <apex:inputField value="{!Contacts.cont.ABNUSER__c}"/>
         </apex:column>
         <apex:column headerValue="Action">
             <!--<apex:commandButton value="Remove Row" action="{!delWrapper}" rerender="wtable">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/>-->
         </apex:column>
      </apex:pageBlockTable>
      <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable" immediate="true">
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" immediate="true">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlock>
   <apex:pageBlock title="Employee">
      <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable1">
         <apex:column headerValue="Appointment">
            <apex:inputField value="{!Contacts.cont.Lobbyists_Appointment__c}"/>
         </apex:column>
         <apex:column headerValue="Name">
            <apex:inputField value="{!Contacts.cont.Employee_NameUSER__c}"/>
         </apex:column>
         <apex:column headerValue="Position">
            <apex:inputField value="{!Contacts.cont.Position__c}"/>
         </apex:column>
         <apex:column headerValue="NSW Gov board ?">
            <apex:inputCheckbox id="GvCHX" onchange="slideToggle" value="{!Contacts.cont.Government_Board_or_Committee_Member__c}"/>
         </apex:column>
         <apex:column headerValue="Details">
         
            <div id="GvCHXDetails" style="display:none">Age is something</div>
            
            <!--<apex:inputField id="GvCHXDetails" label="details" value="{!Contacts.cont.Details__c}"/>-->
         </apex:column>
         <!--<apex:column headerValue="Active">
              <apex:inputCheckbox value="{!Contacts.cont.Active__c}" />
         </apex:column>--> <!--this will be defaulted to TRUE on any new entry-->
             <apex:column headerValue="Add Declaration">
             <apex:inputCheckbox value="{!Contacts.cont.Declaration_Attached__c}" />
         </apex:column>
         <apex:column headerValue="Action">
             <!--<apex:commandButton value="Remove Row" action="{!delWrapper}" rerender="wtable">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/>-->
         </apex:column>
      </apex:pageBlockTable>
      <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlock>
 </apex:form>
</apex:page>
Hi expert,

I have requirement in the subject . I have 2 record type :client and employee . When we choose each record it will display the VF page base on record type with different field. How can i handle it ?
Hi all,

For example . I have 2 recordtype :client and employee and the current page we select View list for each record type it will display the different layout. Is there any way to display 2 view in 1 VF page ? get the ID of view list and display on VF page
Hi all,

I have requirement to display 2 recordtype in one page. 2 section for example :client and employee. when I click new button it will display 2 page layout base on the recordtype . Could any one sugggest how to solve this requirement ?

 
Hi expert,

I have trigger below and it got soql exception. I just join project few days so I do not understand the logic of the flow. Can any one advise to improve the code. I see SOQL in for loop:
     if (Trigger.isInsert) {
                
                LineItemFormController.isInsertTrigger = true;
                for(Line_Item__c item :Trigger.New){
                if ((lineItemRecordType != '') && (item.Cloned_Line_Item__c == null) && (item.RecordTypeId == lineItemRecordType)) {
                    lineItemIds.add(item.Id);
                    if (lineItemMaps.get(item.Id) == null) {
                        lineItemMaps.put(item.Id, new List<Line_Item__c>());
                    }
                    }
                }
                
                List<Line_Item__c> oldAuditLineItems = [SELECT Id,Line_Item__c, Active__c, Line_Item_Status__c
                                                    FROM Line_Item__c
                                                    WHERE RecordTypeId =:auditRecordType
                                                    AND Active__c = true
                                                    //US5105
                                                    AND Line_Item_Status__c != 'Audited'
                                                    AND Line_Item__c IN :lineItemIds
                                                   ];
                for (Line_Item__c auditItem : oldAuditLineItems) {
                    lineItemMaps.get(auditItem.Line_Item__c).add(auditItem);
                }
                System.Debug('nghiatran: Insert ' + isUpdate);
                System.Debug('vinhvinh: Come to Insert Audit trigger');
                for(Line_Item__c item :Trigger.New){
                    Line_Item_Type__c lineItemType  = [SELECT Id,Line_Item_Category_Text__c,Line_Item_Type_Aggregated_Category__c,Name FROM Line_Item_Type__c where id =: item.Line_Item_Type__c limit 1];
                    if ((item.Cloned_Line_Item__c == null) && (item.RecordTypeId == lineItemRecordType)) {
                        // US6137 insert start
                        system.debug('nghiatran lineItemType.Line_Item_Type_Aggregated_Category__c ' + lineItemType.Line_Item_Type_Aggregated_Category__c);
                        if(lineItemType.Line_Item_Type_Aggregated_Category__c == 'Electoral Expenditure' ||
                            lineItemType.Line_Item_Type_Aggregated_Category__c == 'Small Donations Made' ||
                            lineItemType.Line_Item_Type_Aggregated_Category__c == 'Small Donations Received')
                            return;
                        // US6137 insert end
                       if (lineItemMaps.get(item.Id).size() == 0 ) {
                           system.debug('nghiatran access insert after ' + lineItemType.Line_Item_Type_Aggregated_Category__c);
                            Line_Item__c temp = item.Clone(false,true);
                            temp.Line_Item__c = item.Id;
                            temp.Line_Item_Type__c = item.Line_Item_Type__c;
                            temp.RecordTypeId = auditRecordType;
                            temp.Active__c = true;
                            temp.Line_Item_Status__c = 'Not Audited';
                            newAuditLineItems.add(temp);
                        }
                    }
                }
            }
Hi Expert,

I have test class and trigger below. when I run test class it thrown too many SOQL in the trigger. Could any one help to fix it ?
Test class
@isTest(SeeAllData=true)
public with sharing class TestNonComplianceCreateController{
    static Disclosure_Claim_for_Payment__c dcp;
    
    static Non_Compliance__c nci;
    static testMethod void newTest() {
        InitialData();
        Test.SetCurrentPage(Page.NonComplianceCreate);
        
        List<RecordType> recordTypes = [SELECT Id, Name FROM RecordType Where Name='Non-Compliance' Limit 1];       
        String recordTypeId=recordTypes[0].Id;
        ApexPages.CurrentPage().GetParameters().Put('retURL', '/' + dcp.Id);
        ApexPages.CurrentPage().GetParameters().Put('what_id', dcp.Id);
              
        //System.Debug('aaa ' + str);
        //ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, '/' + dcp.Id));
        
        ApexPages.StandardController sc = new ApexPages.StandardController(new Task());          
        NonComplianceCreateController controller = new NonComplianceCreateController(sc);
        controller.GetAllTaskFieldSet();
        controller.Entity.Non_Compliance_Id__c = nci.Id;
        controller.Save();
        
        //For Exception => not set retURL
        Test.SetCurrentPage(Page.NonComplianceCreate);
        ApexPages.CurrentPage().GetParameters().Put('RecordType', recordTypeId);
        ApexPages.StandardController sc1 = new ApexPages.StandardController(new Task());          
        NonComplianceCreateController controller1 = new NonComplianceCreateController(sc1);
        controller1.Entity.Non_Compliance_Id__c = nci.Id;
        controller1.Save();
        
        //For Test NonComplianceTrigger
        nci.Name='Updated Test';
        upsert nci;
    }
    static void InitialData()
    {
        Map<String, String> listRecordType = new Map<String,String>();
        for (RecordType r : [SELECT Id, Name FROM RecordType]) {
            listRecordType.put (r.Name, r.Id);
        }
        Account accountPerson = new Account(LastName = 'Test', FirstName='Name',RecordTypeId=listRecordType.get('Person') );
        upsert accountPerson;
        
        dcp = new Disclosure_Claim_for_Payment__c(isTemplate__c=false,RecordTypeId=listRecordType.get('Disclosure (Major Political Donor)'), Stakeholder__c = accountPerson.Id);
        upsert dcp;
        
        List<Line_Item_Category__c> listLIC = new List<Line_Item_Category__c>();
        List<Line_Item_Category__c> listlic1 = [SELECT Id, Add_Row__c, Reference_Number__c FROM Line_Item_Category__c WHERE Reference_Number__c = '1009'];
        Line_Item_Category__c lic1;
        if(listlic1.size() > 0){
             lic1 = listlic1[0];
            listLIC.add(lic1);
        }else{
            lic1 = new Line_Item_Category__c(Add_Row__c=true,Reference_Number__c='1009');
            listLIC.add(lic1);        
        }
        List<Line_Item_Category__c> listlic2 = [SELECT Id, Add_Row__c, Reference_Number__c FROM Line_Item_Category__c WHERE Reference_Number__c = '1010'];
        Line_Item_Category__c lic2;
        if(listlic2.size() > 0){
             lic2 = listlic2[0];
            listLIC.add(lic2);
        }else{
            lic2 = new Line_Item_Category__c(Add_Row__c=true,Reference_Number__c='1010');
            listLIC.add(lic2);        
        }
        //Line_Item_Category__c lic1 = new Line_Item_Category__c(Add_Row__c=true,Reference_Number__c='1009');
        //upsert lic1;
        //Line_Item_Category__c lic2 = new Line_Item_Category__c(Add_Row__c=true,Reference_Number__c='1010');
        //upsert lic2;
        system.debug('Huy test: ' + Limits.getLimitQueries());
        Line_Item_Type__c lit1 = new Line_Item_Type__c(Line_Item_Category__c=lic1.Id,Disclosure_Claim_for_Payment__c=dcp.Id);
        upsert lit1;
        system.debug('Huy test: ' + Limits.getLimitQueries());
        Line_Item_Type__c lit2 = new Line_Item_Type__c(Line_Item_Category__c=lic2.Id,Disclosure_Claim_for_Payment__c=dcp.Id);
        upsert lit2;
        system.debug('Huy test: ' + Limits.getLimitQueries());
        Line_Item__c li = new Line_Item__c(Line_Item_Type__c = lit1.Id);
        upsert li; // it thrown exception here
        
        system.debug('Huy test: ' + Limits.getLimitQueries());
        nci = new Non_Compliance__c(Name='test',Legislative_Reference__c='test',Compliance_Issue__c='test',
                                    RecordTypeId=listRecordType.get('Disclosure Non-Compliance'));
        upsert nci;
        system.debug('Huy test: ' + Limits.getLimitQueries());
    }
}

and the trigger .I just paste a part of the trigger and the bold line is thrown exception
trigger LineItemTrigger on Line_Item__c (after insert, after update, before delete, after delete, before insert, before update) {

// QC 940 update
    set<id> LineItemTypeId = new set<id>();
    for(Line_Item__c lineItem: trigger.new ){
        LineItemTypeId.add(lineItem.line_Item_Type__c );    
    }
    
    map<id, Line_Item_Type__c> lineItemcategory = new map<id,Line_Item_Type__c>( [select id,line_Item_category_text__c from Line_Item_Type__c where id in :LineItemTypeId] );
    
    Id AuditlineItemRecordTypeId = [SELECT Id FROM RecordType WHERE Name='Audit Line Item' LIMIT 1].Id;
    
    for(Line_Item__c lineItem: trigger.new ){
    string categoryText = lineItemcategory.get( lineItem.line_Item_Type__c ).line_Item_category_text__c ;
    if( trigger.isBefore && ( trigger.isinsert || trigger.isupdate )) {
            if( lineItem.RecordTypeId== AuditlineItemRecordTypeId){                            
                if( categoryText.startsWith('ECE')
                && ( categoryText.Contains('Stationery and Postage')
                || categoryText.Contains('Distribution of Election Material') )  ){
                    
                    LineItem.vouching_Advertising_material_provided__c = 'NA' ;
                    
                }
            }
        
        }
    
    }
It is used only 1 time . but it thrown exception
 
Can anyone help me ? I create an entitlement and try create a case using that entitlement but i got the error in the subject 

User-added imageUser-added image
Hi there,
I am writing a webservice callout which is triggered on clicking a link in an Account detail page; Upon the click of the link, the code will go to the external system and get the record from the other system based on the account I clicked the link from and display in a VF page.
So far, I've got to the point where i could retrieve from the endpoint but I do not know how to put the condition based on which Account Id i click the link from?

<!-----Visualforce Page-------------->
<apex:page controller="GetRestfulExample" action="{!fetchData}" contentType="text/plain">
     {!response}
</apex:page>

<!---------Controller----------->
public class GetRestfulExample {
    private final String serviceEndpoint= 'http://headers.jsontest.com/';
    public String Response { get; set;}
    public String Headers { get; set; }
   
    public void fetchData() {
        getAndParse('GET');
    }

  public void getAndParse(String GET) {

    // Get the XML document from the external server
    Http http = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint(serviceEndpoint);
   
    req.setMethod('GET');
    HttpResponse res = http.send(req);

    System.debug(res.getBody());
     this.response=res.getBody();
  }
}

Where can I put the condition to just display the fields for this account I am currently in?

Please throw me some ideas!

Thanks,
justin~sfdc

We are currently developing an Apex application to be packaged and listed in the AppExchange directory.

Our application contains custom buttons associated with the Account, Case, Contact, Lead, Opportunity objects.

Before we created the package, we added the custom buttons to their respective page layouts (Account, Case, Contact, Lead, Opportunity) in our development organization where the application was developed.

 

After we installed our managed package in one of our sandboxes, we found out that the custom buttons were not displaying in the respective sandbox page layouts.

 

We tried adding the custom buttons manually, after the installation, by customizing the layout of the respective pages and drag-and-dropping the custom buttons.

However, we found out that this action did not have an organization-wide effect. By logging with a different user, we would not see the custom buttons in the respective page layouts that had been added by another user.

 

So our questions are:

 

1) Can the installation of a managed package also add custom buttons to the page layouts of the target organization?

 

2) If not, how should proceed the user performing the installation in order to manually add the custom buttons to the respective layouts, in a way that the action has an organization-wide effect (all users of the organization would see the custom buttons)?

 

We do not want to settle with a solution where, after package installation, each and every user of the organization would have to add manually the custom buttons.