public with sharing class NewRepairPartsController { public RepairPart__c repairPart{get;set;} public String swoId{get;set;} public String repairId{get;set;} public Boolean pageClose{get;set;} public String baseUrl{get;set;} public String productId{get;set;} /*public NewRepairPartsController(ApexPages.StandardController stdController) { swoId = System.currentPageReference().getParameters().get('swoId'); }*/ public NewRepairPartsController() { swoId = System.currentPageReference().getParameters().get('swoId'); repairId = System.currentPageReference().getParameters().get('id'); } public void init(){ baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); String path = URL.getCurrentRequestUrl().getPath(); if (path.indexOf('/apex') > 0) { baseUrl += path.substring(0, path.indexOf('/apex')); } else if (path.indexOf('production/') > 0) { baseUrl += '/production'; } if(String.isNotBlank(repairId)){ Schema.DescribeSobjectResult repairPartType = RepairPart__c.sObjectType.getDescribe(); Map repairPart_fields = repairPartType.fields.getMap(); String soql_repair = 'select '; String fields = ''; for (String field : repairPart_fields.keySet()) { if (fields.length() > 0) { fields += ', '; } fields += field; } soql_repair += fields; soql_repair += ' from RepairPart__c where Id = \'' + repairId + '\''; repairPart = Database.query(soql_repair); }else{ repairPart = new RepairPart__c(); if(String.isNotBlank(swoId)){ repairPart.SWO_ID__c = swoId; } } } public void save(){ pageClose = false; upsert repairPart; pageClose = true; System.debug('id:'+repairPart.Id); repairId = repairPart.Id; return; } public Boolean mastData(){ Boolean temp = true; if(repairPart.Product__c == null){ repairPart.Product__c.addError('ITEM can not be empty'); temp = false; } if(repairPart.QUANTITY__c == null){ repairPart.QUANTITY__c.addError('QUANTITY can not be empty'); temp = false; } if(repairPart.LOCATION__c == null){ repairPart.LOCATION__c.addError('LOCATION can not be empty'); temp = false; } System.debug('temp:'+temp); return temp; } public void deleteAction(){ pageClose = true; if(String.isNotBlank(repairPart.Id)){ delete repairPart; return; }else{ return; } } public void productReturn(){ if(String.isNotBlank(productId)){ List productList = [SELECT Id, Name, Product_ECCode__c, Description, ProductCode FROM Product2 WHERE Id = :productId limit 1]; if(productList!=null && productList.size()!=0){ repairPart.PART_NUMBER__c = productList[0].Product_ECCode__c; repairPart.DESCRIPTION__c = productList[0].Description; repairPart.ITEM__c = productList[0].ProductCode; } } } }