• Gokul Bharati
  • NEWBIE
  • 25 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
My trigger is Working Fine, Apex Class is Working Fine, Only Test Class is Problem
This is my Test class Code:
@isTest
    private class testcountOppLineItmsCount {
    static testMethod void testcountOppLineItmsCount() {
        List<OpportunityLineItem > lstoplitm= new list<OpportunityLineItem >();
       Opportunity o = new Opportunity(name='test opp1', CloseDate=date.today(), StageName='Closed Own');
       insert o;
      
           
      OpportunityLineItem op=new OpportunityLineItem (quantity=1,Opportunityid=o.id, TotalPrice=100  );
      insert op;
     lstoplitm.add(op);
     
      insert lstoplitm;
      countOppLineItmsCount.Change(lstoplitm);
       }
       }

Error is:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId, unknown (versions 3.0 and higher must specify pricebook entry id, others must specify product id): [PricebookEntryId, unknown]

--

I am New for this PricebookEntry.. psl correct my code or tell me wht shall i do?

thaks 

Hi All,

I am trying to connect  to Google drive API  from Apex using JWT to retrieve Oauth 2.0 token.Google isnt accepting my assertion values (JWT) and its returning an invalid Grant message.Can you please help.

Please find the below code and sample key:

public Class GoogleSalesforceDrive{

public static void AuthenticateGoogle(){
        
        http h = new Http();
        Httprequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        
        req.setEndpoint('https://accounts.google.com/o/oauth2/token');
        req.setMethod('POST');
        req.setHeader('ContentType','application/x-www-form-urlencoded');
        
        String Header = '{"alg":"RS256","typ":"JWT"}';
        
        String Header_Encode = EncodingUtil.base64Encode(blob.valueof(Header));
        
        String claim_set = '{"iss":"427541316564-7ljpoen8etct2b9odjsonl9r6fcdvna2@developer.gserviceaccount.com"';
        claim_set += ',"scope":"https://www.googleapis.com/auth/drive"';
        claim_set += ',"aud":"https://accounts.google.com/o/oauth2/token"';
        claim_set += ',"exp":"'+datetime.now().addHours(1).getTime()/1000;
        claim_set += '","iat":"'+datetime.now().getTime()/1000+'"}';
        
        String claim_set_Encode = EncodingUtil.base64Encode(blob.valueof(claim_set));
        
        String Singature_Encode = Header_Encode+'.'+claim_set_Encode;
        Singature_Encode = Singature_Encode.replaceAll('=','');
        Singature_Encode  = EncodingUtil.urlEncode(Singature_Encode,'UTF-8');
        String key = 'MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMTn4BfNstsUDqw1dO3UYiHFeZWkQwFu0nQGdRf7khlqAEmtMTWsTUUhIsju/j6mqtSP+qCLzimMOu4PAo6wEHGqYGuGqHTBUYxvfmm3escyt4/GTKGgCnJU2cTPd3IxY0E771NW+IwXNY8J3sp5wGi8Uz7W+Cs6nPRHNPnEORoVAgMBAAECgYAaRjqf0oHgO9/tWMC+j418piYgMqgCQ/BvLQFo7tfC7mMVcbfUSqaQ5+gFWeaxI3o+HOw7igw7fQvMAlK8CYBX/mDbbP0ttIF0mOmI+JOZ/4u8Rj0rNDg6p1XFPQNUsPAWhSNQ+FxFyAaKAVd40ZQ744psM/fePDEVDfCL+HuhQQJBAPM6cAlNjlsGBBByVso/1tvlhlilx3EZeaLJZV6FTdE4ebp5ChEhsJPTCZ3liY72ekg1lJmVpIEtPkVzJQ12NwUCQQDPPsD5x9ZHaArdCbxF01Jffkof1C896rXnxONTicoWUMrslHbkFjO06CfOs1BI0J8ZRRq6UtvZ3M62n2/OVqPRAkAoy3RfGxL1UVz9JTBJW8u9thGCbMu2vH8aPo0x/Um//ajtDcASf4QORyclxIn94HlCAzqZR+//eocnPtjIGTvBAkAijqQ/AkOIxKCLGwR54DLsGXLiu87k1C5g50PAukkoT3CG4nqwrcMRd2Sr4tqQSbk9zXgXeZmPSnJtoUhTb78BAkAfYjmtERN0smdt4c79lQftajADMhkYx+Z9Tro2f+e+CvheOYWpwQiG+983KtbJRNm7C9LwKqgsr0A6Q6ddzfnq';
        blob privateKey = EncodingUtil.base64Decode(key);
        
        blob Signature_b =   blob.valueof(Singature_Encode);
        
        String Sinatute_blob = EncodingUtil.base64Encode(Crypto.sign('RSA-SHA256', Signature_b , privateKey));   
        
        String JWT = Singature_Encode+'.'+Sinatute_blob;
        JWT = JWT.replaceAll('=','');
        String grt = 'urn:ietf:params:oauth:grant-type:jwt-bearer';
        system.debug('%%%%%%%%JWT'+JWT);
        req.setBody('grant_type='+grt+'&assertion='+JWT);
        res = h.send(req);
        String Response = res.getBody() +' '+ res.getStatusCode();
        system.debug('Response ='+Response);
       
     } 
    }

Key:
"private_key": "-----BEGIN PRIVATE KEY-----\nMIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMTn4BfNstsUDqw1\ndO3UYiHFeZWkQwFu0nQGdRf7khlqAEmtMTWsTUUhIsju/j6mqtSP+qCLzimMOu4P\nAo6wEHGqYGuGqHTBUYxvfmm3escyt4/GTKGgCnJU2cTPd3IxY0E771NW+IwXNY8J\n3sp5wGi8Uz7W+Cs6nPRHNPnEORoVAgMBAAECgYAaRjqf0oHgO9/tWMC+j418piYg\nMqgCQ/BvLQFo7tfC7mMVcbfUSqaQ5+gFWeaxI3o+HOw7igw7fQvMAlK8CYBX/mDb\nbP0ttIF0mOmI+JOZ/4u8Rj0rNDg6p1XFPQNUsPAWhSNQ+FxFyAaKAVd40ZQ744ps\nM/fePDEVDfCL+HuhQQJBAPM6cAlNjlsGBBByVso/1tvlhlilx3EZeaLJZV6FTdE4\nebp5ChEhsJPTCZ3liY72ekg1lJmVpIEtPkVzJQ12NwUCQQDPPsD5x9ZHaArdCbxF\n01Jffkof1C896rXnxONTicoWUMrslHbkFjO06CfOs1BI0J8ZRRq6UtvZ3M62n2/O\nVqPRAkAoy3RfGxL1UVz9JTBJW8u9thGCbMu2vH8aPo0x/Um//ajtDcASf4QORycl\nxIn94HlCAzqZR+//eocnPtjIGTvBAkAijqQ/AkOIxKCLGwR54DLsGXLiu87k1C5g\n50PAukkoT3CG4nqwrcMRd2Sr4tqQSbk9zXgXeZmPSnJtoUhTb78BAkAfYjmtERN0\nsmdt4c79lQftajADMhkYx+Z9Tro2f+e+CvheOYWpwQiG+983KtbJRNm7C9LwKqgs\nr0A6Q6ddzfnq\n-----END PRIVATE KEY-----\n",

 
My trigger is Working Fine, Apex Class is Working Fine, Only Test Class is Problem
This is my Test class Code:
@isTest
    private class testcountOppLineItmsCount {
    static testMethod void testcountOppLineItmsCount() {
        List<OpportunityLineItem > lstoplitm= new list<OpportunityLineItem >();
       Opportunity o = new Opportunity(name='test opp1', CloseDate=date.today(), StageName='Closed Own');
       insert o;
      
           
      OpportunityLineItem op=new OpportunityLineItem (quantity=1,Opportunityid=o.id, TotalPrice=100  );
      insert op;
     lstoplitm.add(op);
     
      insert lstoplitm;
      countOppLineItmsCount.Change(lstoplitm);
       }
       }

Error is:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId, unknown (versions 3.0 and higher must specify pricebook entry id, others must specify product id): [PricebookEntryId, unknown]

--

I am New for this PricebookEntry.. psl correct my code or tell me wht shall i do?

thaks 

I want to create a trigger which will validate the user role. Which means if role of new user is equals to its manager's role and new user's role id and its manager's roleid don't have a parent child relationship then it will show an exception. If any one hv success in same plz help..
I'm trying to write a trigger to make sure certain fields are not empty based on the status that is chosen.  I have several different types of fields I'm trying to validate.  My code is below but it doesn't seem to be validating anything

Resolution_Detail__c = RTF
Workaround_ICA__c = RTF
Defect_Type_Multi__c = multipicklist
Declined_Reason__c= picklist
NPI_Numbertext__c = plain text
NPI_Tracking_Link__c = URL
CPI_Numbertext__c = plain text
CPI_Tracking_Link__c = URL
Change_Numbertext__c = plain text
CPI_Tracking_Link__c = URL





 
trigger CWStatusValidation on Case (before update, before insert)
{

              
        for (Case objCase : Trigger.new)
        {
           //If Status is any of the following and Resolution Detail is empty, prompt to fill in.
           if((objCase.Status == 'Closed - Cancelled' || objCase.Status == 'Closed - Unable to Reproduce' || objCase.Status == 'Closed - Duplicate'
           || objCase.Status == 'Recurring Incident') && objCase.Resolution_Detail__c == '')            
           {
                trigger.new[0].addError('Please fill in the Resolution Detail for this case.');
           }
              //If Status is any of the following and ICA is empty, prompt to fill in.
              if((objCase.Status == 'Pending - RCA' || objCase.Status == 'Pending - Customer Validation' 
              || objCase.Status == 'Pending - Dealer Validation' || objCase.Status == 'Pending - Evaluation') && objCase.Workaround_ICA__c == '')             
              {
                trigger.new[0].addError('Please fill in the Workaround / ICA for this case.');
              }
                    //If Status = Pending - CPI, fill in Resolution Details, CPI Number and CPI Tracking Link
                    if(objCase.Status == 'Pending - CPI' && objCase.CPI_Numbertext__c == ' ' && objCase.CPI_Tracking_Link__c == ' ' && objCase.Resolution_Detail__c == '' )            
                    {
                        trigger.new[0].addError('Please fill in the Resolution Details, CPI Number and CPI Tracking Link for this case.');
                    }
                         //If the Status = Closed - Declined, fill in Resolution Detail, Defect Type and Declined Reason.
                         if(objCase.Status == 'Closed - Declined' && objCase.Resolution_Detail__c == '' && objCase.Defect_Type_Multi__c == '' && objCase.Declined_Reason__c == '')
                         {
                           trigger.new[0].addError('Please fill in the Resolution Details, Defect Type and Declined Reason for this case.');
                         }
                            //If the Status = Pending - NPI, fill in Resolution Detail, NPI Number and NPI Tracking Link.
                            if(objCase.Status == 'Pending - NPI' && objCase.Resolution_Detail__c == '' && objCase.NPI_Numbertext__c == null && objCase.NPI_Tracking_Link__c == null)
                            {
                               trigger.new[0].addError('Please fill in the Resolution Details, NPI Number and NPI Tracking Link for this case.');
                            }
                                //If the Status = Pending - Change, fill in Resolution Detail, Change Number and Change Tracking Link.
                                if(objCase.Status == 'Pending - Change' && objCase.Resolution_Detail__c == '' && objCase.Change_Number__c == '' && objCase.Change_Tracking_Link__c == '')
                                {
                                   trigger.new[0].addError('Please fill in the Resolution Details, Change Number and Change Tracking Link for this case.');
                                }
                                    //If the Status is any of the following, fill in Resolution Detail and Defect Type.
                                    if((objCase.Status == 'Closed - Resolved' || objCase.Status == 'Closed - No Response') && objCase.Resolution_Detail__c == '' && objCase.Defect_Type_Multi__c == '' )
                                    {
                                       trigger.new[0].addError('Please fill in the Resolution Details and Defect Type for this case.');
                                    }
           
         }       
}
  • November 24, 2014
  • Like
  • 1
I can't believe no one out there has wanted to do this but I've searched and searched and haven't found anything similar.  Specifically when converting a lead with an opportunity we'd like it to immedietly go to the add product page for the opportunity or at least just the page for the opportunity that was just created.  It seems like there should be some way to do this.  Something must tell it that it was just at the lead page and is now at the account page even if it's an existing account.  I just can't find how.  If anyone has any ideas on this I would love to hear them.

Thanks,
Amanda