• Lavanya
  • NEWBIE
  • 25 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 34
    Questions
  • 45
    Replies
Hi All, I have created a code to capture a customer signature and added it has attachment to that account.This working fine, but when I added this code to my vf page which is created using datatable. In that datatable I am having a custom button " Sign" when the user click on the button it will show a popup, from that popup I need to capture the signature. I have created this popup using output panel but I can't able to draw the signature on popup.Kindly give me any idea for this.
Here is link to my code:
<!-- SignUp Popup Start-->
<apex:outputPanel id="signuppopup">
  
    <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
    <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}" style="overflow:auto; width:800px; height:500px;">
        <!-- <apex:commandButton value="Submit" action="{!saveAnswers}" rerender="signuppopup"/>
        <apex:commandButton value="Save" action="{!saveAnswers}" rerender="signuppopup"/>-->
    <apex:commandButton value="HidePopup" action="{!closePopup}" rerender="signuppopup" style="float:right" />
      
          
        <!-------------- Account Detail Header --------------->
        <apex:pageBlock >
        <apex:pageBlockSection title="Account Details" columns="2">
        <apex:outputField value="{!CSignup.Acc.Name}"/>
        <apex:outputField value="{!CSignup.Acc.SAP_Customer__c}"/>
        <apex:outputField value="{!CSignup.Acc.Customer_Category__c}"/>
        <apex:outputField value="{!CSignup.Acc.Customer_Grading__c}"/>       
        <apex:outputField value="{!CSignup.Acc.Customer_Price_Group__c}"/>       
        <apex:outputField value="{!CSignup.Acc.ABC_Class__c}"/>
        <apex:outputField value="{!CSignup.Acc.Account_Status__c}"/>
        <apex:outputField value="{!CSignup.Acc.Sales_Office__c}"/> 
        </apex:pageBlockSection> 
            <apex:pageBlockSection title="SIGNUP FORM"></apex:pageBlockSection>
            <!--<button onclick="findAccounts();" value = "sign" rerender="signature"/>-->
          <!--<apex:commandButton value="Submit" action="{!saveSignature}" rerender="signature"/>-->
        <!-------------- End of Account Detail Header ---------------> 
    <!--</apex:pageBlock>
        <apex:pageBlock >-->
<script>var $j = jQuery.noConflict();</script>
<apex:stylesheet value="{!URLFOR($Resource.jquerymobile132mincss,'styles.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.jqueryjs)}"  />
<apex:includeScript value="{!URLFOR($Resource.jquerymobile132minjs)}"/>

<div data-role="page" id="signatureCaptureHome">
<div data-role="content">
<input id="accountNameId" type="text" name="accountName"/>
<input type="button" name="findAccountBtn" onclick="findAccounts();" value="Find Accounts"/>
<h1 id="recordSigId">Record Signature:</h1>
<canvas id="signatureCanvas" height="200px" width="300px"/>
<input id="saveSigButton" type="button" name="SigCap" onclick="saveSignature();" value="Capture Signature"></input>
</div>
</div>
<div data-role="page" id="signatureCaptureHome">
<div data-role="content">
<input id="accountNameId" type="text" name="accountName"/>
<input type="button" name="findAccountBtn" onclick="findAccounts();" value="Find Accounts"/>
</div>
</div>
<!-------------------->
<script>

    var canvas;
    var context;
    var drawingUtil;
    var isDrawing = false;
    var accountId = '';

function DrawingUtil()
{
    isDrawing = false;
    canvas.addEventListener("touchstart",start,false);
    canvas.addEventListener("touchmove",draw,false);
    canvas.addEventListener("touchend",stop,false);
    context.strokeStyle = "#FFF"; 
}

//Start Event for Signature Captuare on HTML5 Canvas
function start(event)
{
    isDrawing = true;
    canvas = document.getElementById("signatureCanvas");
    context = canvas.getContext("2d");   
    context.strokeStyle = "rgba(155,0,0,0.5)";     
    context.beginPath();
     context.moveTo(event.touches[0].pageX - canvas.getBoundingClientRect().left,event.touches[0].pageY - canvas.getBoundingClientRect().top);
}

//Event while someone is drawing to caputre the path while they draw....
function draw(event) {
    event.preventDefault();
    if(isDrawing) {   
        context.lineTo(event.touches[0].pageX - canvas.getBoundingClientRect().left,event.touches[0].pageY - canvas.getBoundingClientRect().top);
        context.stroke();
    }
}


//Event when someone stops drawing their signature line
function stop(event) {
    if(isDrawing) {
        context.stroke();
        context.closePath();
        isDrawing = false;
    }
}

canvas = document.getElementById("signatureCanvas");
context = canvas.getContext("2d");
drawingUtil = new DrawingUtil(canvas);

function saveSignature()
{
var strDataURI = canvas.toDataURL();
    // alert(strDataURI);
    strDataURI = strDataURI.replace(/^data:image\/(png|jpg);base64,/, "");
//alert(strDataURI);
//AnyObjectSignatureController.saveSignature(strDataURI,accountId,processResult);
CSignup.saveSignature(strDataURI,accountId,processResult);
}

function processResult(result)
{
alert(JSON.stringify(result));
}

function findAccounts()
{
var nameValue = document.getElementById("accountNameId").value;
//AnyObjectSignatureController.findAccounts(nameValue, processSearchResult);
CSignup.saveSignature(strDataURI,accountId,processResult);
}

function processSearchResult(result)
{
$j = jQuery.noConflict();
//$j("#accountList").html("");
$j.each(result, function(i, record) {accountId = record.Id; $j("#recordSigId").html("Record Signature: " + record.Name);});
$j("#recordSigId").trigger("update");
//$j("#accountList").trigger("update");
//alert(JSON.stringify(result));
}


</script>
  
<!----------------->   

        </apex:pageBlock>
    </apex:outputPanel>
</apex:outputPanel>
<!-- SignUp Popup End-->
<apex:pageBlock Title=" Plan" id="table1">
<apex:dataTable value="{!list1}" var="a" columnswidth="50px,50px">
<apex:column headervalue="{!firstheader}" />
</apex:dataTable>
<apex:pageBlockSection >     
<apex:dataTable value="{!list1}" var="a" columnswidth="50px,50px" cellpadding="5" columns="8" border="1" width="1150px" bgcolor="#c7d6f2" rowClasses="1" >
<apex:commandButton value="SIGNUP FORM" action="{!getSignupfuntion}" disabled="{!disableList1}" reRender="signuppopup">
               <apex:param name="p1" value="{!a.jpd.AccountName__c}" assignTo="{!recordId}"/>
         </apex:commandButton>&nbsp;
</apex:column> 
          
</apex:dataTable>
<!--</apex:pageBlockTable>-->

</apex:pageBlockSection>
</apex:pageBlock>

I am having one custom object "Site" which has lookup relationship with opportunity. Which means each site record has more than one opportunity. For example if a site record has 5 opportunity in that 4 opportunity has already closed then when i am trying to close the last opportunity in that site record it must display a alert message " your opportunity is closed, would you like to close the site record also yes or no". If i press yes means it must go to that particular site record their we can manually close the site record.

Hi All,

 

       I have wirtten a apex code and Vf page for uplaoding a csv file to create a new Account, Contact. In my file the account is given in lower case letter, i need to change it to upper case letter and then  need to save in to salesforce. I tried  but can't get solution for this. Kindly any tell how to resolve this and also tell me any links for this. Here i have attached the code also. Thanks in advance

 

Code:

 

for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
String SalesforceAccountNumber = inputvalues[2];
Acc_Bulider = inputvalues[3];
if(Acc_Bulider != 'Builder Unknown')
{

Account a = new Account();
a.Name = inputvalues[3];

acctNames.add(a.Name);
  accstoupload.add(a);
}

}

 

Hi All,

 

     I hvae created a new custom button "craete opportunity" on my custom object which will create 10 opporutunity at a time which is VF page. Now i need to add the "notes" to my opportunity which each opportunity will have notes.Note field is an long text area, value typed here must be saved as a notes in that particular opportunity. This note field should be below that opportunity. Can any one tell how to do this using Vf and apex code. also tell me any links for this, waiting for your reply. Thanks in advance.

 

 

 

 

Regards

Lavanya.

 

I have created a VF page for Opportunity, added this new vf page to Opportunity new button. When I am creating a new Opportunity, probability is showing in correct value. For example if I select the stage as "Negotiation" the probability should be "80%" but it's showing "10%". I am using PE, kindly any one tell how to resolve this and also tell any links for this. Thanks in advance, waiting for your reply.

VF Page:
>**apex:inputfield value="{!Opportunity.StageName}" required="true" id="stage" onclick="changeblock();"/>

>apex:outputfield value="{!Opportunity.Probability}" />**

Hi All,I have created a Apex code for my custom object button which will create a 10 opportunity. Now i need to move this to production. I didn't have any idea about writting test class, Can anyone help me how to write test class for this,also tell me any link about class. I am new to salesforce this is the first time I am going to write test class.Thanks in advance,waiting for your reply.

 

Apex Code:

 

public class Conversion_site
{
    private Site__c siteObj;
    public String Sales_pop {get; set;}
    private List<Opportunity> lstOpp = new List<Opportunity>();
    public List<opportunityRecords> lstOppRecords {get; set;}
    public Map<Integer, opportunityRecords> mapOppRecords {get; set;}
    public Integer selectedRowIndex {get; set;}
    public Integer rowCount {get; set;}
    private Integer intialCount = 10;
    private Integer maxCount {get; set;}
    public List<String> lstOppName {get; set;}
    private Map<Integer, String> mapOppName {get; set;}
    private Map<Integer, String> mappedOppName = new Map<Integer, String>();
    public String dateTimeValue { get; set; }
    public Boolean showOppRec {get; set;}

/*Opportunity records*/
public class opportunityRecords implements Comparable
{
    //Holds record Index
    public Integer recIndex {get; set;}
    public String oppType {get; set;}
    public Opportunity opp {get; set;}
    public Boolean rendered {get; set;}

    public opportunityRecords(Integer index)
    {
        recIndex = index;
        opp = new Opportunity();
        rendered = true;
    }

    // Implement the compareTo() method
    public Integer compareTo(Object compareTo) {
        opportunityRecords oppRec = (opportunityRecords)compareTo;
        if (recIndex == oppRec.recIndex) return 0;
        if (recIndex > oppRec.recIndex) return 1;
        return -1;        
    }
}

////save the records by adding the elements in the inner class list to lstAcct,return to the same page
public PageReference Convert()
{
    system.debug('>>>Inside convert');
    PageReference pr = new PageReference('/' + siteObj.Id);
    Integer totalRows = 0;
    lstOpp.clear();
    for(opportunityRecords oppRec : lstOppRecords)
    {
        if(oppRec.rendered)
        {
            totalRows++;
            oppRec.opp.Name = siteObj.Name+'-'+oppRec.oppType;
            oppRec.opp.Site_Ref_No__c = siteObj.Site_Ref_No__c;
            oppRec.opp.Site_Lead__c = siteObj.Id;
            if(oppRec.opp.StageName == 'No Contact Made')
                oppRec.opp.Probability= 0;
            else if(oppRec.opp.StageName == 'Contact Made')
                oppRec.opp.Probability= 10;
            else if(oppRec.opp.StageName == 'Taking Off')
                oppRec.opp.Probability= 25;
            else if(oppRec.opp.StageName == 'Quotation with Customer ')
                oppRec.opp.Probability= 50;
            else if(oppRec.opp.StageName == 'Negotiation/Review')
                oppRec.opp.Probability= 75;
            else if(oppRec.opp.StageName == 'Closed Won')
                oppRec.opp.Probability= 100;
            else if(oppRec.opp.StageName == 'Closed Lost')
                oppRec.opp.Probability= 0;

            if (oppRec.opp.AccountId != null && oppRec.opp.CloseDate != null && oppRec.opp.OwnerId != null)
            {    /*Default user as Opp owner*/
                /*if (oppRec.opp.OwnerId == null)
                    oppRec.opp.OwnerId = UserInfo.getUserId();*/
                system.debug('>>>Check already available:');
                system.debug(oppRec.opp);
                lstOpp.add(oppRec.opp);
                //mapOppRecords.remove(oppRec.recIndex);
                oppRec.rendered = false;
                mapOppRecords.put(oppRec.recIndex,oppRec);
                rowCount = rowCount - 1;
            }
        }
    }
    insert lstOpp;
    if (lstOpp.size() != totalRows)
    {
        clearAndPopulateList();
        String successMsg = '';
        if(lstOpp.size() > 0)
        {
            if(lstOpp.size() == 1)
                successMsg = 'Successfully Created ' + lstOpp.size() + ' Opportunity';
            else if(lstOpp.size() > 1)
                successMsg = 'Successfully Created ' + lstOpp.size() + ' Opportunities';
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,successMsg));   
        }
        String errorMsg = 'Please enter Account,Sales Person and Close Date for below Opportunities. Otherwise click cancel to go back to Site Leads page.';

        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO,errorMsg));

        pr = null;
    }
    else
    {
        showOppRec = false;
        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'All Opportunities created successfully. Please click cancel to go back to Site Leads page.')); 
        //pr.setRedirect(True);
        pr = null;
    }
    return pr;
}

//add one more row
public void Add()
{   
    if (rowCount < maxCount)
    {
        rowCount = rowCount+1;
        addMore();
        clearAndPopulateMap();
    }
    else
    {
        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Maximum row that can be added is ' + maxCount));
        //return null;
    }
}

/*Begin addMore*/
public void addMore()
{
//clearAndPopulateMap();
    //call to the iner class constructor
    Set<Integer> setName = mapOppName.keySet();
    List<Integer> lstName = new List<Integer>();
    lstName.addAll(setName);
    mappedOppName.put(lstName[0], mapOppName.get(lstName[0]));
    mapOppName.remove(lstName[0]);
    opportunityRecords oppRecord = new opportunityRecords(rowCount);
    oppRecord.oppType = mappedOppName.get(lstName[0]);
 /*----Default value for Account and Salesperson----*/
  /*Id accId = siteObj.Account__c;
    system.debug('accId' + accId);
    if (accId != null)
    {
        oppRecord.opp.AccountId = accId;
        Id ownerid = getSalesPerson(oppRecord.opp.AccountId);
        if (ownerid != null)
            oppRecord.opp.OwnerId = ownerid;
    }*/
   // oppRecord.opp.CloseDate = siteObj.Completion_Date__c;
    oppRecord.opp.CloseDate=date.today()+7;
    oppRecord.opp.StageName = 'No Contact Made';
    //add the record to the inner class list
    lstOppRecords.add(oppRecord);
//clearAndPopulateMap();
    system.debug('lstOppRecords---->'+lstOppRecords);            
}/* end addMore*/


private void clearAndPopulateMap()
{
    if(!lstOppRecords.isEmpty())
    {
        mapOppRecords.clear();
        for(opportunityRecords oppRec : lstOppRecords)
        {
            mapOppRecords.put(oppRec.recIndex, oppRec);
        }
        lstOppRecords.sort();
    }
}

private void clearAndPopulateList()
{
    if(!lstOppRecords.isEmpty())
    {
        lstOppRecords.clear();
        lstOppRecords = mapOppRecords.values();
        lstOppRecords.sort();
    }
}

/* begin delete */
public PageReference Del()
{
    /*if(rowCount > 1)
    {
        system.debug('selected row index---->'+selectedRowIndex);
        //lstOppRecords.remove(selectedRowIndex-1);
        opportunityRecords opRec = mapOppRecords.get(selectedRowIndex);
        for(Integer i = 0; i < mapOppRecords.size(); i++)
        {
            if (mappedOppName.containsKey(i) && mappedOppName.get(i) == opRec.oppType)
            {
                mapOppName.put(i, mappedOppName.get(i));
                mappedOppName.remove(i);
                break;
            }
        }
    mapOppRecords.remove(selectedRowIndex);
        rowCount = rowCount - 1;
    clearAndPopulateList();
        return null;
    }
    else
    {
        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please enter atleast one Opportunity.'));
        return null;
    }*/
    return null;

} /*End del*/

private void AddOpportunity(Integer rc)
{
    for(Integer i = 0; i < rc; i++) 
    {
        rowCount += i;
        addMore();
    }
    clearAndPopulateMap();
}

//Sales Person Populate from Account
public Id getSalesPerson(Id accountid)
{
    Id salesPersonId = [select EXO_Sales_Rep__r.id, EXO_Sales_Rep__r.Name 
                    from Account 
                    where id=:accountid 
                    LIMIT 1].EXO_Sales_Rep__r.Id;
    return salesPersonId;
}

//OnChange SalesPerson Populate
public void SalesPersonPopulate()
{
    system.debug('>>>ListOpprec start ' + lstOppRecords);
    opportunityRecords opRec = mapOppRecords.get(selectedRowIndex);
    if (opRec.opp.AccountId != null)
    {
        Id ownerid = getSalesPerson(opRec.opp.AccountId);
        opRec.opp.OwnerId = ownerid;
        mapOppRecords.put(selectedRowIndex, opRec);
        clearAndPopulateList();
    }
    system.debug('>>>ListOpprec start ' + lstOppRecords);
}

private void opportunityList()
{
    lstOppName = new List<String>();
    mapOppName = new Map<Integer, String>();
    lstOppName.add('Floor Systems');
    lstOppName.add('Footings & Concrete');
    lstOppName.add('Frames');
    lstOppName.add('Roof');
    lstOppName.add('External Cladding');
    lstOppName.add('Plasterer');
    lstOppName.add('Fix out');
    lstOppName.add('Renderer');
    lstOppName.add('Retaining Walls / Landscaping');
    lstOppName.add('Hire');
    maxCount = lstOppName.size();
    for(Integer i = 0; i < maxCount; i++)
    {
        mapOppName.put(i, lstOppName[i]);
    }
}
public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
    for(String name : lstOppName)
    {
        options.add(new SelectOption(name,name));
    }
    return options;
}

/*Constructor*/
public Conversion_site(ApexPages.StandardController stdController)
{  dateTimeValue = System.Now().format('dd/MM/yyyy');//GMT 
    siteObj = (Site__c)stdController.getRecord();
    lstOppRecords = new List<opportunityRecords>();
    mapOppRecords = new Map<Integer, opportunityRecords>();
    opportunityList();
    rowCount = 0;
    AddOpportunity(intialCount);
    selectedRowIndex = 0;
    showOppRec = true;
}/*End Constructor*/

Hi All, In my custom object  std detailed page layout, I need to change the "Back to list". I  have searched  but I didn't get any solution. Kindly  any one tell how to change and also send me any links for this. Thanks in advance, waiting for your reply.

 

Regards,

Lavanya.

Hi All,

when I save the below formula, it shows this error:

 

Error: Compiled formula is too big to execute (19,959 characters). Maximum size is 5,000 character

 

if the sum of Value_1__c to Value_13__c <= 10, then  display level 1

if the sum of Value_1__c to Value_13__c >10 and Value_1__c to Value_13__c <= 18, then  display level 2

if the sum of Value_1__c to Value_13__c >18 then level 3

 

 

formula value:

if((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) <= 10

&&
(Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c ) <> 0 , "Level 1",
if( AND((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c + Value_10__c + Value_11__c + Value_12__c + Value_13__c) > 10
&&
(Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) <= 18), "Level 2",
if((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) > 18,"Level 3",
"Level Not Calculated Yet" )))

 

 

All field Value_1__c to Value_13__c also formula field which get s the value from the picklist selected.

 

we tried this also:

 

total_risk_cal__c = Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c


if((total_risk_cal__c) <= 10
&&
(total_risk_cal__c ) <> 0 , "Level 1",
if( AND((total_risk_cal__c) > 10
&&
(total_risk_cal__c) <= 18), "Level 2",
if((total_risk_cal__c) > 18,"Level 3",
"Level Not Calculated Yet" )))

 

but getting same error. We are trying an alternate method of creating a whole page using VF. We didn't get any ideal for how to give fomula field dynmaically in Visual force we are using professional edition. Kindly any one tell how to dao this and please send me any sample code for this also some links. Thanks in advance, waiting for you reply.

 

Regards,

Lavanya.

 

 

Hi All,

 

          I am uploading a csv using apex programming to upload  data to my custom object. I am getting this error while uploading  csv file. Some the same is uploading correctly. Can one tell how to resolve this. I tried a lot but i couldn't resolve this.

 

Error:

List index out of bounds: 5
Error is in expression '{!ReadFile}' in page 

 

Thanks,

public class NHS_Project_DataUpload_1
{

    public NHS_Project_DataUpload_1(ApexPages.StandardController controller) {

    }

/*public FileUploaderAll(ApexPages.StandardController controller) {
}*/

public PageReference fileAccess() {
return null;
}


public String dateTimeValue { get; set; }
public  NHS_Project_DataUpload_1(){
dateTimeValue = System.Now().format('dd/MM/yyyy');//GMT
}
 public string  siteCordell_acc;
 public string  Acc_cordell_acc;
 //public string  opp_site_cordell_acc; 
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Account> accstoupload;
List<Contact> contoupload;
List<Opportunity> opptoupload;
List<Site__c> sitetoupload;
 List<String> acctNames;
 
List<Account> newAccts = new List<Account>();
List<Account> existAccts = new List<Account>();
public Pagereference ReadFile()
{
  nameFile=contentFile.toString();
  filelines = nameFile.split('\n');
  accstoupload = new List<Account>();
  contoupload = new List<Contact>();
  opptoupload = new List<Opportunity>();
  sitetoupload = new List<Site__c>();
  acctNames = new List<String>();
  List<Account> existingAccts =new List<Account>();
     for (Integer i=1;i<filelines.size();i++)
      {
      
         String[] inputvalues = new String[]{};
         inputvalues = filelines[i].split(',');
         String Role_Description_Acct ;
          Role_Description_Acct = inputvalues[14];
      if(( Role_Description_Acct  == 'Builder') || ( Role_Description_Acct  == 'Contractor') || ( Role_Description_Acct  == 'Construction Manager')||(Role_Description_Acct == ''))
        { 
         
         Account a = new Account();
          
          a.Name = inputvalues[28];
          a.BillingStreet  = inputvalues[29];
          a.BillingCity = inputvalues[30];             
          a.BillingState = inputvalues[31];
          a.BillingPostalCode = inputvalues[32];
          a.Phone = inputvalues[33];
          a.Fax = inputvalues[34];           
          a.Email__c = inputvalues[35]; 
          a.Cordell_Account_Number__c=inputvalues[13];
         // a.BillingCountry = inputvalues[4];
                   
         
          acctNames.add(a.Name);
          accstoupload.add(a);
          
         }
  // accstoupload.add(a);
    }
   // existingAccts = [SELECT Id, Name FROM Account where name in :acctNames];
// existingAccts = [SELECT Cordell_Account_Number__c, Name FROM Account where Cordell_Account_Number__c in :acctNames];    
     existingAccts = [SELECT Cordell_Account_Number__c, Name FROM Account where name in :acctNames];
    
   //create a map with names as key
   Map<String, Id> acctNamesIdMap = new Map<String, Id>();
//Creating Map for with names as key for exising account to create Opportunity   
   
     // load the map - this will help you find out if an account name exists already
    for (Account acct : existingAccts)
      {
        acctNamesIdMap.put(acct.Name, acct.Id);
        //acctNamesIdMap.put(acct.Name, acct.Cordell_Account_Number__c);//checking existing account using cordell account no
        //existAccts=[SELECT Cordell_Account_Number__c FROM Account where name in :acctNames];
         System.debug('******Voltum******');
       ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'Account ' + acct.Name + ' already exists,Duplicate Account Name not allowed');
      ApexPages.addMessage(errormsg);
      }
    
    for (Account acct : accstoupload)
      {
       //if account name does not exist in map, add it to list of new accounts
       // if (!acctNamesIdMap.containsKey(acct.Cordell_Account_Number__c))       
     if (!acctNamesIdMap.containsKey(acct.Name))    
              
          {
            newAccts.add(acct);
ApexPages.Message successmsg = new ApexPages.Message(ApexPages.severity.confirm,'New Account ' + acct.Name + ' is created,related Contact, Opportunity and Site record also created');
ApexPages.addMessage(successmsg);
         }
        
      }
      
    try
    {
    
     insert newAccts;
    
     
    /* ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.info,'AccountName with Account Id are the new Account created.Related Contact and Opportunity also created');
     ApexPages.Message msg1 = new ApexPages.Message(ApexPages.severity.info,'AccountName without Account Id are the existing Accounts');
     ApexPages.addMessage(msg);
     ApexPages.addMessage(msg1);*/
          
    }
     catch (Exception e)
    {
   // update existAccts;
    ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'Account Name already exist, change Account Name and try again');
     ApexPages.addMessage(errormsg);
      
    }
    
    //Query Inserted Records for Account and Builts a Map (mapAccInserted)
    Set<String> setAccCordellId = new Set<String>();
    for (Account acct : accstoupload)
    {
        if(!setAccCordellId.contains(acct.Cordell_Account_Number__c))
        {
            setAccCordellId.add(acct.Cordell_Account_Number__c);
        }
    }
    Map<String, Account> mapAccInserted = new Map<String, Account>();
    Map<String, Account> mapAccInserted1 = new Map<String, Account>();
    List<Account> lstAccInserted = new List<Account>([SELECT Id, Name, Cordell_Account_Number__c
                                                        FROM Account
                                                        WHERE Cordell_Account_Number__c in :setAccCordellId]);
    for(Account a: lstAccInserted)
    {
        mapAccInserted.put(a.Cordell_Account_Number__c, a);
         //mapAccInserted1.put(a.Id, a);
    }
    
//accstoupload = [SELECT Id, Name FROM Account  WHERE Cordell_Account_Number__c in :setAccCordellId];
 
                                                   
   /* for(Account a: accstoupload)
    {
        
         mapAccInserted1.put(a.Id, a);
    }*/
     
 
system.debug('>>>mapAccInserted' + mapAccInserted);
//return null;
for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');
Contact con = new Contact();
/*****************************************************/
String  Cordell_AccNo_Con;
//String Acc_Id;

Cordell_AccNo_Con = inputconvalues [13];

//Contact con = new Contact();
/************************************ getting  Account for contact ***********************************/
/*for(account a: accstoupload)
{
   Account  Acc_Id = mapAccInserted1.get(a.Id);

 // Account Acc_cordell_acc_con = mapAccInserted.get(Cordell_AccNo_Con);
 
 // Account Acc_cordell_acc_con = mapAccInserted.get(Acc_Id);
system.debug('>>>Map Acc cordell_insert:' +Acc_cordell_acc);
 if( Acc_Id !=null)
//if(!mapAccInserted.containsKey( Acc_cordell_acc_con))
// con.AccountId = Acc_cordell_acc_con.Id;
 con.AccountId =  Acc_Id.Id;
 
}
 if(con.AccountId !=null)
 {
//opp.AccountId = Acc_cordell_acc.Account__c;
con.Lastname = inputconvalues[36];
con.Email = inputconvalues[37];
con.Phone = inputconvalues[38];

contoupload.add(con);
 }*/
 
/*************************************************************/
 

 
 /*for(account a: accstoupload)
{
con.AccountId = accstoupload.id;
//con.AccountId = accstoupload[i-1].id;
//********con.AccountId = accstoupload[i-1].Cordell_Account_Number__c;
} 
if(con.AccountId!= null)
{

con.Lastname = inputconvalues[36];
con.Email = inputconvalues[37];
con.Phone = inputconvalues[38];

contoupload.add(con);
}*/
for(Account a: accstoupload)
{
//con.AccountId = accstoupload.id;
con.AccountId =accstoupload[i-1].id;
//********con.AccountId = accstoupload[i-1].Cordell_Account_Number__c;
} 
if(con.AccountId!= null)
{

con.Lastname = inputconvalues[36];
con.Email = inputconvalues[37];
con.Phone = inputconvalues[38];

contoupload.add(con);
}


}
try
{
insert contoupload;

}

catch (Exception e1)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.INFO,'Account Name associate with this Contact already exist ');
ApexPages.addMessage(errormsg);
}
// return null;

for (Integer i=1;i<filelines.size();i++)
{
String[] inputsitevalues = new String[]{};
inputsitevalues = filelines[i].split(',');
String Role_Description_site;
//Site__c site= new Site__c();
//to get the acc_id for site
/*for(account a: accstoupload)
{
//site.Site_Acc__c = accstoupload[i-1].id;
site.Cordell_Account_No__c= accstoupload[i-1].Cordell_Account_Number__c;
} */

//site.CompanyName__c = inputsitevalues[0];
// no account exist create new site
//if(site.Cordell_Account_No__c!= null)
//if(site.Cordell_Account_No__c== null)
//{
//Project import page
//************* new site creating if cordell numberis not in account ******/
Role_Description_site= inputsitevalues[14];
if((Role_Description_site == 'Builder') || (Role_Description_site  == 'Contractor') || (Role_Description_site == 'Construction Manager')|| (Role_Description_site == ''))
{ 
         Site__c site= new Site__c();
        site.Cordell_Account_No__c = inputsitevalues[13];
        system.debug('>>>Map Acc INserted:' + mapAccInserted.get(site.Cordell_Account_No__c));   
          /*************************/
           Account siteCordell_acc = mapAccInserted.get(site.Cordell_Account_No__c);
            if(siteCordell_acc!= null)
               {
                site.Account__c = siteCordell_acc.Id;
               } 

   site.Project_ID__c = inputsitevalues[0];
   site.Project_Title__c = inputsitevalues[1];
   site.Site_Address__c = inputsitevalues[2];
   site.Project_City__c = inputsitevalues[3];
   site.State__c= inputsitevalues[4];
   site.Post_code__c= inputsitevalues[5];
   site.Council__c = inputsitevalues[6];
   site.Type__c = inputsitevalues[7];
   site.Project_First_Reported__c =date.today();//**Date field**
   site.Estimated_Value__c =decimal.valueOf(inputsitevalues[9]);
   site.Project_Details__c = inputsitevalues[10];
   site.Project_Additional_Details__c= inputsitevalues[11];
   site.Development_Type__c = inputsitevalues[12];
        if(site.Development_Type__c=='New')
              site.Category_s__c  = 'Commercial - New';
       else
              site.Category_s__c  = 'Commercial - Add & Alter';
      
    site.Role_Description__c = inputsitevalues[14];
    site.Tender_Type__c = inputsitevalues[15];
   site.Floor_Area__c = integer.valueOf(inputsitevalues[16]);
   site.Floors__c = integer.valueOf(inputsitevalues[17]);
   site.Ownership__c = inputsitevalues[18];
    //site.Tender_Due_Date__c =date.today();//**date field** [19]
    site.Tender_Due_Date__c = date.parse(inputsitevalues[19]);//**date field[19]
    //site.Commence_Date__c =date.today();//**date field**[20]
     site.Commence_Date__c= date.parse(inputsitevalues[20]);//**date field[20]
    // site.Completion_Date__c=date.today();//**date field**[21]
    site.Completion_Date__c= date.parse(inputsitevalues[21]);//**date field[21]
     //site.Last_Updated__c = date.today();//**date field**[22]
    site.Last_Updated__c = date.parse(inputsitevalues[22]);//**date field[22]
    //site.Status__c = inputsitevalues[23];
    site.Note__c = inputsitevalues[24];
    site.Project_Stage__c = inputsitevalues[25];
    site.Site_Area__c =integer.valueOf(inputsitevalues[26]);
    site.Units__c = integer.valueOf(inputsitevalues[27]);
     //site.Account__c=inputsitevalues[28];//Main Contractor
    site.Cordell_Account_No__c=inputsitevalues[13];
    site.Company_Name__c = inputsitevalues[28];
    site.Company_Address__c = inputsitevalues[29];
    site.Company_City__c = inputsitevalues[30];
    site.Company_State__c= inputsitevalues[31];
    site.Company_Postal_Code__c = inputsitevalues[32];
    site.Company_Phone__c = inputsitevalues[33];
    site.Company_Fax__c = inputsitevalues[34];
    site.Company_Email__c= inputsitevalues[35];
    site.Contact_Name__c = inputsitevalues[36];
    site.Contact_Email__c = inputsitevalues[37];
    site.Contact_Mobile__c = inputsitevalues[38];
    site.Name =inputsitevalues[1] ;// Project title is site name
    site.Source_s__c = 'Cordell';             

/***************************************************************************/              
 // site.Company_ID__c = integer.valueOf(inputsitevalues[13]);
  //  site.Cordell_Account_No__c = inputsitevalues[13];
   //system.debug('>>>Map Acc INserted:' + mapAccInserted.get(site.Cordell_Account_No__c));



 /*siteCordell_acc = mapAccInserted.get(site.Cordell_Account_No__c).Id;
if(siteCordell_acc!= null)
{
 
site.Account__c = siteCordell_acc;  
}*/



//site.Role_Description__c = inputsitevalues[14];

/*************** end of new site reating if cordell account number in account **************/


 sitetoupload.add(site);
}
}
try
{
insert  sitetoupload;
ApexPages.Message sitecreatedmsg = new ApexPages.Message(ApexPages.severity.confirm,'New Site Lead created');
       ApexPages.addMessage(sitecreatedmsg);
}
catch (Exception e3)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}

//Query Inserted Records for Site and Builts a Map (mapSiteInserted)
    Set<String> setSiteCordellId = new Set<String>();
    for (Site__c site : sitetoupload)
    {
        if(!setSiteCordellId.contains(site.Cordell_Account_No__c))
        {
            setSiteCordellId.add(site.Cordell_Account_No__c);
        }
    }
    Map<String, Site__c> mapSiteInserted = new Map<String, Site__c>();
    List<Site__c> lstSiteInserted = new List<Site__c>([SELECT Id, Name, Cordell_Account_No__c, Site_Ref_No__c, Account__c,Project_ID__c,
                                                       Site_Address__c     FROM Site__c
                                                        WHERE Cordell_Account_No__c in :setSiteCordellId]);
    for(Site__c s: lstSiteInserted)
    {
        mapSiteInserted.put(s.Cordell_Account_No__c+s.Project_ID__c+s.Site_Address__c, s);
    }

for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');

Opportunity opp = new Opportunity();
/*for(account a: accstoupload)
{
opp.AccountId = accstoupload[i-1].id;
//opp.AccountId = accstoupload[i-1].Cordell_Account_Number__c;
//opp.AccountId = a.Id;
}
if(opp.AccountId!= null)
{*/
opp.Name = inputvalues[0]+'-'+ inputvalues[1];
//opp.CloseDate =date.parse(inputvalues[21]);
opp.StageName = 'No Contact Made';
opp.Cordell_AccNo_Opp__c = inputvalues[13]; 
opp.CloseDate = date.today()+7;
opp.ProjectID_PermitNoOfSite__c=inputvalues[0];
opp.Project_SiteAddress__c=inputvalues[2];



/*siteCordell_acc = mapAccInserted.get(site.Cordell_Account_No__c).Id;
if(siteCordell_acc!= null)
{
  //  site.Account__c = siteCordell_acc.Id;
site.Account__c = siteCordell_acc;  
} */          

/*********************************/
/*Acc_cordell_acc = mapSiteInserted.get(inputvalues[13]).Id;
system.debug('>>>Map Acc cordell_insert:' +Acc_cordell_acc);
 if(Acc_cordell_acc !=null)
opp.AccountId = Acc_cordell_acc;
 opp_site_cordell_acc =mapSiteInserted.get(inputvalues[13]).Id;
if(opp_site_cordell_acc != null)
opp.Site_Ref_No__c = opp_site_cordell_acc; */ 


//Site__c Acc_cordell_acc = mapSiteInserted.get(inputvalues[13]);
Account Acc_cordell_acc = mapAccInserted.get(opp.Cordell_AccNo_Opp__c);
system.debug('>>>Map Acc cordell_insert:' +Acc_cordell_acc);
 if(Acc_cordell_acc !=null)
//opp.AccountId = Acc_cordell_acc.Account__c;
 opp.AccountId = Acc_cordell_acc.Id;
// Site__c opp_site_cordell_acc =mapSiteInserted.get(inputvalues[13]+inputvalues[0]+inputvalues[2]);
Site__c opp_site_cordell_acc =mapSiteInserted.get(opp.Cordell_AccNo_Opp__c+opp.ProjectID_PermitNoOfSite__c+opp.Project_SiteAddress__c);
if(opp_site_cordell_acc != null)
opp.Site_Ref_No__c = opp_site_cordell_acc.Site_Ref_No__c;  


           

opptoupload.add(opp);
//}
}
try
{
insert opptoupload;
}
catch (Exception e2)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}

return null;
}
public List<Account> getuploadedAccounts()
{

if (accstoupload!= NULL)
if (accstoupload.size() > 0)
return accstoupload;

else
return null;
else
return null;
}

public List<Contact> getuploadedContact()
{
if (contoupload!= NULL)
if (contoupload.size() > 0)
return contoupload;
else
return null;
else
return null;
}

public List<Opportunity> getuploadedOpportunity()
{
if (opptoupload!= NULL)
if (opptoupload.size() > 0)
return opptoupload;
else
return null;
else
return null;
}
public List<Site__c> getuploadedSite()
{
if (sitetoupload!= NULL)
if (sitetoupload.size() > 0)
return  sitetoupload;
else
return null;
else
return null;
}
/* public pageReference fileAccess(){
Document lstDoc = [select id,name,Body from Document where name = 'test'];

System.Debug('DOC NAME :: '+lstDoc.name);
System.Debug('DOCBODY :: '+lstDoc.Body);


return null;
} */

public static testMethod void testReadFile1() {

Document lstDoc = [select id,name,Body from Document where name = 'test'];

// System.Debug('DOC NAME :: '+lstDoc.name);
//System.Debug('DOCBODY :: '+lstDoc.Body);
//FileUploader file=new FileUploader();
//FileUploaderAll file=new FileUploaderAll();
NHS_Project_DataUpload file=new NHS_Project_DataUpload();
Blob content= lstDoc.Body;
file.nameFile=content.toString();
}

public static testMethod void testReadFile2() {

}

}

 

Regards,

Lavanya.

Hi All,

 

            I am having a custom field "Demo" on my custom object. Below this custom object i am having 4 checkbox.

For Example: in the custom field has the value  "Demo= IREAGL" means. 

  IR is splited than the checkbox IRON must be checked.

   EA is splited than the checkbox EARTH must be checked.

   GL is splited than the checkbox GLASS must be checked.

    other check box  must be  left unchecked

 

One more thing this custom field value is upload using CSV file using apex code. I nedd split the split the test into 2 letter and corresponding value must be used to check the check box.

           

                           Kindly  any one tell how to do this.

 

Hi All, In my custom object i have created a  VF page in that I have created a lookup field for "Account" which will display all my existing Account. Also i have created a picklist field for Opportunity(for example i have given 10 values). In the same page i have created a button "convert" when i click the "convert" it must create a new opportuinty to that Account which i have selected. Here i have apex code and Vf page code for this. Kindly tell me how to do this.

 

 

public class Conversion_site
{
private final Site__c Acc_site; //User sobject
private Site__c siteObj;
public Account t{get;set;}
public PageReference RedirecttoSite()
{
String currentLead = '/' + siteObj.Id;
PageReference pageRef = new PageReference(currentLead);
return pageRef;
}


// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public Conversion_site(ApexPages.StandardController stdController)
{
System.debug('******Voltum******');
this.Acc_site = (Site__c)stdController.getRecord();
siteObj = (Site__c)stdController.getRecord();
t =new Account();

}

//creating Opportunity1 picklist values
String s1='Timber';
public String getString1()
{
return s1;
}
public void setString1(String s1 )
{
this.s1 = s1;
}

}

 

VF page Code:

 

<apex:page standardController="Site__c" cache="true" extensions="Conversion_site">
<apex:form >

<apex:pageBlock title="Convert {!Site__c.name} " >

 

<!-- Opportunity1 ,Account 1 ,Sales Person1-->
<apex:pageBlockSectionItem >
<apex:outputLabel value="1"/>
<apex:selectList label="1" value="{!string1}" size="1" required="true">
<apex:selectOption itemValue="Timber" itemLabel="Timber"/>
<apex:selectOption itemValue="Plasterboard & Villaboard" itemLabel="Plasterboard & Villaboard"/>
<apex:selectOption itemValue="Steel Products" itemLabel="Steel Products"/>
<apex:selectOption itemValue="Power Tools" itemLabel="Power Tools"/>
<apex:selectOption itemValue="Sand & Gravel" itemLabel="Sand & Gravel"/>
<apex:selectOption itemValue="Cement & Concrete" itemLabel="Cement & Concrete"/>
<apex:selectOption itemValue="Safety Equipment" itemLabel="Safety Equipment"/>
<apex:selectOption itemValue="Equipment Hire" itemLabel="Equipment Hire"/>
</apex:selectList>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:inputField value="{!t.Parentid}"/>
</apex:pageBlockSectionItem>

 

 

 

Hi All, in my custom object I am having a cutom button"convert" when i click this button"convert"it will  create new Account,Contact and Opportunity. But I need to do same as Lead(Ie,. in Lead if click "convert" button it will go to an other page where we can existing Account for that or we can create a new Account. For creating Opportunity it will have a checkbox which will ask us whether we have to new opportunity for that record, after we made all this we again  "convert")

Like that when i click my custom button"convert" on my custom tab, it must go to another window from that page we have select Account for that(existing or new) if i select existing account means all Account must be displayed in the listbox, we have to select any from that and we have to  create a new opportunity for that record.

 

Here i have attached my Apex code to create Account, contact and opportunity.Also VF page code.

Apex code:

 

public class Convert
{

public PageReference RedirecttoSite()
{
String currentLead = '/' + siteObj.Id;
PageReference pageRef = new PageReference(currentLead);
return pageRef;
}

private Site__c siteObj;
//public ID Cus_Account_ID, Cus_obj_Record_ID;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public Convert(ApexPages.StandardController stdController)
{
System.debug('******sai******');
siteObj = (Site__c)stdController.getRecord();
// Cus_obj_Record_ID=siteObj.Id;
}
List<Account> acctList = new List<account>();
public void convertbutton()
{

Account acc = new Account();
acc.Name = siteObj.Company_Name__c;
acctList = [select id from Account where Name = :acc.Name];
if (acctList.size() > 0)
{

ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'Account Name ' + acc.Name + ' already exists,Duplicate Account Name not allowed');
ApexPages.addMessage(errormsg);
return;
}
acc.BillingStreet = siteObj.Company_Address__c;
acc.BillingCity = siteObj.Company_City__c;
acc.BillingState= siteObj.Company_State__c;
acc.BillingPostalCode = siteObj.Company_Postal_Code__c;
acc.Phone = siteObj.Company_Phone__c;
acc.Website = siteObj.Company_Email__c;
acc.Fax = siteObj.Company_Fax__c;
// acc.CurrencyIsoCode = siteObj.CurrencyIsoCode;

try
{
insert acc;
ApexPages.Message successmsg = new ApexPages.Message(ApexPages.severity.confirm,'New Account ' + acc.Name + ' is created, Related Contact and Opporunity also created' );
ApexPages.addMessage(successmsg);
}
Catch (Exception ex1)
{
ex1.getmessage();
}
Contact cc = new Contact();
cc.LastName = siteObj.Contact_Name__c;
cc.Email = siteObj.Contact_Email__c;
cc.Phone = siteObj.Contact_Mobile__c;
cc.AccountId = acc.Id;

try
{
insert cc;
}
Catch (Exception ex2)
{

ex2.getmessage();
}

Opportunity opp = new Opportunity();
opp.Name = siteObj.Opp_Name__c;
opp.AccountId= acc.Id;
opp.CloseDate = siteObj.Opp_CloseDate__c;
opp.StageName = siteObj.Opp_stage__c;
if(opp.StageName == 'Needs Analysis')
opp.Probability= 20;
else if(opp.StageName == 'Prospecting')
opp.Probability= 10;
else if(opp.StageName == 'Negotiation/Review')
opp.Probability= 90;
else if(opp.StageName == 'Closed Won')
opp.Probability= 100;
else if(opp.StageName == 'Closed Lost')
opp.Probability= 0;

try
{
insert opp;
}
Catch (Exception ex3)
{
 ex3.getmessage();
}

}
 }

 

VF page code for "convert"button:

<apex:page standardController="Site__c" cache="true" action="{!convertbutton}" extensions="Convert" >
<br/><br/>
<apex:messages style="color:red; font-weight:bold; text-align:center;"/>
<apex:form >
<center>
<!--<apex:pagemessages />-->
<apex:outputField value="{!Site__c.Company_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Address__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_City__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_State__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Postal_Code__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Phone__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Email__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Fax__c}" rendered="false"/>

<apex:outputField value="{!Site__c.Contact_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Contact_Email__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Contact_Mobile__c}" rendered="false"/>

<!--<apex:outputField value="{!Site__c.CurrencyIsoCode}" rendered="false"/>-->
<apex:outputField value="{!Site__c.ConvertedSite__c}" rendered="false"/>

<apex:outputField value="{!Site__c.Opp_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Opp_CloseDate__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Opp_stage__c}" rendered="false"/>


<apex:commandLink value="Redirect to Site" style="color:blue; font-weight:bold;" action="{!RedirecttoSite}"/>

</center>

</apex:form>
</apex:page>

 

Any one tell how to do this. kindly give me any idea for this and tell me any sample code for this.Waitng for your reply

 

Regards,

Lavanya.

 

My requirement is I am trying to pull information from Salesforce to SAP (by passing the in the field "IvAcctNo" to SAP , I need to get the related record details and display it in salesforce).How to do this give me any idea, also tell how to map this fields with salesforce.

Hi All, I am having a custom button "convert" on my custom object, whencilck the convert button it must create a new account, contact and opportunity.Before it convert it into Account,Contact and Opportunity it must check the all Account name in "Account" tab. If the Account Name is exist means it must display the error message"Account Name exist" . Other wise it must create new Account, Contact and Opportunity. For "convert " i am using Apex code and VF page. I tried using a checkbox for this but when uncheck the checkbox it is creating a new account in the same name, that is same account name which is already exist. Kindly tell me now to resolve this

 

Apex code:

public class Convert {

public PageReference RedirecttoLead()
{
String currentLead = '/' + siteObj.Id;
PageReference pageRef = new PageReference(currentLead);
return pageRef;
}

private Site__c siteObj;
//public ID Cus_Account_ID, Cus_obj_Record_ID;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public Convert(ApexPages.StandardController stdController)
{
System.debug('******Voltum******');
siteObj = (Site__c)stdController.getRecord();
// Cus_obj_Record_ID=siteObj.Id;
}

public void convertbutton(){

Account acc = new Account();
acc.Name = siteObj.Company_Name__c;
acc.BillingStreet = siteObj.Company_Address__c;
acc.BillingCity = siteObj.Company_City__c;
acc.BillingState= siteObj.Company_State__c;
acc.BillingPostalCode = siteObj.Company_Postal_Code__c;
acc.Phone = siteObj.Company_Phone__c;
acc.Website = siteObj.Company_Email__c;
acc.Fax = siteObj.Company_Fax__c;
// acc.CurrencyIsoCode = siteObj.CurrencyIsoCode;

try
{
insert acc;
}
Catch (Exception ex1)
{
ex1.getmessage();
}
Contact cc = new Contact();
cc.LastName = siteObj.Contact_Name__c;
cc.Email = siteObj.Contact_Email__c;
cc.Phone = siteObj.Contact_Mobile__c;
cc.AccountId = acc.Id;
//temp_siteObj = [select AccountId from Contact where Id ='Cus_obj_Record_ID'];
//Cus_Account_ID = temp_siteObj.AccountId;

//Id accountId = [select AccountId from Contact where Id = {ID}][0].AccountId;
//System.Debug(accountId);

try
{
insert cc;
}
Catch (Exception ex2)
{

ex2.getmessage();
}

Opportunity opp = new Opportunity();
opp.Name = siteObj.Opp_Name__c;
opp.AccountId= acc.Id;
opp.CloseDate = siteObj.Opp_CloseDate__c;
opp.StageName = siteObj.Opp_stage__c;

try
{
insert opp;
}
Catch (Exception ex3)
{

ex3.getmessage();
}




// try
// {
// Delete siteObj;
//}
//catch(Exception ex4)
// {
// ex4.getmessage();
// }

}

}

 

VF Page Code:

<apex:page standardController="Site__c" cache="true" action="{!convertbutton}" extensions="Convert" >
<br/><br/>
<apex:messages style="color:red; font-weight:bold; text-align:center;"/>
<apex:form >
<center>

<apex:outputField value="{!Site__c.Company_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Address__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_City__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_State__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Postal_Code__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Phone__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Email__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Fax__c}" rendered="false"/>

<apex:outputField value="{!Site__c.Contact_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Contact_Email__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Contact_Mobile__c}" rendered="false"/>

<!--<apex:outputField value="{!Site__c.CurrencyIsoCode}" rendered="false"/>-->
<apex:outputField value="{!Site__c.ConvertedSite__c}" rendered="false"/>

<apex:outputField value="{!Site__c.Opp_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Opp_CloseDate__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Opp_stage__c}" rendered="false"/>
<apex:commandLink value="Redirect to Lead" style="color:blue; font-weight:bold;" action="{!RedirecttoLead}"/>

</center>

</apex:form>
</apex:page>

Hi All,wheni upload a csv it must create account, contact, opportunity.

In my custom lead i am having custom field

company name,

company street,

company city, 

comapny state,

company postal code.

 

when i upload csv file,this fields must be mapped to "Billing Address" field on "Account". How this can be done. i didn't how to map this fileds.

Apex code:

public class FileUploaderAll
{
public FileUploaderAll(ApexPages.StandardController controller) {
}

public PageReference fileAccess() {
return null;
}

public FileUploaderAll(){
}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Account> accstoupload;
List<Contact> contoupload;
List<Opportunity> opptoupload;
List<CustomLead__c> custtoupload;
List<String> acctNames;

List<Account> newAccts = new List<Account>();
public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
custtoupload = new List<CustomLead__c>();
acctNames = new List<String>();
List<Account> existingAccts =new List<Account>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Account a = new Account();
a.Name = inputvalues[0];
acctNames.add(a.Name);

accstoupload.add(a);
}


existingAccts = [SELECT Id, Name FROM Account where name in :acctNames];
//create a map with names as key
Map<String, Id> acctNamesIdMap = new Map<String, Id>();
// load the map - this will help you find out if an account name exists already
for (Account acct : existingAccts)
{
acctNamesIdMap.put(acct.Name, acct.Id);
System.debug('******Sai******');
}

for (Account acct : accstoupload)
{
//if account name does not exist in map, add it to list of new accounts
if (!acctNamesIdMap.containsKey(acct.Name))
//if (!acctNamesIdMap.containsKey(acct.Id))
{
newAccts.add(acct);

}

}

try
{

insert newAccts;
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.info,'AccountName with Account Id are the new Account created.Related Contact and Opportunity also created');
ApexPages.Message msg1 = new ApexPages.Message(ApexPages.severity.info,'AccountName without Account Id are the existing Accounts');
ApexPages.addMessage(msg);
ApexPages.addMessage(msg1);

}
catch (Exception e)
{

ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'Account Name already exist, change Account Name and try again');
ApexPages.addMessage(errormsg);

}


//return null;
for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');

Contact con = new Contact();
for(account a: accstoupload)
{
con.AccountId = accstoupload[i-1].id;
//con.AccountId = a.Id;
}
//con.Account= inputconvalues[0];
if(con.AccountId!= null){

con.Lastname = inputconvalues[1];
con.Lastname_lead__c = inputconvalues[2];

contoupload.add(con);
}}
try
{
insert contoupload;

Hi All, I have apex code  generated by WSDL for SAP. My requirement is using this code i need to connect my salesforce with SAP(table) which is  to get the data from SAP table and display it in Salesforce. First this i need made a connection with my salesforce and SAP. I tried a lot for this connect but i can't connect this. Kindly tell me the step for how to connect this using Apex code.

 

Generated code for WSDL to Apex:

 

//Generated by wsdl2apex

public class sapComDocumentSapSoapFunctionsMcS {
public class zsd_cust_det_webservice {
public String endpoint_x = 'http://serverapp5.cssydney.local:8000/sap/bc/srt/rfc/sap/zsd_cust_det_webservice/100/zsd_cust_det_we...
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style', 'sapComDocumentSapSoapFunctionsMcS', 'urn:sap-com:document:sap:rfc:functions', 'sapComDocumentSapRfcFunctions'};
public sapComDocumentSapSoapFunctionsMcS.ZsdTCustDet ZsdCustWebservDemo(String IvAcctNo) {
sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemo_element request_x = new sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemo_element();
sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemoResponse_element response_x;
request_x.IvAcctNo = IvAcctNo;
Map<String, sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemoResponse_element> response_map_x = new Map<String, sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemoResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'',
'urn:sap-com:document:sap:soap:functions:mc-style',
'ZsdCustWebservDemo',
'urn:sap-com:document:sap:soap:functions:mc-style',
'ZsdCustWebservDemoResponse',
'sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemoResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.EtAccDet;
}
}
public class ZsdCustWebservDemo_element {
public String IvAcctNo;
private String[] IvAcctNo_type_info = new String[]{'IvAcctNo','urn:sap-com:document:sap:rfc:functions','char10','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style','false','true'};
private String[] field_order_type_info = new String[]{'IvAcctNo'};
}
public class ZsdSCustDet {
public String AcctNo;
public String SalesOrdNo;
public String PoNo;
public String PoDate;
public String NetVal;
public String Currency_x;
private String[] AcctNo_type_info = new String[]{'AcctNo','urn:sap-com:document:sap:rfc:functions','char10','1','1','false'};
private String[] SalesOrdNo_type_info = new String[]{'SalesOrdNo','urn:sap-com:document:sap:rfc:functions','char10','1','1','false'};
private String[] PoNo_type_info = new String[]{'PoNo','urn:sap-com:document:sap:rfc:functions','char20','1','1','false'};
private String[] PoDate_type_info = new String[]{'PoDate','urn:sap-com:document:sap:rfc:functions','date','1','1','false'};
private String[] NetVal_type_info = new String[]{'NetVal','urn:sap-com:document:sap:rfc:functions','curr15.2','1','1','false'};
private String[] Currency_x_type_info = new String[]{'Currency','urn:sap-com:document:sap:rfc:functions','cuky5','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style','false','true'};
private String[] field_order_type_info = new String[]{'AcctNo','SalesOrdNo','PoNo','PoDate','NetVal','Currency_x'};
}
public class ZsdTCustDet {
public sapComDocumentSapSoapFunctionsMcS.ZsdSCustDet[] item;
private String[] item_type_info = new String[]{'item','urn:sap-com:document:sap:soap:functions:mc-style','ZsdSCustDet','0','-1','false'};
private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style','false','true'};
private String[] field_order_type_info = new String[]{'item'};
}
public class ZsdCustWebservDemoResponse_element {
public sapComDocumentSapSoapFunctionsMcS.ZsdTCustDet EtAccDet;
private String[] EtAccDet_type_info = new String[]{'EtAccDet','urn:sap-com:document:sap:soap:functions:mc-style','ZsdTCustDet','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style','false','true'};
private String[] field_order_type_info = new String[]{'EtAccDet'};
}
}

 

Thanks,

Regards,

Lavanya.

 

Hi all , when i am uploading csv file to create a new account, conatct and oppotunity i need to check account duplicate name. If not exist i need to create new  account else it must show the error message that account name already exist. i need to achevie this uiong apex code. Kindly anyone tell how to resolve this.

 

Apex code:

 

public class FileUploaderAll
{

public FileUploaderAll(ApexPages.StandardController controller) {

}


public PageReference fileAccess() {
return null;
}


public FileUploaderAll(){

}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Account> accstoupload;
List<Contact> contoupload;
List<Opportunity> opptoupload;
List<CustomLead__c> custtoupload;

public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
custtoupload = new List<CustomLead__c>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');


Account a = new Account();
a.Name = inputvalues[0];

accstoupload.add(a);
}
try
{
insert accstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}

//return null;
for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');

Contact con = new Contact();
for(account a: accstoupload)
{
con.AccountId = accstoupload[i-1].id;
//con.AccountId = a.Id;
}
//con.Account= inputconvalues[0];
con.Lastname = inputconvalues[1];
con.Lastname_lead__c = inputconvalues[2];

contoupload.add(con);
}

try
{
insert contoupload;
}
catch (Exception e1)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
// return null;

for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');

Opportunity opp = new Opportunity();
for(account a: accstoupload)
{
opp.AccountId = accstoupload[i-1].id;
//opp.AccountId = a.Id;
}
opp.Name = inputvalues[3];
opp.OPP_DateOfBirth__c = inputvalues[4];
opp.StageName = inputvalues[6];
opp.CloseDate = date.parse(inputvalues[5]);
// a.ShippingPostalCode = inputvalues[4];
// a.ShippingCountry = inputvalues[5];

opptoupload.add(opp);
}

try
{
insert opptoupload;
}
catch (Exception e2)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
for (Integer i=1;i<filelines.size();i++)
{
String[] inputcustvalues = new String[]{};
inputcustvalues = filelines[i].split(',');


CustomLead__c cust = new CustomLead__c();
cust.CompanyName__c = inputcustvalues[0];
cust.LastName_c__c = inputcustvalues[1];
cust.Name = inputcustvalues[2];
cust.opp_name__c = inputcustvalues[3];

custtoupload.add(cust);
}
try
{
insert custtoupload;
}
catch (Exception e3)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
return null;
}
public List<Account> getuploadedAccounts()
{
if (accstoupload!= NULL)
if (accstoupload.size() > 0)
return accstoupload;
else
return null;
else
return null;
}

public List<Contact> getuploadedContact()
{
if (contoupload!= NULL)
if (contoupload.size() > 0)
return contoupload;
else
return null;
else
return null;
}

public List<Opportunity> getuploadedOpportunity()
{
if (opptoupload!= NULL)
if (opptoupload.size() > 0)
return opptoupload;
else
return null;
else
return null;
}
public List<CustomLead__c> getuploadedCustomLead()
{
if (custtoupload!= NULL)
if (custtoupload.size() > 0)
return custtoupload;
else
return null;
else
return null;
}
/* public pageReference fileAccess(){
Document lstDoc = [select id,name,Body from Document where name = 'test'];

System.Debug('DOC NAME :: '+lstDoc.name);
System.Debug('DOCBODY :: '+lstDoc.Body);


return null;
} */

public static testMethod void testReadFile1() {

Document lstDoc = [select id,name,Body from Document where name = 'test'];

// System.Debug('DOC NAME :: '+lstDoc.name);
//System.Debug('DOCBODY :: '+lstDoc.Body);
FileUploader file=new FileUploader();
Blob content= lstDoc.Body;
file.nameFile=content.toString();

}

public static testMethod void testReadFile2() {

}

}

 

Hi i am trying to upload a csv using apex code, once i click upload button it must create a Account, contact and opportunity. its similar like the lead conversion. But in the contact i want to display the Account name to that contact. In my code i getting for this, kindly any one tell how to resolve this. The CSV may conatin more 10 records.

 

Apex code:

public class FileUploaderAll
{

public FileUploaderAll(ApexPages.StandardController controller) {

}


public PageReference fileAccess() {
return null;
}


public FileUploaderAll(){

}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Account> accstoupload;
List<Contact> contoupload;
List<Opportunity> opptoupload;


public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');


Account a = new Account();
a.Name = inputvalues[0];
accstoupload.add(a);

}
try
{
insert accstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}


for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');

Contact con = new Contact();
 con.AccountId = accstoupload.Id;
con.Lastname = inputconvalues[1];
con.Lastname_lead__c = inputconvalues[2];
contoupload.add(con);

}

try
{
insert contoupload;
}
catch (Exception e1)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
// return null;


for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');

Opportunity opp = new Opportunity();
opp.Name = inputvalues[3];
opp.OPP_DateOfBirth__c = inputvalues[4];
opp.StageName = inputvalues[6];
opp.CloseDate = date.parse(inputvalues[5]);

opptoupload.add(opp);
}

try
{
insert opptoupload;
}
catch (Exception e2)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
return null;
}
public List<Account> getuploadedAccounts()
{
if (accstoupload!= NULL)
if (accstoupload.size() > 0)
return accstoupload;
else
return null;
else
return null;
}

public List<Contact> getuploadedContact()
{
if (contoupload!= NULL)
if (contoupload.size() > 0)
return contoupload;
else
return null;
else
return null;
}

public List<Opportunity> getuploadedOpportunity()
{
if (opptoupload!= NULL)
if (opptoupload.size() > 0)
return opptoupload;
else
return null;
else
return null;
}
/* public pageReference fileAccess(){
Document lstDoc = [select id,name,Body from Document where name = 'test'];

System.Debug('DOC NAME :: '+lstDoc.name);
System.Debug('DOCBODY :: '+lstDoc.Body);


return null;
} */

public static testMethod void testReadFile1() {

Document lstDoc = [select id,name,Body from Document where name = 'test'];

// System.Debug('DOC NAME :: '+lstDoc.name);
//System.Debug('DOCBODY :: '+lstDoc.Body);
FileUploader file=new FileUploader();
Blob content= lstDoc.Body;
file.nameFile=content.toString();

}

public static testMethod void testReadFile2() {

}

}

 

Thanks,

Regards, 

lavanya

Hi when i am upload a csv to create Account and contact using Apex code. In the contact i need to give the acoount name which is a list. How to get accoutn id to contact.In the code i have bold the line contac.Kindly anyone tell how to resolve this.

 

My code:

 

accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');

Account a = new Account();
a.Name = inputvalues[0];

accstoupload.add(a);
}

for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');

Contact con = new Contact();
 con.AccountId = a.Id;
con.Lastname = inputconvalues[1];
con.Lastname_lead__c = inputconvalues[2];


contoupload.add(con);
}

Hi this the error i am getting

Error: Compile Error: Illegal assignment from String to Date at line 95 column 1.

 

In the code  i had make that error line bold.

code:

for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');

Opportunity opp = new Opportunity();
opp.Name = inputvalues[3];
opp.OPP_DateOfBirth__c = inputvalues[4];
opp.StageName = inputvalues[6];
opp.CloseDate = inputvalues[5];

opptoupload.add(opp);
}

 

I am having one custom object "Site" which has lookup relationship with opportunity. Which means each site record has more than one opportunity. For example if a site record has 5 opportunity in that 4 opportunity has already closed then when i am trying to close the last opportunity in that site record it must display a alert message " your opportunity is closed, would you like to close the site record also yes or no". If i press yes means it must go to that particular site record their we can manually close the site record.

Hi All,

 

       I have wirtten a apex code and Vf page for uplaoding a csv file to create a new Account, Contact. In my file the account is given in lower case letter, i need to change it to upper case letter and then  need to save in to salesforce. I tried  but can't get solution for this. Kindly any tell how to resolve this and also tell me any links for this. Here i have attached the code also. Thanks in advance

 

Code:

 

for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
String SalesforceAccountNumber = inputvalues[2];
Acc_Bulider = inputvalues[3];
if(Acc_Bulider != 'Builder Unknown')
{

Account a = new Account();
a.Name = inputvalues[3];

acctNames.add(a.Name);
  accstoupload.add(a);
}

}

 

Hi All,

when I save the below formula, it shows this error:

 

Error: Compiled formula is too big to execute (19,959 characters). Maximum size is 5,000 character

 

if the sum of Value_1__c to Value_13__c <= 10, then  display level 1

if the sum of Value_1__c to Value_13__c >10 and Value_1__c to Value_13__c <= 18, then  display level 2

if the sum of Value_1__c to Value_13__c >18 then level 3

 

 

formula value:

if((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) <= 10

&&
(Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c ) <> 0 , "Level 1",
if( AND((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c + Value_10__c + Value_11__c + Value_12__c + Value_13__c) > 10
&&
(Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) <= 18), "Level 2",
if((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) > 18,"Level 3",
"Level Not Calculated Yet" )))

 

 

All field Value_1__c to Value_13__c also formula field which get s the value from the picklist selected.

 

we tried this also:

 

total_risk_cal__c = Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c


if((total_risk_cal__c) <= 10
&&
(total_risk_cal__c ) <> 0 , "Level 1",
if( AND((total_risk_cal__c) > 10
&&
(total_risk_cal__c) <= 18), "Level 2",
if((total_risk_cal__c) > 18,"Level 3",
"Level Not Calculated Yet" )))

 

but getting same error. We are trying an alternate method of creating a whole page using VF. We didn't get any ideal for how to give fomula field dynmaically in Visual force we are using professional edition. Kindly any one tell how to dao this and please send me any sample code for this also some links. Thanks in advance, waiting for you reply.

 

Regards,

Lavanya.

 

 

Hi All,

 

            I am having a custom field "Demo" on my custom object. Below this custom object i am having 4 checkbox.

For Example: in the custom field has the value  "Demo= IREAGL" means. 

  IR is splited than the checkbox IRON must be checked.

   EA is splited than the checkbox EARTH must be checked.

   GL is splited than the checkbox GLASS must be checked.

    other check box  must be  left unchecked

 

One more thing this custom field value is upload using CSV file using apex code. I nedd split the split the test into 2 letter and corresponding value must be used to check the check box.

           

                           Kindly  any one tell how to do this.

 

Hi All, I am having a custom button "convert" on my custom object, whencilck the convert button it must create a new account, contact and opportunity.Before it convert it into Account,Contact and Opportunity it must check the all Account name in "Account" tab. If the Account Name is exist means it must display the error message"Account Name exist" . Other wise it must create new Account, Contact and Opportunity. For "convert " i am using Apex code and VF page. I tried using a checkbox for this but when uncheck the checkbox it is creating a new account in the same name, that is same account name which is already exist. Kindly tell me now to resolve this

 

Apex code:

public class Convert {

public PageReference RedirecttoLead()
{
String currentLead = '/' + siteObj.Id;
PageReference pageRef = new PageReference(currentLead);
return pageRef;
}

private Site__c siteObj;
//public ID Cus_Account_ID, Cus_obj_Record_ID;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public Convert(ApexPages.StandardController stdController)
{
System.debug('******Voltum******');
siteObj = (Site__c)stdController.getRecord();
// Cus_obj_Record_ID=siteObj.Id;
}

public void convertbutton(){

Account acc = new Account();
acc.Name = siteObj.Company_Name__c;
acc.BillingStreet = siteObj.Company_Address__c;
acc.BillingCity = siteObj.Company_City__c;
acc.BillingState= siteObj.Company_State__c;
acc.BillingPostalCode = siteObj.Company_Postal_Code__c;
acc.Phone = siteObj.Company_Phone__c;
acc.Website = siteObj.Company_Email__c;
acc.Fax = siteObj.Company_Fax__c;
// acc.CurrencyIsoCode = siteObj.CurrencyIsoCode;

try
{
insert acc;
}
Catch (Exception ex1)
{
ex1.getmessage();
}
Contact cc = new Contact();
cc.LastName = siteObj.Contact_Name__c;
cc.Email = siteObj.Contact_Email__c;
cc.Phone = siteObj.Contact_Mobile__c;
cc.AccountId = acc.Id;
//temp_siteObj = [select AccountId from Contact where Id ='Cus_obj_Record_ID'];
//Cus_Account_ID = temp_siteObj.AccountId;

//Id accountId = [select AccountId from Contact where Id = {ID}][0].AccountId;
//System.Debug(accountId);

try
{
insert cc;
}
Catch (Exception ex2)
{

ex2.getmessage();
}

Opportunity opp = new Opportunity();
opp.Name = siteObj.Opp_Name__c;
opp.AccountId= acc.Id;
opp.CloseDate = siteObj.Opp_CloseDate__c;
opp.StageName = siteObj.Opp_stage__c;

try
{
insert opp;
}
Catch (Exception ex3)
{

ex3.getmessage();
}




// try
// {
// Delete siteObj;
//}
//catch(Exception ex4)
// {
// ex4.getmessage();
// }

}

}

 

VF Page Code:

<apex:page standardController="Site__c" cache="true" action="{!convertbutton}" extensions="Convert" >
<br/><br/>
<apex:messages style="color:red; font-weight:bold; text-align:center;"/>
<apex:form >
<center>

<apex:outputField value="{!Site__c.Company_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Address__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_City__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_State__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Postal_Code__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Phone__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Email__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Fax__c}" rendered="false"/>

<apex:outputField value="{!Site__c.Contact_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Contact_Email__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Contact_Mobile__c}" rendered="false"/>

<!--<apex:outputField value="{!Site__c.CurrencyIsoCode}" rendered="false"/>-->
<apex:outputField value="{!Site__c.ConvertedSite__c}" rendered="false"/>

<apex:outputField value="{!Site__c.Opp_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Opp_CloseDate__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Opp_stage__c}" rendered="false"/>
<apex:commandLink value="Redirect to Lead" style="color:blue; font-weight:bold;" action="{!RedirecttoLead}"/>

</center>

</apex:form>
</apex:page>

Hi All,wheni upload a csv it must create account, contact, opportunity.

In my custom lead i am having custom field

company name,

company street,

company city, 

comapny state,

company postal code.

 

when i upload csv file,this fields must be mapped to "Billing Address" field on "Account". How this can be done. i didn't how to map this fileds.

Apex code:

public class FileUploaderAll
{
public FileUploaderAll(ApexPages.StandardController controller) {
}

public PageReference fileAccess() {
return null;
}

public FileUploaderAll(){
}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Account> accstoupload;
List<Contact> contoupload;
List<Opportunity> opptoupload;
List<CustomLead__c> custtoupload;
List<String> acctNames;

List<Account> newAccts = new List<Account>();
public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
custtoupload = new List<CustomLead__c>();
acctNames = new List<String>();
List<Account> existingAccts =new List<Account>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Account a = new Account();
a.Name = inputvalues[0];
acctNames.add(a.Name);

accstoupload.add(a);
}


existingAccts = [SELECT Id, Name FROM Account where name in :acctNames];
//create a map with names as key
Map<String, Id> acctNamesIdMap = new Map<String, Id>();
// load the map - this will help you find out if an account name exists already
for (Account acct : existingAccts)
{
acctNamesIdMap.put(acct.Name, acct.Id);
System.debug('******Sai******');
}

for (Account acct : accstoupload)
{
//if account name does not exist in map, add it to list of new accounts
if (!acctNamesIdMap.containsKey(acct.Name))
//if (!acctNamesIdMap.containsKey(acct.Id))
{
newAccts.add(acct);

}

}

try
{

insert newAccts;
ApexPages.Message msg = new ApexPages.Message(ApexPages.severity.info,'AccountName with Account Id are the new Account created.Related Contact and Opportunity also created');
ApexPages.Message msg1 = new ApexPages.Message(ApexPages.severity.info,'AccountName without Account Id are the existing Accounts');
ApexPages.addMessage(msg);
ApexPages.addMessage(msg1);

}
catch (Exception e)
{

ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'Account Name already exist, change Account Name and try again');
ApexPages.addMessage(errormsg);

}


//return null;
for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');

Contact con = new Contact();
for(account a: accstoupload)
{
con.AccountId = accstoupload[i-1].id;
//con.AccountId = a.Id;
}
//con.Account= inputconvalues[0];
if(con.AccountId!= null){

con.Lastname = inputconvalues[1];
con.Lastname_lead__c = inputconvalues[2];

contoupload.add(con);
}}
try
{
insert contoupload;

Hi all , when i am uploading csv file to create a new account, conatct and oppotunity i need to check account duplicate name. If not exist i need to create new  account else it must show the error message that account name already exist. i need to achevie this uiong apex code. Kindly anyone tell how to resolve this.

 

Apex code:

 

public class FileUploaderAll
{

public FileUploaderAll(ApexPages.StandardController controller) {

}


public PageReference fileAccess() {
return null;
}


public FileUploaderAll(){

}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Account> accstoupload;
List<Contact> contoupload;
List<Opportunity> opptoupload;
List<CustomLead__c> custtoupload;

public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
custtoupload = new List<CustomLead__c>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');


Account a = new Account();
a.Name = inputvalues[0];

accstoupload.add(a);
}
try
{
insert accstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}

//return null;
for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');

Contact con = new Contact();
for(account a: accstoupload)
{
con.AccountId = accstoupload[i-1].id;
//con.AccountId = a.Id;
}
//con.Account= inputconvalues[0];
con.Lastname = inputconvalues[1];
con.Lastname_lead__c = inputconvalues[2];

contoupload.add(con);
}

try
{
insert contoupload;
}
catch (Exception e1)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
// return null;

for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');

Opportunity opp = new Opportunity();
for(account a: accstoupload)
{
opp.AccountId = accstoupload[i-1].id;
//opp.AccountId = a.Id;
}
opp.Name = inputvalues[3];
opp.OPP_DateOfBirth__c = inputvalues[4];
opp.StageName = inputvalues[6];
opp.CloseDate = date.parse(inputvalues[5]);
// a.ShippingPostalCode = inputvalues[4];
// a.ShippingCountry = inputvalues[5];

opptoupload.add(opp);
}

try
{
insert opptoupload;
}
catch (Exception e2)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
for (Integer i=1;i<filelines.size();i++)
{
String[] inputcustvalues = new String[]{};
inputcustvalues = filelines[i].split(',');


CustomLead__c cust = new CustomLead__c();
cust.CompanyName__c = inputcustvalues[0];
cust.LastName_c__c = inputcustvalues[1];
cust.Name = inputcustvalues[2];
cust.opp_name__c = inputcustvalues[3];

custtoupload.add(cust);
}
try
{
insert custtoupload;
}
catch (Exception e3)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
return null;
}
public List<Account> getuploadedAccounts()
{
if (accstoupload!= NULL)
if (accstoupload.size() > 0)
return accstoupload;
else
return null;
else
return null;
}

public List<Contact> getuploadedContact()
{
if (contoupload!= NULL)
if (contoupload.size() > 0)
return contoupload;
else
return null;
else
return null;
}

public List<Opportunity> getuploadedOpportunity()
{
if (opptoupload!= NULL)
if (opptoupload.size() > 0)
return opptoupload;
else
return null;
else
return null;
}
public List<CustomLead__c> getuploadedCustomLead()
{
if (custtoupload!= NULL)
if (custtoupload.size() > 0)
return custtoupload;
else
return null;
else
return null;
}
/* public pageReference fileAccess(){
Document lstDoc = [select id,name,Body from Document where name = 'test'];

System.Debug('DOC NAME :: '+lstDoc.name);
System.Debug('DOCBODY :: '+lstDoc.Body);


return null;
} */

public static testMethod void testReadFile1() {

Document lstDoc = [select id,name,Body from Document where name = 'test'];

// System.Debug('DOC NAME :: '+lstDoc.name);
//System.Debug('DOCBODY :: '+lstDoc.Body);
FileUploader file=new FileUploader();
Blob content= lstDoc.Body;
file.nameFile=content.toString();

}

public static testMethod void testReadFile2() {

}

}

 

Hi i am trying to upload a csv using apex code, once i click upload button it must create a Account, contact and opportunity. its similar like the lead conversion. But in the contact i want to display the Account name to that contact. In my code i getting for this, kindly any one tell how to resolve this. The CSV may conatin more 10 records.

 

Apex code:

public class FileUploaderAll
{

public FileUploaderAll(ApexPages.StandardController controller) {

}


public PageReference fileAccess() {
return null;
}


public FileUploaderAll(){

}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Account> accstoupload;
List<Contact> contoupload;
List<Opportunity> opptoupload;


public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');


Account a = new Account();
a.Name = inputvalues[0];
accstoupload.add(a);

}
try
{
insert accstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}


for (Integer i=1;i<filelines.size();i++)
{
String[] inputconvalues = new String[]{};
inputconvalues = filelines[i].split(',');

Contact con = new Contact();
 con.AccountId = accstoupload.Id;
con.Lastname = inputconvalues[1];
con.Lastname_lead__c = inputconvalues[2];
contoupload.add(con);

}

try
{
insert contoupload;
}
catch (Exception e1)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
// return null;


for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');

Opportunity opp = new Opportunity();
opp.Name = inputvalues[3];
opp.OPP_DateOfBirth__c = inputvalues[4];
opp.StageName = inputvalues[6];
opp.CloseDate = date.parse(inputvalues[5]);

opptoupload.add(opp);
}

try
{
insert opptoupload;
}
catch (Exception e2)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
return null;
}
public List<Account> getuploadedAccounts()
{
if (accstoupload!= NULL)
if (accstoupload.size() > 0)
return accstoupload;
else
return null;
else
return null;
}

public List<Contact> getuploadedContact()
{
if (contoupload!= NULL)
if (contoupload.size() > 0)
return contoupload;
else
return null;
else
return null;
}

public List<Opportunity> getuploadedOpportunity()
{
if (opptoupload!= NULL)
if (opptoupload.size() > 0)
return opptoupload;
else
return null;
else
return null;
}
/* public pageReference fileAccess(){
Document lstDoc = [select id,name,Body from Document where name = 'test'];

System.Debug('DOC NAME :: '+lstDoc.name);
System.Debug('DOCBODY :: '+lstDoc.Body);


return null;
} */

public static testMethod void testReadFile1() {

Document lstDoc = [select id,name,Body from Document where name = 'test'];

// System.Debug('DOC NAME :: '+lstDoc.name);
//System.Debug('DOCBODY :: '+lstDoc.Body);
FileUploader file=new FileUploader();
Blob content= lstDoc.Body;
file.nameFile=content.toString();

}

public static testMethod void testReadFile2() {

}

}

 

Thanks,

Regards, 

lavanya