• praveen kumar 110
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies
 ReadResult result = metadataConnection.readMetadata('CustomField', new String[]{'Account.TYPE'});
    for( Metadata data : result.getRecords() )
    {
        CustomObjectTranslation objectTranslation = (CustomObjectTranslation)data;
        for( CustomFieldTranslation fieldTranslation : objectTranslation.getFields() )
        {
            if( fieldTranslation.getPicklistValues().length > 0 )
            {
                System.out.println( 'Field: ' + fieldTranslation.getName() );
                for( PicklistValueTranslation value : fieldTranslation.getPicklistValues() )
                    System.out.println( '   '+ value.getMasterLabel() + ' -> ' + value.getTranslation() );
            }
        }
    }

I got below error:
---------------------
Unexpected token 'result'.

pubic class GSkController {


 public GSkController (ApexPages.StandardSetController setController)

{

  if(caseID!=null && caseId!='')
        {
            for(String strCaseId : caseId.split(','))
            {
                lstSelectedCaseIds.add(strCaseId);
            }
            if(lstSelectedCaseIds!=null && lstSelectedCaseIds.size()>0)
            {
                 lstSelectedCase = [select Id,Contact.Id,Contact.Name, Status from Case where ID in : lstSelectedCaseIds];
                                     
                                     System.debug('lstSelectedCase******'+lstSelectedCase[0].Contact.Id);

                    // "contact id is getting null"
            }


}


------------------------------------------------------------------------------------------------
Test Class:

@isTest(seeAllData=true)
private class TestGSkController {

  static testMethod void MyunitTest()
  {  
    
    Profile p = [select id, name from Profile where  name = 'System Administrator'];
     User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
      LocaleSidKey='en_US', ProfileId = p.Id,
      TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');

        
                
   Insert u;
       
    System.runAs(u)
    {
      
          Contact conTestContact = new contact();
      conTestContact.name='test';          
          insert conTestContact;

          System.debug('conTestContact***************'+conTestContact.id); // I am getting Id
    
        Case ObjCase=new Case();
        
           ObjCase.Name='test';       
        objCase.Contact=conTestContact;
        
    insert objcase;
        
        System.debug('objcase***********'+objcase.contact.id);  // I am getting id value  
    
       pageReference.getParameters().put('id',ObjCase.id);          
                    
                  
             GSkController ObjKey = new GSkController(new ApexPages.StandardSetController(Database.getQueryLocator([select Id,Contact.id from Case where ID =:ObjCase.id])));
            
  }
}
}

   
list<account>  lstaccout=[select name,phone,billingaddress from account where name='test' and phone='999999999' and address='test'];    am getting the list from out source with out id   i want to check it  in my account list if account is there update other wise upsert  the list of accounts
 ReadResult result = metadataConnection.readMetadata('CustomField', new String[]{'Account.TYPE'});
    for( Metadata data : result.getRecords() )
    {
        CustomObjectTranslation objectTranslation = (CustomObjectTranslation)data;
        for( CustomFieldTranslation fieldTranslation : objectTranslation.getFields() )
        {
            if( fieldTranslation.getPicklistValues().length > 0 )
            {
                System.out.println( 'Field: ' + fieldTranslation.getName() );
                for( PicklistValueTranslation value : fieldTranslation.getPicklistValues() )
                    System.out.println( '   '+ value.getMasterLabel() + ' -> ' + value.getTranslation() );
            }
        }
    }

I got below error:
---------------------
Unexpected token 'result'.

pubic class GSkController {


 public GSkController (ApexPages.StandardSetController setController)

{

  if(caseID!=null && caseId!='')
        {
            for(String strCaseId : caseId.split(','))
            {
                lstSelectedCaseIds.add(strCaseId);
            }
            if(lstSelectedCaseIds!=null && lstSelectedCaseIds.size()>0)
            {
                 lstSelectedCase = [select Id,Contact.Id,Contact.Name, Status from Case where ID in : lstSelectedCaseIds];
                                     
                                     System.debug('lstSelectedCase******'+lstSelectedCase[0].Contact.Id);

                    // "contact id is getting null"
            }


}


------------------------------------------------------------------------------------------------
Test Class:

@isTest(seeAllData=true)
private class TestGSkController {

  static testMethod void MyunitTest()
  {  
    
    Profile p = [select id, name from Profile where  name = 'System Administrator'];
     User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
      LocaleSidKey='en_US', ProfileId = p.Id,
      TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');

        
                
   Insert u;
       
    System.runAs(u)
    {
      
          Contact conTestContact = new contact();
      conTestContact.name='test';          
          insert conTestContact;

          System.debug('conTestContact***************'+conTestContact.id); // I am getting Id
    
        Case ObjCase=new Case();
        
           ObjCase.Name='test';       
        objCase.Contact=conTestContact;
        
    insert objcase;
        
        System.debug('objcase***********'+objcase.contact.id);  // I am getting id value  
    
       pageReference.getParameters().put('id',ObjCase.id);          
                    
                  
             GSkController ObjKey = new GSkController(new ApexPages.StandardSetController(Database.getQueryLocator([select Id,Contact.id from Case where ID =:ObjCase.id])));
            
  }
}
}

   
list<account>  lstaccout=[select name,phone,billingaddress from account where name='test' and phone='999999999' and address='test'];    am getting the list from out source with out id   i want to check it  in my account list if account is there update other wise upsert  the list of accounts
Here Is my Trigger:

trigger opportunityinsertupdate on Opportunity (before insert,before update) {
    if(checkRecursive.runOnce()) {
    Set<Id> accountIds = new Set<Id>();
        for(Opportunity currentOpportunity: Trigger.New) {
            accountIds.add(currentOpportunity.AccountId);
        }

        Map<Id, Account> accountMap = new Map<Id, Account>([Select Id, Super_Region__c from Account Where Id in:accountIds]);
        boolean flag=True;
        
     
 
            if(Trigger.isInsert){
                for(Opportunity opp: trigger.New){
                    system.debug('opp.name.===='+opp.name);
                    if(opp.name != null){
                        if(opp.name.startsWith('FO-')){
                            opp.CampaignId = '701U0000000QsAA';
                        }
                    }    
                 }
                for(opportunity o : trigger.new) {
                    if(accountMap.get(o.AccountId) != null) {
              
                        if(((o.Record_Type_Name__c == 'NC Power')||(o.Record_Type_Name__c == 'NC Oil & Gas')||(o.Record_Type_Name__c == 'NC Nuclear')) &&(o.stagename == 'Closed Won') && (o.FS_Included__c == false) && accountMap.get(o.AccountId).Super_Region__c == 'Asia/India') {
                            o.Name = o.Name + ' - FS Opp';
                            o.RecordTypeId = '012U0000000UIoX';
                            o.stagename = 'Sales Lead';
                            o.amount = 1;
                            o.CurrencyIsoCode = 'USD';
                            o.Target_ShipDate__c = o.CloseDate.addmonths(3);
                            flag = false;
                            o.FS_Included__c = true;
                        }
                     
                    }
                }
                  
                                                
                              
                    
                   
                
           
    }   
         
     if(trigger.isUpdate && flag)  {
     
            for(opportunity o1:trigger.new) {
                if(accountMap.get(o1.AccountId) != null) {
               
                        if(((o1.Record_Type_Name__c == 'NC Power')||(o1.Record_Type_Name__c == 'NC Oil & Gas')||(o1.Record_Type_Name__c == 'NC Nuclear')) &&(o1.stagename == 'Closed Won') && (o1.FS_Included__c == false) && accountMap.get(o1.AccountId).Super_Region__c == 'Asia/India') {
                                              
                            Opportunity o2= new opportunity();
                            o2.name = o1.name+' - Fsopp';
                            o2.CloseDate = o1.CloseDate;
                            o2.RecordTypeId = '012U0000000UIoX';
                            o2.stagename = 'Sales Lead';
                            o2.amount = 1;
                            o2.CurrencyIsoCode = 'USD';
                        
                            o2.Target_ShipDate__c = o1.CloseDate.addmonths(3);
                          
                            o2.FS_Included__c = true;
                            insert o2;
                    
                        }
                 
                }
            }
        }
}

}
please help me writing the test class for this trigger

thanks in advance..