• Rahul Gupta 137
  • NEWBIE
  • 5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies
In a visual force page, i want to create two section one for creating records for the object . As soon as I hit submit button In the second section of page record that got should get the display in a table. It should have at least 5 last record

I want to create a custom button on the detail page of account that shows no of contacts and opportunity for that account.Custom button should invoke a VF page that has above details 
hi guys ,
i need help to devolp the code for finding contact from case list .
there will a picklist of cases we will have to choose a certain case and click on custom button find which will give contacts under that case 

thanks in advance 
I want to create a custom button on the detail page of account that shows no of contacts and opportunity for that account.Custom button should invoke a VF page that has above details 
i am trying with this sample code as i am new to rest api .
http://www.oyecode.com/2014/08/start-building-your-own-rest-api-in.html

i am getting the below error , i am not getting understood whats the issue is 

class : 
/***************************************************************************
Name : OyeCode Api Service, custom designed in Apex 
Created By : Harshit Pandey (hpandey@salesforce.com)
Created Date : August 18, 2014
Description : An Apex REST service to that supports the following 
operations, related to insertion and retrieval of Contacts :
1. GET /ContactId - Return the Response as instance of custom class called ResponseClass
- Reponse class return customized information which is match Record, CustomMessage, Error (if any)
2. POST/Contact - Creates a new Contact and insert records in the database.
***************************************************************************/

@RestResource(urlMapping='/OyeCode/*')
global class OyeCodeRestAPI {
    
    //**************************************************
    //Private methods 
    //**************************************************
    
    //Check if Object is NULL or Blank
    global static boolean isNotNullOrEmpty(string str)
    {
        return str!=null || !String.isBlank(str); 
    }
    
    // Create a Contact 
    public static Contact createContact(String firstName, String lastName, String email,String Phone)
    {
        //check if the fields provided on not empty
        if(isNotNullOrEmpty(firstName) && isNotNullOrEmpty(lastName) && isNotNullOrEmpty(email) && isNotNullOrEmpty(Phone))
        {
            Contact newContact = new Contact();
            newContact.FirstName = firstName;
            newContact.LastName = lastName;
            newContact.Email = email;
            newContact.Phone=phone;
            return newContact;         
        }
        else 
        {
            System.Debug('Required field values are not provided here');
            return null;
        }
    }
    
    
    //====================================================================================
    // *** REST POST *** : Require field should not be empty, method to post a new Contact
    //====================================================================================
    @HttpPost
    global static ResponseHandler post(String firstname, String  lastname, String email, String Phone)
    {
        Contact  newContact =  createContact(firstName, lastName, email, Phone);
        ResponseHandler response = new ResponseHandler();
        try
        {
            insert newContact;
            List<sObject> thesObjectList = new List<sObject>();
            thesObjectList.add((sObject)newContact);
            response.Data = thesObjectList;
            response.Status = 'Success';
            response.ErrorCode = null;
            response.Message = null;
        } 
        catch(DmlException e) 
        {
            //Add custom error code when you could not insert a record
            response.ErrorCode = 'Oyecode - 0001';
            response.Status = 'error';
            response.Message = e.getMessage();
        }
        return response;   
    }
    
    
    //==============================================================================================
    // *** REST GET *** :  Requires the id of Contact and reutrn results as Response Type
    //===============================================================================================
    @HttpGet 
    global static ResponseHandler GET()
    {
        ResponseHandler response = new ResponseHandler();
        Contact  returnContact = getContact();
        
        if(returnContact!=null)
        {
            response.Status = 'Success';
            response.ErrorCode = '';
            List<sObject> thesObjectList = new List<sObject>();
            thesObjectList.add((sObject)returnContact);
            response.Data = thesObjectList;
            response.Message = 'Success : Found Contact';
        }
        
        else
        {
            response.ErrorCode = 'OyeCode-0002';
            response.Status = 'error';
            response.Message = 'Fail : Ahh, Contact Not Found';
            
        }
        
        return response;
    }
    
    //Adding custom Exception sub-class 
    public class NoRecordMatchException extends Exception {}
    
    public static Contact getContact()
    {
        //Read the Request from the URL
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String ContactId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); 
        Contact result;
        try{
            result = [SELECT Id, lastname, firstName, phone, email FROM Contact WHERE Id = :ContactId];
        }
        Catch(System.QueryException e)
        {
            //Add custom exception dynamically to the ErrorMap
            throw new NoRecordMatchException('Unable to find the record maching Id : '+ContactId);
        }
        return result;
    }
    
}
hi guys ,
i need help to devolp the code for finding contact from case list .
there will a picklist of cases we will have to choose a certain case and click on custom button find which will give contacts under that case 

thanks in advance 
trigger OPPTRIGGER on OpportunityLineItem (after update) {
    Set<Id> OLI= new set<Id>();
    for(OpportunityLineItem obj: TriggerNew)
    {
        SetOLI.add(obj.Id);
        
    }
    Map<ID, OpportunityLineItem> map1= New Map<ID, OpportunityLineItem>();
    for(OpportunityLineItem obj:[Select Id,Name,quantity,opportunity,opportunity.AccountId,Opportunity.Account.myruchika__Total_sales_quantities__c from OpportunityLineItem where ID in :Set OLI])
    {
        if(obj.opportunity!=null && obj.Opportunity.AccountId!= null)
        {
            if(map1.get(obj.Opportunity.AccountId)== null)
            {
                map1.put(obj.Opportunity.AccountId, New list<OLI> New OpportunityLineItem)
                {
                    map1.get(obj.Opportunity.AccountId).Add(obj);
                }
            
            }
        }
    }
    list<Account> lstacc= New list<Account>();
    for(Account obj:[Select Id,myruchika__Total_sales_quantities__c from account where ID in:Map.keySet()])
    {
        if(map1.get(obj.Id)!=null)
        {
            decimal total quantities=0;
        }
    }
       for(OpportunityLineItem objLI:Map1.get(obj.Id)) 
       {
           totalquantity+=objLI.quantity
       }
       if(obj.myruchika__Total_sales_quantities__c==null) 
       {
           obj.myruchika__Total_sales_quantities__c=0;
       }
      obj.myruchika__Total_sales_quantities__c+=totalquantity;
    lstacc.add(obj);
}
updateOpportunityLineItem.size() >0)
        update updateOpportunityLineItem;
}
}

error is coming in this code
please help me for this code 
is this Code is right??

trigger createAssetonClosedWon on Opportunity (after insert, after update) {
    for(opportunity o:Trigger.New) {
        if(o.iswon==true && o.hasOpportunitylineitem==true){
            string opptyId= o.Id;
            Opportunitylineitem[] OLI=[Select Quantity,UnitPrice,PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description from opportunitylineitem where opportunityId=:opptyId];
            asset[] ast= New Asset[]{};
                asset a= new asset();
            for(opportunitylineitem ol:OLI){
                a= new asset();
                a.AccountId=a.AccountID;
                a.Quantity=ol.quantity;
                
                a.Product2Id=ol.PricebookEntry.Product2Id;
                a.price=ol.UnitPrice;
                a.Description=ol.Description;
                a.name=ol.PricebookEntry.Product2.Name;
                ast.add(a);
                
                
            }
            
            insert ast;
            
            
        }
    }
}
 error 
Apex trigger myruchika.createAssetonClosedWon caused an unexpected exception, contact your administrator: myruchika.createAssetonClosedWon: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: AccountId, ContactId (asset must have account and/or contact parent(s)): [AccountId, ContactId]: Trigger.myruchika.createAssetonClosedWon: line 22, column 1 
  
create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null?
The Apex class must be called 'AccountHandler' and be in the public scope.
The Apex class must have a public static method called 'insertNewAccount'.
The 'insertNewAccount' method must accept an incoming string as a parameter, name the account after the parameter, insert it into the system and then return the account record.
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.