• Subodh shukla
  • NEWBIE
  • 165 Points
  • Member since 2015

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
Hi, I am doing Trialhead. But i stuck here. This is my error message:
User-added image

And my code is:
<apex:page controller="NewCaseListController" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Cases List" id="cases_list">            
            <apex:pageBlockTable value="{! NewCases }" var="cs">
                    <apex:outputLink value="{! cs.Id}">{! cs.Id}>
                          <apex:repeat value="{!newCases}" var="case" id="theRepeat">
                         </apex:repeat>
                    </apex:outputLink>
                <apex:column value="{! cs.CaseNumber }"/>
                <apex:column value="{! cs.id }"/>
                <apex:column value="{! cs.Status}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) {
List<task> carry=New List<task>();

  for(opportunity opp:trigger.new){
   if(opp.stagename=='closed own'){
    task t=new task(whatid=opp.id);
    carry.add(t); 
    }
   }
     insert carry;

 }

 The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.The Apex trigger must be called 'ClosedOpportunityTrigger'
With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
This challenge specifically tests 200 records in one operation.

I tried with the above code, task is not created.
Hi, I copleted the challange "Creating Custom Objects and Fields" in trailhead. But while check challange it shows below error:

Challenge not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name__c]: [Name__c]

Custom objects

While I check the Name field with Name__c is available. Anything am I missed?
Trigger:
trigger RestrictContactByName on Contact (before insert, before update) {
    
    //check contacts prior to insert or update for invalid data
    For (Contact c : Trigger.New) {
        if(c.LastName == 'INVALIDNAME') {    //invalidname is invalid
            c.AddError('The Last Name "'+c.LastName+'" is not allowed for DML');
        }

    }
}

Test class:

@istest
public class TestRestrictContactByName {
    
    public static testmethod void testcontact1(){
        list<contact> cont=new list<contact>();
        contact con =new contact(lastname='testttt');
        cont.add(con);
        try{
        insert con;
        }
        catch(System.DmlException e){
             
        system.assert(e.getmessage().contains('The lastname testttt is not allow for DML'));
        }
    }
    
    public static testmethod void testcontact2(){
        list<contact> conn=new list<contact>();
        contact con =new contact(lastname='testtttt');
        conn.add(con);
        try{
        insert conn;
        }
        catch(System.DmlException e){
             
        //system.assert(e.getmessage().contains('The lastname testtttt is not allow for DML'));
        }
        
        conn.get(0).lastname='Invaliddata';
    
    try{
        update conn;
    }
    catch(System.DmlException e){
        system.assert(e.getmessage().contains('The lastname Invaliddata is not allow for DML'));
        
    }
}
}

 
  • October 01, 2015
  • Like
  • 0

List contactList = new List();    
List accountList = new List();

accountList = [Select Id,Account_Field__c from Account]; 
contactList = [Select Id from contact where AccountId in :accountList];

for(Account a:accountList){
              if(a.Account_Field__c == null)
                  for(Contact c:cntList){
                  a.Account_Field__c = c.Id;
                  accountList.add(a);
                  }
              }
          }
update accountList;
Thanks in advance
Hi,
In my batch class i have to populate Account Object field Account_Field__c with contact id when these field(field Account_Field__c) is null. I have tried above piece of code but it is not updating the field.

 
List<Contact> contactList = new List<Contact>();     
List<Account> accountList = new List<Account>();

 accountList = [Select Id,Account_Field__c from Account];  
 contactList = [Select Id from contact where AccountId in :accountList];

for(Account a:accountList){
              if(a.Account_Field__c == null)
                  for(Contact c:cntList){
                  a.Account_Field__c = c.Id;
                  accountList.add(a);
                  } 
              }
          }
update accountList;

Thanks in advance
 

we have a account and contacts there is status field in both
if the status of contact become open i want status of account become close and vise versa.
there is 6 contacts in account and all have different status , how can i achieve this.
Hi all,
I have a below trigger to update Invoice
trigger Updateinvoicestatus on Line_Item__c (after insert,after update) {
  
    Invoice_Statement__c[] I = new list<Invoice_Statement__c>();
    for(Line_Item__c ln: trigger.new)  {     
        Invoice_Statement__c INV= new Invoice_Statement__c(id = ln.Invoice_Statement__c);
        List<Line_Item__c>Lnv=[select id,Name from Line_Item__c where Invoice_statement__c =:INV.id];
        if(Lnv.size()==5){
            INV.status__c='Closed';
             I.add(INV);
             }
            if(Lnv.size()==6){
            ln.addError('You cant add more then five item');
           
        }
               
    }  
   Update I; 
     }
But in test class for the above trigger is giving following error
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Updateinvoicestatus: execution of AfterInsert
caused by: System.ListException: Duplicate id in list: a0228000005aT8UAAU
Trigger.Updateinvoicestatus: line 17, column 1: []
here is my test class
@istest
public class TestUpadateInvcStatus {
    public  static testmethod void updatetest(){
        Merchandise__c [] M = new list<Merchandise__c> {
            new merchandise__c (Name = 'test 1', Description__c = 'test', Price__c = 100, Total_Inventory__c = 1000),
            new merchandise__c (Name = 'test 2', Description__c = 'test', Price__c = 100, Total_Inventory__c = 1000),
            new merchandise__c (Name = 'test 3', Description__c = 'test', Price__c = 100, Total_Inventory__c = 1000),
            new merchandise__c (Name = 'test 4', Description__c = 'test', Price__c = 100, Total_Inventory__c = 1000),
            new merchandise__c (Name = 'test 5', Description__c = 'test', Price__c = 100, Total_Inventory__c = 1000)
                };
        Insert m;
        
        Invoice_Statement__c inv = new Invoice_Statement__c (Status__c = 'Open');
        insert inv;
        
        Line_Item__c [] li = New List<Line_Item__c>{ 
            new line_Item__c(Name = '1', Merchandise__c = m[0].id, Invoice_Statement__c = inv.id ),
                new line_Item__c(Name = '2', Merchandise__c = m[1].id, Invoice_Statement__c = inv.id ),
                new line_Item__c(Name = '3', Merchandise__c = m[2].id, Invoice_Statement__c = inv.id ),
                new line_Item__c(Name = '3', Merchandise__c = m[4].id, Invoice_Statement__c = inv.id ),
                new line_Item__c(Name = '3', Merchandise__c = m[4].id, Invoice_Statement__c = inv.id )
                
                };
         
                 Insert li;   
                  Line_item__c itm = new line_item__c(Name = '4', Merchandise__c = m[4].id, Invoice_Statement__c = inv.id);
        			Database.SaveResult sa = Database.insert(itm, false);
                    System.assert(!sa.isSuccess()); 
                    
                        
    }
}
It is giving 90% code coverage.
Pls give sugesstion Why I am getting this error?
 

trigger Updateinvoicestatus on Line_Item__c (after insert,after update) {
trigger Updateinvoicestatus on Line_Item__c (after insert,after update) {
  
    Invoice_Statement__c[] I = new list<Invoice_Statement__c>();
    for(Line_Item__c ln: trigger.new)  {     
        Invoice_Statement__c INV= new Invoice_Statement__c(id = ln.Invoice_Statement__c);
        List<Line_Item__c>Lnv=[select id,Name from Line_Item__c where Invoice_statement__c =:INV.id];
        if(Lnv.size()==2){
            INV.status__c='Closed';
             I.add(INV);
             }
            if(lnv.size()==3){
            ln.addError('You cant add more then five item');
           
        }
        
       
    }  
     Update I;
    

}
Plz give Suggestion

List contactList = new List();    
List accountList = new List();

accountList = [Select Id,Account_Field__c from Account]; 
contactList = [Select Id from contact where AccountId in :accountList];

for(Account a:accountList){
              if(a.Account_Field__c == null)
                  for(Contact c:cntList){
                  a.Account_Field__c = c.Id;
                  accountList.add(a);
                  }
              }
          }
update accountList;
Thanks in advance
I am having 2 scenario something like this :
1. I have created one custom field named "lookup realtion" on standard object Account.. I want to fire trigger in such a way that when ever new account is inserted with the same name contact is being created and the custom field on Account which i have created should get populated with the contact name. and 
2. is on the account and contact I had created the custom field named "Checkbox" which is of checkbox type... and while insertion if account checkbox is checked the checkbox field on contact  should also be get checked and later on when i uncheck the checkbox on account the contact field checkbox also be get unchecked. I had written the code which perfectly well for creating the contact when ever new account is being created.. but I am facing problem in implementin these two above mentioned logics.. plz edit my code and suggest me your innovative Ideas..
public class CreateAccountContact 
{
 trigger CreateAccountContact on Account (after insert, after update){

if(Trigger.isInsert){

    List<Contact> ct = new List <Contact>();   
    for(Account acc : trigger.new){    
        Contact c = new Contact();       
                    c.LastName = acc.name;
                    c.AccountId=acc.id;
                    c.Fax=acc.Fax;
                    c.MailingStreet=acc.BillingStreet;
                    c.MailingCity=acc.BillingCity;
                    c.MailingState=acc.BillingState;              
                    c.MailingPostalCode=acc.BillingPostalCode;
                    c.MailingCountry=acc.BillingCountry;
                    c.Phone=acc.Phone;        
        ct.add(c);      
    }
   
    insert ct; 
}
}
}
Hi, I am doing Trialhead. But i stuck here. This is my error message:
User-added image

And my code is:
<apex:page controller="NewCaseListController" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Cases List" id="cases_list">            
            <apex:pageBlockTable value="{! NewCases }" var="cs">
                    <apex:outputLink value="{! cs.Id}">{! cs.Id}>
                          <apex:repeat value="{!newCases}" var="case" id="theRepeat">
                         </apex:repeat>
                    </apex:outputLink>
                <apex:column value="{! cs.CaseNumber }"/>
                <apex:column value="{! cs.id }"/>
                <apex:column value="{! cs.Status}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
I have been trying to hide the edit button from all of the tabs of my salesforce app. Is there a way to do it?? 
trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) {
List<task> carry=New List<task>();

  for(opportunity opp:trigger.new){
   if(opp.stagename=='closed own'){
    task t=new task(whatid=opp.id);
    carry.add(t); 
    }
   }
     insert carry;

 }

 The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.The Apex trigger must be called 'ClosedOpportunityTrigger'
With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
This challenge specifically tests 200 records in one operation.

I tried with the above code, task is not created.
Hi, I copleted the challange "Creating Custom Objects and Fields" in trailhead. But while check challange it shows below error:

Challenge not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name__c]: [Name__c]

Custom objects

While I check the Name field with Name__c is available. Anything am I missed?
Trigger:
trigger RestrictContactByName on Contact (before insert, before update) {
    
    //check contacts prior to insert or update for invalid data
    For (Contact c : Trigger.New) {
        if(c.LastName == 'INVALIDNAME') {    //invalidname is invalid
            c.AddError('The Last Name "'+c.LastName+'" is not allowed for DML');
        }

    }
}

Test class:

@istest
public class TestRestrictContactByName {
    
    public static testmethod void testcontact1(){
        list<contact> cont=new list<contact>();
        contact con =new contact(lastname='testttt');
        cont.add(con);
        try{
        insert con;
        }
        catch(System.DmlException e){
             
        system.assert(e.getmessage().contains('The lastname testttt is not allow for DML'));
        }
    }
    
    public static testmethod void testcontact2(){
        list<contact> conn=new list<contact>();
        contact con =new contact(lastname='testtttt');
        conn.add(con);
        try{
        insert conn;
        }
        catch(System.DmlException e){
             
        //system.assert(e.getmessage().contains('The lastname testtttt is not allow for DML'));
        }
        
        conn.get(0).lastname='Invaliddata';
    
    try{
        update conn;
    }
    catch(System.DmlException e){
        system.assert(e.getmessage().contains('The lastname Invaliddata is not allow for DML'));
        
    }
}
}

 
  • October 01, 2015
  • Like
  • 0
hi.... 
i am new to understand apex.it is very difficult to  learn.and document are also very hard to understand.so some one give me 
some another apex development document .it is very important please help...