function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ajaybharathajaybharath 

Return URL for a Custom Button

Hi

 

I need to auto-populate the account lookup for a new Contact by using custom button.

When i click on the standard Button New Contact , the retUrl and accId denotes the Id's of the account for which a new contact is created , somthing like this .. https://ap1.salesforce.com/003/e?retURL=%2F0019000000FecuW&accid=0019000000FecuW

I dont wanna hard code it so ,
I create a new custom button say New My Contact .. as a list button and content source as URL ..
I gave something like this ,
/003/e?retURL=/{! Account.Id }& accid={!Account.Id}
but its returning null for account Id ..

Please Help


Thanks
Aj

Best Answer chosen by Admin (Salesforce Developers) 
ajaybharathajaybharath

Hi Mukul


Thanks for ur assistance.
As per my requirement , i should use a custom button to auto pop it .
I used a class n invoked it thro sforce.apex.execute and this code works fine

global class RecordTypeExtension {
    public RecordTypeExtension(){
        
    }
    webservice static String getRecordTypeId(String recordTypeName){
        String resultId = '';
        RecordType RT = [Select r.SobjectType, r.Name, r.Id, r.DeveloperName From RecordType r where r.SobjectType = 'Contact' and r.DeveloperName = :recordTypeName limit 1];
        System.Debug('******'+RT);
        if(RT != null){
            resultId = String.valueOf(RT.Id);
        }
        return resultId;
    }
}

 script

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")} 
var recordTypeName = '{!Account.RecordType}';
var rid= sforce.apex.execute('RecordTypeExtension','getRecordTypeId',{string:recordTypeName});
var aid='{!Account.Id}'; 
var r=confirm("Do you want to Create Record Type for account?"); 

if (r==true) 
{
window.location='/003/e?retURL= /'+aid+' &accid='+aid+'&RecordType='+rid;
}

 

 

 Thanks
 Aj

All Answers

ajaybharathajaybharath

hi ..

i used a onclick javascript code and
this code works for auto-populating account lookup for a new contact ,

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
//var newRecords = []; 

//var c = new sforce.SObject("Account"); 
var id='{!Account.Id}'; 



var r=confirm("Do you want to Add New Influencer Contact"); 

if (r==true) 
{ 
window.location='/003/e?retURL=/'+id+'&accid='+id; 
}

but now i want to auto pop a recordtype of account record to contact record
can anyone please help

ignatiuz_forceignatiuz_force

you can write a trigger or workflow do that on contact creation.

ajaybharathajaybharath

Hi Mukul


Thanks for ur assistance.
As per my requirement , i should use a custom button to auto pop it .
I used a class n invoked it thro sforce.apex.execute and this code works fine

global class RecordTypeExtension {
    public RecordTypeExtension(){
        
    }
    webservice static String getRecordTypeId(String recordTypeName){
        String resultId = '';
        RecordType RT = [Select r.SobjectType, r.Name, r.Id, r.DeveloperName From RecordType r where r.SobjectType = 'Contact' and r.DeveloperName = :recordTypeName limit 1];
        System.Debug('******'+RT);
        if(RT != null){
            resultId = String.valueOf(RT.Id);
        }
        return resultId;
    }
}

 script

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")} 
var recordTypeName = '{!Account.RecordType}';
var rid= sforce.apex.execute('RecordTypeExtension','getRecordTypeId',{string:recordTypeName});
var aid='{!Account.Id}'; 
var r=confirm("Do you want to Create Record Type for account?"); 

if (r==true) 
{
window.location='/003/e?retURL= /'+aid+' &accid='+aid+'&RecordType='+rid;
}

 

 

 Thanks
 Aj

This was selected as the best answer